core/state: simplify dump

This commit is contained in:
Felix Lange 2017-09-15 12:13:22 +02:00
parent cb63bbef86
commit 0d01e0a929

View file

@ -52,20 +52,18 @@ func (self *StateDB) RawDump() Dump {
if err := rlp.DecodeBytes(it.Value, &data); err != nil { if err := rlp.DecodeBytes(it.Value, &data); err != nil {
panic(err) panic(err)
} }
code, _ := self.db.ContractCode(common.BytesToHash(it.Key), common.BytesToHash(data.CodeHash))
obj := newObject(nil, common.BytesToAddress(addr), data, nil)
account := DumpAccount{ account := DumpAccount{
Balance: data.Balance.String(), Balance: data.Balance.String(),
Nonce: data.Nonce, Nonce: data.Nonce,
Root: common.Bytes2Hex(data.Root[:]), Root: common.Bytes2Hex(data.Root[:]),
CodeHash: common.Bytes2Hex(data.CodeHash), CodeHash: common.Bytes2Hex(data.CodeHash),
Code: common.Bytes2Hex(obj.Code(self.db)), Code: common.Bytes2Hex(code),
Storage: make(map[string]string), Storage: make(map[string]string),
} }
so := self.getStateObject(common.BytesToAddress(addr)) storage := self.StorageTrie(common.BytesToAddress(addr))
storageIt := trie.NewIterator(so.getTrie(self.db).NodeIterator(nil)) for it := trie.NewIterator(storage.NodeIterator(nil)); it.Next(); {
for storageIt.Next() { account.Storage[common.Bytes2Hex(storage.GetKey(it.Key))] = common.Bytes2Hex(it.Value)
account.Storage[common.Bytes2Hex(so.getTrie(self.db).GetKey(storageIt.Key))] = common.Bytes2Hex(storageIt.Value)
} }
dump.Accounts[common.Bytes2Hex(addr)] = account dump.Accounts[common.Bytes2Hex(addr)] = account
} }
@ -77,6 +75,5 @@ func (self *StateDB) Dump() []byte {
if err != nil { if err != nil {
fmt.Println("dump err", err) fmt.Println("dump err", err)
} }
return json return json
} }