diff options
author | Jeffrey Wilcke <geffobscura@gmail.com> | 2015-06-24 01:19:33 +0800 |
---|---|---|
committer | Jeffrey Wilcke <geffobscura@gmail.com> | 2015-06-24 01:19:33 +0800 |
commit | 72e2613a9fe3205fa5a67b72b832e03b2357ee88 (patch) | |
tree | bbc987510d279d9e174ff8f684158d668131661e /core/state/statedb.go | |
parent | 5daf8729be88eca87b302ebf7a46fc69cad0f6d0 (diff) | |
parent | 67e6f74e9af00ff011a6a02f18644804eb18cdaa (diff) | |
download | go-tangerine-0.9.32.tar go-tangerine-0.9.32.tar.gz go-tangerine-0.9.32.tar.bz2 go-tangerine-0.9.32.tar.lz go-tangerine-0.9.32.tar.xz go-tangerine-0.9.32.tar.zst go-tangerine-0.9.32.zip |
Merge branch 'release/0.9.32'v0.9.32
Diffstat (limited to 'core/state/statedb.go')
-rw-r--r-- | core/state/statedb.go | 46 |
1 files changed, 16 insertions, 30 deletions
diff --git a/core/state/statedb.go b/core/state/statedb.go index b3050515b..f6f63f329 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -21,7 +21,7 @@ type StateDB struct { stateObjects map[string]*StateObject - refund map[string]*big.Int + refund *big.Int thash, bhash common.Hash txIndex int @@ -31,7 +31,7 @@ type StateDB struct { // Create a new state from a given trie func New(root common.Hash, db common.Database) *StateDB { trie := trie.NewSecure(root[:], db) - return &StateDB{db: db, trie: trie, stateObjects: make(map[string]*StateObject), refund: make(map[string]*big.Int), logs: make(map[common.Hash]Logs)} + return &StateDB{db: db, trie: trie, stateObjects: make(map[string]*StateObject), refund: new(big.Int), logs: make(map[common.Hash]Logs)} } func (self *StateDB) PrintRoot() { @@ -63,12 +63,8 @@ func (self *StateDB) Logs() Logs { return logs } -func (self *StateDB) Refund(address common.Address, gas *big.Int) { - addr := address.Str() - if self.refund[addr] == nil { - self.refund[addr] = new(big.Int) - } - self.refund[addr].Add(self.refund[addr], gas) +func (self *StateDB) Refund(gas *big.Int) { + self.refund.Add(self.refund, gas) } /* @@ -107,13 +103,13 @@ func (self *StateDB) GetCode(addr common.Address) []byte { return nil } -func (self *StateDB) GetState(a common.Address, b common.Hash) []byte { +func (self *StateDB) GetState(a common.Address, b common.Hash) common.Hash { stateObject := self.GetStateObject(a) if stateObject != nil { - return stateObject.GetState(b).Bytes() + return stateObject.GetState(b) } - return nil + return common.Hash{} } func (self *StateDB) IsDeleted(addr common.Address) bool { @@ -149,10 +145,10 @@ func (self *StateDB) SetCode(addr common.Address, code []byte) { } } -func (self *StateDB) SetState(addr common.Address, key common.Hash, value interface{}) { +func (self *StateDB) SetState(addr common.Address, key common.Hash, value common.Hash) { stateObject := self.GetOrNewStateObject(addr) if stateObject != nil { - stateObject.SetState(key, common.NewValue(value)) + stateObject.SetState(key, value) } } @@ -263,14 +259,12 @@ func (s *StateDB) Cmp(other *StateDB) bool { func (self *StateDB) Copy() *StateDB { state := New(common.Hash{}, self.db) - state.trie = self.trie.Copy() + state.trie = self.trie for k, stateObject := range self.stateObjects { state.stateObjects[k] = stateObject.Copy() } - for addr, refund := range self.refund { - state.refund[addr] = new(big.Int).Set(refund) - } + state.refund.Set(self.refund) for hash, logs := range self.logs { state.logs[hash] = make(Logs, len(logs)) @@ -302,10 +296,6 @@ func (s *StateDB) Reset() { // Reset all nested states for _, stateObject := range s.stateObjects { - if stateObject.State == nil { - continue - } - stateObject.Reset() } @@ -316,11 +306,7 @@ func (s *StateDB) Reset() { func (s *StateDB) Sync() { // Sync all nested states for _, stateObject := range s.stateObjects { - if stateObject.State == nil { - continue - } - - stateObject.State.Sync() + stateObject.trie.Commit() } s.trie.Commit() @@ -330,22 +316,22 @@ func (s *StateDB) Sync() { func (self *StateDB) Empty() { self.stateObjects = make(map[string]*StateObject) - self.refund = make(map[string]*big.Int) + self.refund = new(big.Int) } -func (self *StateDB) Refunds() map[string]*big.Int { +func (self *StateDB) Refunds() *big.Int { return self.refund } func (self *StateDB) Update() { - self.refund = make(map[string]*big.Int) + self.refund = new(big.Int) for _, stateObject := range self.stateObjects { if stateObject.dirty { if stateObject.remove { self.DeleteStateObject(stateObject) } else { - stateObject.Sync() + stateObject.Update() self.UpdateStateObject(stateObject) } |