diff options
author | obscuren <geffobscura@gmail.com> | 2014-12-20 09:34:12 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-12-20 09:34:12 +0800 |
commit | 3983dd2428137211f84f299f9ce8690c22f50afd (patch) | |
tree | 3a2dc53b365e6f377fc82a3514150d1297fe549c /state/dump.go | |
parent | 7daa8c2f6eb25511c6a54ad420709af911fc6748 (diff) | |
parent | 0a9dc1536c5d776844d6947a0090ff7e1a7c6ab4 (diff) | |
download | go-tangerine-vv0.7.10.tar go-tangerine-vv0.7.10.tar.gz go-tangerine-vv0.7.10.tar.bz2 go-tangerine-vv0.7.10.tar.lz go-tangerine-vv0.7.10.tar.xz go-tangerine-vv0.7.10.tar.zst go-tangerine-vv0.7.10.zip |
Merge branch 'release/v0.7.10'vv0.7.10
Diffstat (limited to 'state/dump.go')
-rw-r--r-- | state/dump.go | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/state/dump.go b/state/dump.go new file mode 100644 index 000000000..c1f5ecf3a --- /dev/null +++ b/state/dump.go @@ -0,0 +1,56 @@ +package state + +import ( + "encoding/json" + "fmt" + + "github.com/ethereum/go-ethereum/ethutil" +) + +type Account struct { + Balance string `json:"balance"` + Nonce uint64 `json:"nonce"` + Root string `json:"root"` + CodeHash string `json:"codeHash"` + Storage map[string]string `json:"storage"` +} + +type World struct { + Root string `json:"root"` + Accounts map[string]Account `json:"accounts"` +} + +func (self *StateDB) Dump() []byte { + world := World{ + Root: ethutil.Bytes2Hex(self.Trie.GetRoot()), + Accounts: make(map[string]Account), + } + + self.Trie.NewIterator().Each(func(key string, value *ethutil.Value) { + stateObject := NewStateObjectFromBytes([]byte(key), value.Bytes()) + + account := Account{Balance: stateObject.balance.String(), Nonce: stateObject.Nonce, Root: ethutil.Bytes2Hex(stateObject.Root()), CodeHash: ethutil.Bytes2Hex(stateObject.codeHash)} + account.Storage = make(map[string]string) + + stateObject.EachStorage(func(key string, value *ethutil.Value) { + value.Decode() + account.Storage[ethutil.Bytes2Hex([]byte(key))] = ethutil.Bytes2Hex(value.Bytes()) + }) + world.Accounts[ethutil.Bytes2Hex([]byte(key))] = account + }) + + json, err := json.MarshalIndent(world, "", " ") + if err != nil { + fmt.Println("dump err", err) + } + + return json +} + +// Debug stuff +func (self *StateObject) CreateOutputForDiff() { + fmt.Printf("%x %x %x %x\n", self.Address(), self.State.Root(), self.balance.Bytes(), self.Nonce) + self.EachStorage(func(addr string, value *ethutil.Value) { + fmt.Printf("%x %x\n", addr, value.Bytes()) + }) +} |