diff options
author | obscuren <geffobscura@gmail.com> | 2014-07-21 17:56:04 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-07-21 17:56:04 +0800 |
commit | 93261b98c2bc664af30676129def291ff9e8a9ce (patch) | |
tree | 5974e89344e6222908dbb6a398b9453b276254f8 /ethchain/state_object.go | |
parent | 9f00aeae29d53fec358fcecdc9bcc162b8e3984c (diff) | |
download | dexon-93261b98c2bc664af30676129def291ff9e8a9ce.tar dexon-93261b98c2bc664af30676129def291ff9e8a9ce.tar.gz dexon-93261b98c2bc664af30676129def291ff9e8a9ce.tar.bz2 dexon-93261b98c2bc664af30676129def291ff9e8a9ce.tar.lz dexon-93261b98c2bc664af30676129def291ff9e8a9ce.tar.xz dexon-93261b98c2bc664af30676129def291ff9e8a9ce.tar.zst dexon-93261b98c2bc664af30676129def291ff9e8a9ce.zip |
Changed iterator
Diffstat (limited to 'ethchain/state_object.go')
-rw-r--r-- | ethchain/state_object.go | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/ethchain/state_object.go b/ethchain/state_object.go index 8e7b5fece..184609015 100644 --- a/ethchain/state_object.go +++ b/ethchain/state_object.go @@ -151,6 +151,24 @@ func (self *StateObject) setStorage(k []byte, value *ethutil.Value) { */ } +// Iterate over each storage address and yield callback +func (self *StateObject) EachStorage(cb ethtrie.EachCallback) { + // First loop over the uncommit/cached values in storage + for key, value := range self.storage { + // XXX Most iterators Fns as it stands require encoded values + encoded := ethutil.NewValue(value.Encode()) + cb(key, encoded) + } + + it := self.state.trie.NewIterator() + it.Each(func(key string, value *ethutil.Value) { + // If it's cached don't call the callback. + if self.storage[key] == nil { + cb(key, value) + } + }) +} + func (self *StateObject) Sync() { /* fmt.Println("############# BEFORE ################") @@ -303,6 +321,14 @@ func (c *StateObject) Init() Code { return c.initScript } +// Debug stuff +func (self *StateObject) CreateOutputForDiff() { + fmt.Printf("%x %x %x %x\n", self.Address(), self.state.Root(), self.Amount.Bytes(), self.Nonce) + self.EachStorage(func(addr string, value *ethutil.Value) { + fmt.Printf("%x %x\n", addr, value.Bytes()) + }) +} + // // Encoding // |