core, trie: decode the value for storage dump (#19943)

* core, trie: decode the value for storage dump

* core/state: address comment
ChrisChinchilla-patch-3
gary rong 6 years ago committed by Péter Szilágyi
parent 8657a0d6b5
commit df6c08a485
  1. 7
      core/state/dump.go
  2. 4
      trie/iterator.go

@ -118,7 +118,12 @@ func (self *StateDB) dump(c collector, excludeCode, excludeStorage, excludeMissi
account.Storage = make(map[common.Hash]string) account.Storage = make(map[common.Hash]string)
storageIt := trie.NewIterator(obj.getTrie(self.db).NodeIterator(nil)) storageIt := trie.NewIterator(obj.getTrie(self.db).NodeIterator(nil))
for storageIt.Next() { for storageIt.Next() {
account.Storage[common.BytesToHash(self.trie.GetKey(storageIt.Key))] = common.Bytes2Hex(storageIt.Value) _, content, _, err := rlp.Split(storageIt.Value)
if err != nil {
log.Error("Failed to decode the value returned by iterator", "error", err)
continue
}
account.Storage[common.BytesToHash(self.trie.GetKey(storageIt.Key))] = common.Bytes2Hex(content)
} }
} }
c.onAccount(addr, account) c.onAccount(addr, account)

@ -34,7 +34,9 @@ type Iterator struct {
Err error Err error
} }
// NewIterator creates a new key-value iterator from a node iterator // NewIterator creates a new key-value iterator from a node iterator.
// Note that the value returned by the iterator is raw. If the content is encoded
// (e.g. storage value is RLP-encoded), it's caller's duty to decode it.
func NewIterator(it NodeIterator) *Iterator { func NewIterator(it NodeIterator) *Iterator {
return &Iterator{ return &Iterator{
nodeIt: it, nodeIt: it,

Loading…
Cancel
Save