func (self *JSRE) dump(call otto.FunctionCall) otto.Value { var state *ethstate.State if len(call.ArgumentList) > 0 { var block *ethchain.Block if call.Argument(0).IsNumber() { num, _ := call.Argument(0).ToInteger() block = self.ethereum.BlockChain().GetBlockByNumber(uint64(num)) } else if call.Argument(0).IsString() { hash, _ := call.Argument(0).ToString() block = self.ethereum.BlockChain().GetBlock(ethutil.Hex2Bytes(hash)) } else { fmt.Println("invalid argument for dump. Either hex string or number") } if block == nil { fmt.Println("block not found") return otto.UndefinedValue() } state = block.State() } else { state = self.ethereum.StateManager().CurrentState() } v, _ := self.Vm.ToValue(state.Dump()) return v }
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) }
func main() { runtime.GOMAXPROCS(runtime.NumCPU()) utils.HandleInterrupt() // precedence: code-internal flag default < config file < environment variables < command line Init() // parsing command line // If the difftool option is selected ignore all other log output if DiffTool || Dump { LogLevel = 0 } utils.InitConfig(ConfigFile, Datadir, "ETH") ethutil.Config.Diff = DiffTool ethutil.Config.DiffType = DiffType utils.InitDataDir(Datadir) utils.InitLogging(Datadir, LogFile, LogLevel, DebugFile) db := utils.NewDatabase() keyManager := utils.NewKeyManager(KeyStore, Datadir, db) // create, import, export keys utils.KeyTasks(keyManager, KeyRing, GenAddr, SecretFile, ExportDir, NonInteractive) clientIdentity := utils.NewClientIdentity(ClientIdentifier, Version, Identifier) ethereum := utils.NewEthereum(db, clientIdentity, keyManager, UseUPnP, OutboundPort, MaxPeer) if Dump { var block *ethchain.Block if len(DumpHash) == 0 && DumpNumber == -1 { block = ethereum.BlockChain().CurrentBlock } else if len(DumpHash) > 0 { block = ethereum.BlockChain().GetBlock(ethutil.Hex2Bytes(DumpHash)) } else { block = ethereum.BlockChain().GetBlockByNumber(uint64(DumpNumber)) } if block == nil { fmt.Fprintln(os.Stderr, "block not found") // We want to output valid JSON fmt.Println("{}") os.Exit(1) } // Leave the Println. This needs clean output for piping fmt.Printf("%s\n", block.State().Dump()) os.Exit(0) } if ShowGenesis { utils.ShowGenesis(ethereum) } if StartMining { utils.StartMining(ethereum) } // better reworked as cases if StartJsConsole { InitJsConsole(ethereum) } else if len(InputFile) > 0 { ExecJsFile(ethereum, InputFile) } if StartRpc { utils.StartRpc(ethereum, RpcPort) } utils.StartEthereum(ethereum, UseSeed) // this blocks the thread ethereum.WaitForShutdown() ethlog.Flush() }