2014-10-23 08:48:53 -05:00
|
|
|
// Copyright (c) 2013-2014, Jeffrey Wilcke. All rights reserved.
|
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2.1 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this library; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
// MA 02110-1301 USA
|
|
|
|
|
2014-08-23 08:43:16 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"os"
|
|
|
|
"strconv"
|
2014-12-04 03:28:02 -06:00
|
|
|
|
2014-10-31 08:20:11 -05:00
|
|
|
"github.com/ethereum/go-ethereum/cmd/utils"
|
2014-12-04 03:28:02 -06:00
|
|
|
"github.com/ethereum/go-ethereum/core/types"
|
2014-10-23 08:01:27 -05:00
|
|
|
"github.com/ethereum/go-ethereum/ethutil"
|
2014-10-31 06:56:05 -05:00
|
|
|
"github.com/ethereum/go-ethereum/logger"
|
2014-08-23 08:43:16 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
type plugin struct {
|
|
|
|
Name string `json:"name"`
|
|
|
|
Path string `json:"path"`
|
|
|
|
}
|
|
|
|
|
2014-10-16 05:07:16 -05:00
|
|
|
// LogPrint writes to the GUI log.
|
2014-10-31 06:56:05 -05:00
|
|
|
func (gui *Gui) LogPrint(level logger.LogLevel, msg string) {
|
2014-08-23 08:43:16 -05:00
|
|
|
/*
|
|
|
|
str := strings.TrimRight(s, "\n")
|
|
|
|
lines := strings.Split(str, "\n")
|
|
|
|
|
|
|
|
view := gui.getObjectByName("infoView")
|
|
|
|
for _, line := range lines {
|
|
|
|
view.Call("addLog", line)
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
}
|
2014-12-01 13:18:09 -06:00
|
|
|
func (gui *Gui) Transact(recipient, value, gas, gasPrice, d string) (string, error) {
|
2014-08-23 08:43:16 -05:00
|
|
|
var data string
|
|
|
|
if len(recipient) == 0 {
|
|
|
|
code, err := ethutil.Compile(d, false)
|
|
|
|
if err != nil {
|
2014-12-01 13:18:09 -06:00
|
|
|
return "", err
|
2014-08-23 08:43:16 -05:00
|
|
|
}
|
|
|
|
data = ethutil.Bytes2Hex(code)
|
|
|
|
} else {
|
|
|
|
data = ethutil.Bytes2Hex(utils.FormatTransactionData(d))
|
|
|
|
}
|
|
|
|
|
2015-01-05 12:53:53 -06:00
|
|
|
return gui.xeth.Transact(gui.privateKey(), recipient, value, gas, gasPrice, data)
|
2014-08-23 08:43:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) SetCustomIdentifier(customIdentifier string) {
|
|
|
|
gui.clientIdentity.SetCustomIdentifier(customIdentifier)
|
|
|
|
gui.config.Save("id", customIdentifier)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) GetCustomIdentifier() string {
|
|
|
|
return gui.clientIdentity.GetCustomIdentifier()
|
|
|
|
}
|
|
|
|
|
2014-10-31 06:56:05 -05:00
|
|
|
// functions that allow Gui to implement interface guilogger.LogSystem
|
|
|
|
func (gui *Gui) SetLogLevel(level logger.LogLevel) {
|
2014-08-23 08:43:16 -05:00
|
|
|
gui.logLevel = level
|
2015-01-04 07:20:16 -06:00
|
|
|
gui.eth.Logger().SetLogLevel(level)
|
2014-08-23 08:43:16 -05:00
|
|
|
gui.config.Save("loglevel", level)
|
|
|
|
}
|
|
|
|
|
2014-10-31 06:56:05 -05:00
|
|
|
func (gui *Gui) GetLogLevel() logger.LogLevel {
|
2014-08-23 08:43:16 -05:00
|
|
|
return gui.logLevel
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self *Gui) AddPlugin(pluginPath string) {
|
2014-09-07 17:50:25 -05:00
|
|
|
self.plugins[pluginPath] = plugin{Name: pluginPath, Path: pluginPath}
|
2014-08-23 08:43:16 -05:00
|
|
|
|
|
|
|
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 {
|
2014-12-10 12:59:12 -06:00
|
|
|
stateDump = self.eth.ChainManager().State().Dump()
|
2014-08-23 08:43:16 -05:00
|
|
|
} else {
|
2014-11-18 09:58:22 -06:00
|
|
|
var block *types.Block
|
2014-08-23 08:43:16 -05:00
|
|
|
if hash[0] == '#' {
|
|
|
|
i, _ := strconv.Atoi(hash[1:])
|
2014-10-20 05:03:31 -05:00
|
|
|
block = self.eth.ChainManager().GetBlockByNumber(uint64(i))
|
2014-08-23 08:43:16 -05:00
|
|
|
} else {
|
2014-10-20 05:03:31 -05:00
|
|
|
block = self.eth.ChainManager().GetBlock(ethutil.Hex2Bytes(hash))
|
2014-08-23 08:43:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if block == nil {
|
2014-10-31 06:56:05 -05:00
|
|
|
guilogger.Infof("block err: not found %s\n", hash)
|
2014-08-23 08:43:16 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
stateDump = block.State().Dump()
|
|
|
|
}
|
|
|
|
|
|
|
|
file, err := os.OpenFile(path[7:], os.O_CREATE|os.O_RDWR, os.ModePerm)
|
|
|
|
if err != nil {
|
2014-10-31 06:56:05 -05:00
|
|
|
guilogger.Infoln("dump err: ", err)
|
2014-08-23 08:43:16 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
defer file.Close()
|
|
|
|
|
2014-10-31 06:56:05 -05:00
|
|
|
guilogger.Infof("dumped state (%s) to %s\n", hash, path)
|
2014-08-23 08:43:16 -05:00
|
|
|
|
|
|
|
file.Write(stateDump)
|
|
|
|
}
|