erigon-pulse/cmd/mist/bindings.go

101 lines
2.6 KiB
Go
Raw Normal View History

2015-01-06 11:13:57 +00:00
/*
This file is part of go-ethereum
2014-10-23 13:48:53 +00:00
2015-01-06 11:13:57 +00: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 13:43:16 +00:00
package main
import (
"encoding/json"
"os"
"strconv"
2014-12-04 09:28:02 +00:00
2014-10-31 13:20:11 +00:00
"github.com/ethereum/go-ethereum/cmd/utils"
2014-12-04 09:28:02 +00:00
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethutil"
2015-01-07 12:17:48 +00:00
"github.com/ethereum/go-ethereum/state"
2014-08-23 13:43:16 +00:00
)
type plugin struct {
Name string `json:"name"`
Path string `json:"path"`
}
func (gui *Gui) Transact(from, recipient, value, gas, gasPrice, d string) (string, error) {
2014-08-23 13:43:16 +00:00
var data string
if len(recipient) == 0 {
code, err := ethutil.Compile(d, false)
if err != nil {
return "", err
2014-08-23 13:43:16 +00:00
}
data = ethutil.Bytes2Hex(code)
} else {
data = ethutil.Bytes2Hex(utils.FormatTransactionData(d))
}
return gui.xeth.Transact(from, recipient, value, gas, gasPrice, data)
2014-08-23 13:43:16 +00:00
}
func (self *Gui) AddPlugin(pluginPath string) {
2014-09-07 22:50:25 +00:00
self.plugins[pluginPath] = plugin{Name: pluginPath, Path: pluginPath}
2014-08-23 13:43:16 +00:00
json, _ := json.MarshalIndent(self.plugins, "", " ")
ethutil.WriteFile(self.eth.DataDir+"/plugins.json", json)
2014-08-23 13:43:16 +00:00
}
func (self *Gui) RemovePlugin(pluginPath string) {
delete(self.plugins, pluginPath)
json, _ := json.MarshalIndent(self.plugins, "", " ")
ethutil.WriteFile(self.eth.DataDir+"/plugins.json", json)
2014-08-23 13:43:16 +00:00
}
func (self *Gui) DumpState(hash, path string) {
var stateDump []byte
if len(hash) == 0 {
2014-12-10 18:59:12 +00:00
stateDump = self.eth.ChainManager().State().Dump()
2014-08-23 13:43:16 +00:00
} else {
var block *types.Block
2014-08-23 13:43:16 +00:00
if hash[0] == '#' {
i, _ := strconv.Atoi(hash[1:])
2014-10-20 10:03:31 +00:00
block = self.eth.ChainManager().GetBlockByNumber(uint64(i))
2014-08-23 13:43:16 +00:00
} else {
2014-10-20 10:03:31 +00:00
block = self.eth.ChainManager().GetBlock(ethutil.Hex2Bytes(hash))
2014-08-23 13:43:16 +00:00
}
if block == nil {
2014-10-31 11:56:05 +00:00
guilogger.Infof("block err: not found %s\n", hash)
2014-08-23 13:43:16 +00:00
return
}
stateDump = state.New(block.Root(), self.eth.StateDb()).Dump()
2014-08-23 13:43:16 +00:00
}
file, err := os.OpenFile(path[7:], os.O_CREATE|os.O_RDWR, os.ModePerm)
if err != nil {
2014-10-31 11:56:05 +00:00
guilogger.Infoln("dump err: ", err)
2014-08-23 13:43:16 +00:00
return
}
defer file.Close()
2014-10-31 11:56:05 +00:00
guilogger.Infof("dumped state (%s) to %s\n", hash, path)
2014-08-23 13:43:16 +00:00
file.Write(stateDump)
}