diff options
author | Felix Lange <fjl@twurst.com> | 2014-10-23 21:01:27 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2014-10-23 21:01:27 +0800 |
commit | 69baa465ea69ae60eed802445cf0132b9eb69934 (patch) | |
tree | b09da7582b5c4850d4db13aee808f2fef2f97de0 /cmd/mist/bindings.go | |
parent | 50fd46924900869e7210217c6a07979b544991c8 (diff) | |
parent | feef194829b07570e91873ed5d1e8cc51e8fa430 (diff) | |
download | dexon-69baa465ea69ae60eed802445cf0132b9eb69934.tar.gz dexon-69baa465ea69ae60eed802445cf0132b9eb69934.tar.zst dexon-69baa465ea69ae60eed802445cf0132b9eb69934.zip |
Merge eth-go repository into go-ethereum
mist, etheruem have been moved to cmd/
Diffstat (limited to 'cmd/mist/bindings.go')
-rw-r--r-- | cmd/mist/bindings.go | 139 |
1 files changed, 139 insertions, 0 deletions
diff --git a/cmd/mist/bindings.go b/cmd/mist/bindings.go new file mode 100644 index 000000000..639033a32 --- /dev/null +++ b/cmd/mist/bindings.go @@ -0,0 +1,139 @@ +package main + +import ( + "encoding/json" + "os" + "strconv" + + "github.com/ethereum/go-ethereum/ethchain" + "github.com/ethereum/go-ethereum/ethlog" + "github.com/ethereum/go-ethereum/ethpipe" + "github.com/ethereum/go-ethereum/ethutil" + "github.com/ethereum/go-ethereum/utils" +) + +type plugin struct { + Name string `json:"name"` + Path string `json:"path"` +} + +// LogPrint writes to the GUI log. +func (gui *Gui) LogPrint(level ethlog.LogLevel, msg string) { + /* + str := strings.TrimRight(s, "\n") + lines := strings.Split(str, "\n") + + view := gui.getObjectByName("infoView") + for _, line := range lines { + view.Call("addLog", line) + } + */ +} +func (gui *Gui) Transact(recipient, value, gas, gasPrice, d string) (*ethpipe.JSReceipt, error) { + var data string + if len(recipient) == 0 { + code, err := ethutil.Compile(d, false) + if err != nil { + return nil, err + } + data = ethutil.Bytes2Hex(code) + } else { + data = ethutil.Bytes2Hex(utils.FormatTransactionData(d)) + } + + return gui.pipe.Transact(gui.privateKey(), recipient, value, gas, gasPrice, data) +} + +func (gui *Gui) SetCustomIdentifier(customIdentifier string) { + gui.clientIdentity.SetCustomIdentifier(customIdentifier) + gui.config.Save("id", customIdentifier) +} + +func (gui *Gui) GetCustomIdentifier() string { + return gui.clientIdentity.GetCustomIdentifier() +} + +func (gui *Gui) ToggleTurboMining() { + gui.miner.ToggleTurbo() +} + +// functions that allow Gui to implement interface ethlog.LogSystem +func (gui *Gui) SetLogLevel(level ethlog.LogLevel) { + gui.logLevel = level + gui.stdLog.SetLogLevel(level) + gui.config.Save("loglevel", level) +} + +func (gui *Gui) GetLogLevel() ethlog.LogLevel { + return gui.logLevel +} + +func (self *Gui) AddPlugin(pluginPath string) { + self.plugins[pluginPath] = plugin{Name: pluginPath, Path: pluginPath} + + json, _ := json.MarshalIndent(self.plugins, "", " ") + ethutil.WriteFile(ethutil.Config.ExecPath+"/plugins.json", json) +} + +func (self *Gui) RemovePlugin(pluginPath string) { + delete(self.plugins, pluginPath) + + json, _ := json.MarshalIndent(self.plugins, "", " ") + ethutil.WriteFile(ethutil.Config.ExecPath+"/plugins.json", json) +} + +// this extra function needed to give int typecast value to gui widget +// that sets initial loglevel to default +func (gui *Gui) GetLogLevelInt() int { + return int(gui.logLevel) +} +func (self *Gui) DumpState(hash, path string) { + var stateDump []byte + + if len(hash) == 0 { + stateDump = self.eth.StateManager().CurrentState().Dump() + } else { + var block *ethchain.Block + if hash[0] == '#' { + i, _ := strconv.Atoi(hash[1:]) + block = self.eth.ChainManager().GetBlockByNumber(uint64(i)) + } else { + block = self.eth.ChainManager().GetBlock(ethutil.Hex2Bytes(hash)) + } + + if block == nil { + logger.Infof("block err: not found %s\n", hash) + return + } + + stateDump = block.State().Dump() + } + + file, err := os.OpenFile(path[7:], os.O_CREATE|os.O_RDWR, os.ModePerm) + if err != nil { + logger.Infoln("dump err: ", err) + return + } + defer file.Close() + + logger.Infof("dumped state (%s) to %s\n", hash, path) + + file.Write(stateDump) +} +func (gui *Gui) ToggleMining() { + var txt string + if gui.eth.Mining { + utils.StopMining(gui.eth) + txt = "Start mining" + + gui.getObjectByName("miningLabel").Set("visible", false) + } else { + utils.StartMining(gui.eth) + gui.miner = utils.GetMiner() + txt = "Stop mining" + + gui.getObjectByName("miningLabel").Set("visible", true) + } + + gui.win.Root().Set("miningButtonText", txt) +} |