aboutsummaryrefslogtreecommitdiffstats
path: root/core/state/statedb.go
diff options
context:
space:
mode:
Diffstat (limited to 'core/state/statedb.go')
-rw-r--r--core/state/statedb.go22
1 files changed, 14 insertions, 8 deletions
diff --git a/core/state/statedb.go b/core/state/statedb.go
index a9de71409..ab93870bf 100644
--- a/core/state/statedb.go
+++ b/core/state/statedb.go
@@ -18,6 +18,7 @@
package state
import (
+ "fmt"
"math/big"
"github.com/ethereum/go-ethereum/common"
@@ -25,6 +26,7 @@ import (
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger/glog"
+ "github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/trie"
)
@@ -205,13 +207,15 @@ func (self *StateDB) Delete(addr common.Address) bool {
// Update the given state object and apply it to state trie
func (self *StateDB) UpdateStateObject(stateObject *StateObject) {
- //addr := stateObject.Address()
-
- if len(stateObject.CodeHash()) > 0 {
- self.db.Put(stateObject.CodeHash(), stateObject.code)
+ if len(stateObject.code) > 0 {
+ self.db.Put(stateObject.codeHash, stateObject.code)
}
addr := stateObject.Address()
- self.trie.Update(addr[:], stateObject.RlpEncode())
+ data, err := rlp.EncodeToBytes(stateObject)
+ if err != nil {
+ panic(fmt.Errorf("can't encode object at %x: %v", addr[:], err))
+ }
+ self.trie.Update(addr[:], data)
}
// Delete the given state object and delete it from the state trie
@@ -238,10 +242,12 @@ func (self *StateDB) GetStateObject(addr common.Address) (stateObject *StateObje
if len(data) == 0 {
return nil
}
-
- stateObject = NewStateObjectFromBytes(addr, []byte(data), self.db)
+ stateObject, err := DecodeObject(addr, self.db, data)
+ if err != nil {
+ glog.Errorf("can't decode object at %x: %v", addr[:], err)
+ return nil
+ }
self.SetStateObject(stateObject)
-
return stateObject
}