diff options
author | obscuren <geffobscura@gmail.com> | 2015-03-17 00:09:08 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-03-17 00:09:08 +0800 |
commit | e620bde405161771ea7ecd1cee8641eb9265465e (patch) | |
tree | f41b8f98215a2db7aa59e11ce107724b978f759d /state/state_object.go | |
parent | 76f215b0feca1fc56890fe5f9ec1acbed79cb701 (diff) | |
download | dexon-e620bde405161771ea7ecd1cee8641eb9265465e.tar dexon-e620bde405161771ea7ecd1cee8641eb9265465e.tar.gz dexon-e620bde405161771ea7ecd1cee8641eb9265465e.tar.bz2 dexon-e620bde405161771ea7ecd1cee8641eb9265465e.tar.lz dexon-e620bde405161771ea7ecd1cee8641eb9265465e.tar.xz dexon-e620bde405161771ea7ecd1cee8641eb9265465e.tar.zst dexon-e620bde405161771ea7ecd1cee8641eb9265465e.zip |
conversion state
Diffstat (limited to 'state/state_object.go')
-rw-r--r-- | state/state_object.go | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/state/state_object.go b/state/state_object.go index 396577a75..853703350 100644 --- a/state/state_object.go +++ b/state/state_object.go @@ -109,7 +109,7 @@ func NewStateObjectFromBytes(address common.Address, data []byte, db common.Data object.nonce = extobject.Nonce object.balance = extobject.Balance object.codeHash = extobject.CodeHash - object.State = New(extobject.Root, db) + object.State = New(extobject.Root[:], db) object.storage = make(map[string]*common.Value) object.gasPool = new(big.Int) object.prepaid = new(big.Int) @@ -124,8 +124,8 @@ func (self *StateObject) MarkForDeletion() { statelogger.Debugf("%x: #%d %v X\n", self.Address(), self.nonce, self.balance) } -func (c *StateObject) getAddr(addr []byte) *common.Value { - return common.NewValueFromBytes([]byte(c.State.trie.Get(addr))) +func (c *StateObject) getAddr(addr common.Hash) *common.Value { + return common.NewValueFromBytes([]byte(c.State.trie.Get(addr[:]))) } func (c *StateObject) setAddr(addr []byte, value interface{}) { @@ -133,34 +133,32 @@ func (c *StateObject) setAddr(addr []byte, value interface{}) { } func (self *StateObject) GetStorage(key *big.Int) *common.Value { - return self.GetState(key.Bytes()) + return self.GetState(common.BytesToHash(key.Bytes())) } func (self *StateObject) SetStorage(key *big.Int, value *common.Value) { - self.SetState(key.Bytes(), value) + self.SetState(common.BytesToHash(key.Bytes()), value) } func (self *StateObject) Storage() Storage { return self.storage } -func (self *StateObject) GetState(k []byte) *common.Value { - key := common.LeftPadBytes(k, 32) - - value := self.storage[string(key)] +func (self *StateObject) GetState(key common.Hash) *common.Value { + strkey := key.Str() + value := self.storage[strkey] if value == nil { value = self.getAddr(key) if !value.IsNil() { - self.storage[string(key)] = value + self.storage[strkey] = value } } return value } -func (self *StateObject) SetState(k []byte, value *common.Value) { - key := common.LeftPadBytes(k, 32) - self.storage[string(key)] = value.Copy() +func (self *StateObject) SetState(k common.Hash, value *common.Value) { + self.storage[k.Str()] = value.Copy() self.dirty = true } |