aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2017-04-19 18:09:04 +0800
committerFelix Lange <fjl@twurst.com>2017-04-25 08:14:32 +0800
commit207bd7d2cddbf16ac2cb870fd6a1c558f02fd8ac (patch)
tree76f8494516a78869b98804bbaa34fc10240adbdf /core
parent4047ccad2fb73fd2cfd69bf5b8cbfa788871ce0f (diff)
downloaddexon-207bd7d2cddbf16ac2cb870fd6a1c558f02fd8ac.tar
dexon-207bd7d2cddbf16ac2cb870fd6a1c558f02fd8ac.tar.gz
dexon-207bd7d2cddbf16ac2cb870fd6a1c558f02fd8ac.tar.bz2
dexon-207bd7d2cddbf16ac2cb870fd6a1c558f02fd8ac.tar.lz
dexon-207bd7d2cddbf16ac2cb870fd6a1c558f02fd8ac.tar.xz
dexon-207bd7d2cddbf16ac2cb870fd6a1c558f02fd8ac.tar.zst
dexon-207bd7d2cddbf16ac2cb870fd6a1c558f02fd8ac.zip
eth: add debug_storageRangeAt
Diffstat (limited to 'core')
-rw-r--r--core/state/state_object.go9
-rw-r--r--core/state/statedb.go11
2 files changed, 18 insertions, 2 deletions
diff --git a/core/state/state_object.go b/core/state/state_object.go
index 7d3315303..dcad9d068 100644
--- a/core/state/state_object.go
+++ b/core/state/state_object.go
@@ -201,7 +201,7 @@ func (self *stateObject) setState(key, value common.Hash) {
}
// updateTrie writes cached storage modifications into the object's storage trie.
-func (self *stateObject) updateTrie(db trie.Database) {
+func (self *stateObject) updateTrie(db trie.Database) *trie.SecureTrie {
tr := self.getTrie(db)
for key, value := range self.dirtyStorage {
delete(self.dirtyStorage, key)
@@ -213,6 +213,7 @@ func (self *stateObject) updateTrie(db trie.Database) {
v, _ := rlp.EncodeToBytes(bytes.TrimLeft(value[:], "\x00"))
tr.Update(key[:], v)
}
+ return tr
}
// UpdateRoot sets the trie root to the current root hash of
@@ -280,7 +281,11 @@ func (c *stateObject) ReturnGas(gas *big.Int) {}
func (self *stateObject) deepCopy(db *StateDB, onDirty func(addr common.Address)) *stateObject {
stateObject := newObject(db, self.address, self.data, onDirty)
- stateObject.trie = self.trie
+ if self.trie != nil {
+ // A shallow copy makes the two tries independent.
+ cpy := *self.trie
+ stateObject.trie = &cpy
+ }
stateObject.code = self.code
stateObject.dirtyStorage = self.dirtyStorage.Copy()
stateObject.cachedStorage = self.dirtyStorage.Copy()
diff --git a/core/state/statedb.go b/core/state/statedb.go
index 431f33e02..3b753a2e6 100644
--- a/core/state/statedb.go
+++ b/core/state/statedb.go
@@ -296,6 +296,17 @@ func (self *StateDB) GetState(a common.Address, b common.Hash) common.Hash {
return common.Hash{}
}
+// StorageTrie returns the storage trie of an account.
+// The return value is a copy and is nil for non-existent accounts.
+func (self *StateDB) StorageTrie(a common.Address) *trie.SecureTrie {
+ stateObject := self.getStateObject(a)
+ if stateObject == nil {
+ return nil
+ }
+ cpy := stateObject.deepCopy(self, nil)
+ return cpy.updateTrie(self.db)
+}
+
func (self *StateDB) HasSuicided(addr common.Address) bool {
stateObject := self.getStateObject(addr)
if stateObject != nil {