From 60050ddf334db6ad4b230460d42d4270d4bc7b7c Mon Sep 17 00:00:00 2001 From: rjl493456442 Date: Mon, 12 Aug 2019 19:44:33 +0800 Subject: [PATCH] core, trie: decode the value for storage dump --- core/state/dump.go | 7 ++++++- trie/iterator.go | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/core/state/dump.go b/core/state/dump.go index 51d3e5554f..771c457f6b 100644 --- a/core/state/dump.go +++ b/core/state/dump.go @@ -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(it.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) diff --git a/trie/iterator.go b/trie/iterator.go index da93b2fadb..8e84dee3b6 100644 --- a/trie/iterator.go +++ b/trie/iterator.go @@ -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,