2015-01-06 13:13:57 +02:00
|
|
|
/*
|
|
|
|
This file is part of go-ethereum
|
2014-10-23 16:48:53 +03:00
|
|
|
|
2015-01-06 13:13:57 +02:00
|
|
|
go-ethereum 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 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
go-ethereum 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 go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @authors
|
|
|
|
* Jeffrey Wilcke <i@jev.io>
|
|
|
|
*/
|
2014-08-23 16:43:16 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2015-03-25 16:58:52 +02:00
|
|
|
"io/ioutil"
|
2014-08-23 16:43:16 +03:00
|
|
|
"os"
|
|
|
|
"strconv"
|
2014-12-04 11:28:02 +02:00
|
|
|
|
2014-10-31 15:20:11 +02:00
|
|
|
"github.com/ethereum/go-ethereum/cmd/utils"
|
2015-03-16 12:27:38 +02:00
|
|
|
"github.com/ethereum/go-ethereum/common"
|
2015-03-23 17:59:09 +02:00
|
|
|
"github.com/ethereum/go-ethereum/core/state"
|
2015-03-25 16:58:52 +02:00
|
|
|
"github.com/ethereum/go-ethereum/core/types"
|
2014-08-23 16:43:16 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
type plugin struct {
|
|
|
|
Name string `json:"name"`
|
|
|
|
Path string `json:"path"`
|
|
|
|
}
|
|
|
|
|
2015-02-26 14:22:09 +02:00
|
|
|
func (gui *Gui) Transact(from, recipient, value, gas, gasPrice, d string) (string, error) {
|
2015-03-16 17:31:08 +02:00
|
|
|
d = common.Bytes2Hex(utils.FormatTransactionData(d))
|
|
|
|
|
|
|
|
return gui.xeth.Transact(from, recipient, value, gas, gasPrice, d)
|
2014-08-23 16:43:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (self *Gui) AddPlugin(pluginPath string) {
|
2014-09-08 01:50:25 +03:00
|
|
|
self.plugins[pluginPath] = plugin{Name: pluginPath, Path: pluginPath}
|
2014-08-23 16:43:16 +03:00
|
|
|
|
|
|
|
json, _ := json.MarshalIndent(self.plugins, "", " ")
|
2015-03-25 16:58:52 +02:00
|
|
|
ioutil.WriteFile(self.eth.DataDir+"/plugins.json", json, os.ModePerm)
|
2014-08-23 16:43:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (self *Gui) RemovePlugin(pluginPath string) {
|
|
|
|
delete(self.plugins, pluginPath)
|
|
|
|
|
|
|
|
json, _ := json.MarshalIndent(self.plugins, "", " ")
|
2015-03-25 16:58:52 +02:00
|
|
|
ioutil.WriteFile(self.eth.DataDir+"/plugins.json", json, os.ModePerm)
|
2014-08-23 16:43:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (self *Gui) DumpState(hash, path string) {
|
|
|
|
var stateDump []byte
|
|
|
|
|
|
|
|
if len(hash) == 0 {
|
2014-12-10 20:59:12 +02:00
|
|
|
stateDump = self.eth.ChainManager().State().Dump()
|
2014-08-23 16:43:16 +03:00
|
|
|
} else {
|
2014-11-18 17:58:22 +02:00
|
|
|
var block *types.Block
|
2014-08-23 16:43:16 +03:00
|
|
|
if hash[0] == '#' {
|
|
|
|
i, _ := strconv.Atoi(hash[1:])
|
2014-10-20 13:03:31 +03:00
|
|
|
block = self.eth.ChainManager().GetBlockByNumber(uint64(i))
|
2014-08-23 16:43:16 +03:00
|
|
|
} else {
|
2015-03-22 15:25:33 +02:00
|
|
|
block = self.eth.ChainManager().GetBlock(common.HexToHash(hash))
|
2014-08-23 16:43:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if block == nil {
|
2014-10-31 13:56:05 +02:00
|
|
|
guilogger.Infof("block err: not found %s\n", hash)
|
2014-08-23 16:43:16 +03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2015-03-06 19:26:16 +02:00
|
|
|
stateDump = state.New(block.Root(), self.eth.StateDb()).Dump()
|
2014-08-23 16:43:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
file, err := os.OpenFile(path[7:], os.O_CREATE|os.O_RDWR, os.ModePerm)
|
|
|
|
if err != nil {
|
2014-10-31 13:56:05 +02:00
|
|
|
guilogger.Infoln("dump err: ", err)
|
2014-08-23 16:43:16 +03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
defer file.Close()
|
|
|
|
|
2014-10-31 13:56:05 +02:00
|
|
|
guilogger.Infof("dumped state (%s) to %s\n", hash, path)
|
2014-08-23 16:43:16 +03:00
|
|
|
|
|
|
|
file.Write(stateDump)
|
|
|
|
}
|