aboutsummaryrefslogtreecommitdiffstats
path: root/state/state_object.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-01-07 20:17:48 +0800
committerobscuren <geffobscura@gmail.com>2015-01-07 20:17:48 +0800
commitfed3e6a808921fb8274b50043c5c39a24a1bbccf (patch)
treed632e95cfce78bd9a99a52bf7f30ee3ff980dfd3 /state/state_object.go
parent032ab665299d75bffc25260e8fa477ace19db06a (diff)
downloadgo-tangerine-fed3e6a808921fb8274b50043c5c39a24a1bbccf.tar
go-tangerine-fed3e6a808921fb8274b50043c5c39a24a1bbccf.tar.gz
go-tangerine-fed3e6a808921fb8274b50043c5c39a24a1bbccf.tar.bz2
go-tangerine-fed3e6a808921fb8274b50043c5c39a24a1bbccf.tar.lz
go-tangerine-fed3e6a808921fb8274b50043c5c39a24a1bbccf.tar.xz
go-tangerine-fed3e6a808921fb8274b50043c5c39a24a1bbccf.tar.zst
go-tangerine-fed3e6a808921fb8274b50043c5c39a24a1bbccf.zip
Refactored ethutil.Config.Db out
Diffstat (limited to 'state/state_object.go')
-rw-r--r--state/state_object.go25
1 files changed, 9 insertions, 16 deletions
diff --git a/state/state_object.go b/state/state_object.go
index 420ad9757..c1c78bee0 100644
--- a/state/state_object.go
+++ b/state/state_object.go
@@ -28,6 +28,7 @@ func (self Storage) Copy() Storage {
}
type StateObject struct {
+ db ethutil.Database
// Address of the object
address []byte
// Shared attributes
@@ -57,28 +58,20 @@ func (self *StateObject) Reset() {
self.State.Reset()
}
-func NewStateObject(addr []byte) *StateObject {
+func NewStateObject(addr []byte, db ethutil.Database) *StateObject {
// This to ensure that it has 20 bytes (and not 0 bytes), thus left or right pad doesn't matter.
address := ethutil.Address(addr)
- object := &StateObject{address: address, balance: new(big.Int), gasPool: new(big.Int)}
- object.State = New(ptrie.New(nil, ethutil.Config.Db)) //New(trie.New(ethutil.Config.Db, ""))
+ object := &StateObject{db: db, address: address, balance: new(big.Int), gasPool: new(big.Int)}
+ object.State = New(nil, db) //New(trie.New(ethutil.Config.Db, ""))
object.storage = make(Storage)
object.gasPool = new(big.Int)
return object
}
-func NewContract(address []byte, balance *big.Int, root []byte) *StateObject {
- contract := NewStateObject(address)
- contract.balance = balance
- contract.State = New(ptrie.New(nil, ethutil.Config.Db)) //New(trie.New(ethutil.Config.Db, string(root)))
-
- return contract
-}
-
-func NewStateObjectFromBytes(address, data []byte) *StateObject {
- object := &StateObject{address: address}
+func NewStateObjectFromBytes(address, data []byte, db ethutil.Database) *StateObject {
+ object := &StateObject{address: address, db: db}
object.RlpDecode(data)
return object
@@ -242,7 +235,7 @@ func (self *StateObject) RefundGas(gas, price *big.Int) {
}
func (self *StateObject) Copy() *StateObject {
- stateObject := NewStateObject(self.Address())
+ stateObject := NewStateObject(self.Address(), self.db)
stateObject.balance.Set(self.balance)
stateObject.codeHash = ethutil.CopyBytes(self.codeHash)
stateObject.Nonce = self.Nonce
@@ -310,13 +303,13 @@ func (c *StateObject) RlpDecode(data []byte) {
c.Nonce = decoder.Get(0).Uint()
c.balance = decoder.Get(1).BigInt()
- c.State = New(ptrie.New(decoder.Get(2).Bytes(), ethutil.Config.Db)) //New(trie.New(ethutil.Config.Db, decoder.Get(2).Interface()))
+ c.State = New(decoder.Get(2).Bytes(), c.db) //New(trie.New(ethutil.Config.Db, decoder.Get(2).Interface()))
c.storage = make(map[string]*ethutil.Value)
c.gasPool = new(big.Int)
c.codeHash = decoder.Get(3).Bytes()
- c.Code, _ = ethutil.Config.Db.Get(c.codeHash)
+ c.Code, _ = c.db.Get(c.codeHash)
}
// Storage change object. Used by the manifest for notifying changes to