Skip to content

Commit

Permalink
core, trie: decode the value for storage dump (#19943)
Browse files Browse the repository at this point in the history
* core, trie: decode the value for storage dump

* core/state: address comment
  • Loading branch information
rjl493456442 authored and karalabe committed Aug 12, 2019
1 parent 8657a0d commit df6c08a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 6 additions & 1 deletion core/state/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,12 @@ func (self *StateDB) dump(c collector, excludeCode, excludeStorage, excludeMissi
account.Storage = make(map[common.Hash]string)
storageIt := trie.NewIterator(obj.getTrie(self.db).NodeIterator(nil))
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)
Expand Down
4 changes: 3 additions & 1 deletion trie/iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ type Iterator struct {
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 {
return &Iterator{
nodeIt: it,
Expand Down

0 comments on commit df6c08a

Please sign in to comment.