diff options
Diffstat (limited to 'ethereal/gui.go')
-rw-r--r-- | ethereal/gui.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/ethereal/gui.go b/ethereal/gui.go index 066db48b9..6149b39b7 100644 --- a/ethereal/gui.go +++ b/ethereal/gui.go @@ -4,6 +4,7 @@ import ( "bytes" "fmt" "math/big" + "os" "strconv" "strings" "time" @@ -155,6 +156,40 @@ func (gui *Gui) showWallet(context *qml.Context) (*qml.Window, error) { return gui.win, nil } +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.BlockChain().GetBlockByNumber(uint64(i)) + } else { + block = self.eth.BlockChain().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) +} + // The done handler will be called by QML when all views have been loaded func (gui *Gui) Done() { gui.qmlDone = true |