aboutsummaryrefslogtreecommitdiffstats
path: root/ethchain/state_object.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-06-16 06:51:04 +0800
committerobscuren <geffobscura@gmail.com>2014-06-16 06:51:04 +0800
commit8198fd7913ea4066afb5c0cf5e57fa5ec4888fac (patch)
tree58ca003b0d8942ec4727f2346050c92bcfec6a99 /ethchain/state_object.go
parentd80f999a215b74e23d21f3548486f996c3eb028d (diff)
downloaddexon-8198fd7913ea4066afb5c0cf5e57fa5ec4888fac.tar.gz
dexon-8198fd7913ea4066afb5c0cf5e57fa5ec4888fac.tar.zst
dexon-8198fd7913ea4066afb5c0cf5e57fa5ec4888fac.zip
Cache whole objects instead of states only
Diffstat (limited to 'ethchain/state_object.go')
-rw-r--r--ethchain/state_object.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/ethchain/state_object.go b/ethchain/state_object.go
index 12ebf8e9b..3775d436c 100644
--- a/ethchain/state_object.go
+++ b/ethchain/state_object.go
@@ -38,6 +38,10 @@ func MakeContract(tx *Transaction, state *State) *StateObject {
return nil
}
+func NewStateObject(addr []byte) *StateObject {
+ return &StateObject{address: addr, Amount: new(big.Int)}
+}
+
func NewContract(address []byte, Amount *big.Int, root []byte) *StateObject {
contract := &StateObject{address: address, Amount: Amount, Nonce: 0}
contract.state = NewState(ethutil.NewTrie(ethutil.Config.Db, string(root)))
@@ -146,6 +150,23 @@ func (self *StateObject) BuyGas(gas, price *big.Int) error {
return nil
}
+func (self *StateObject) Copy() *StateObject {
+ stCopy := &StateObject{}
+ stCopy.address = make([]byte, len(self.address))
+ copy(stCopy.address, self.address)
+ stCopy.Amount = new(big.Int).Set(self.Amount)
+ stCopy.ScriptHash = make([]byte, len(self.ScriptHash))
+ copy(stCopy.ScriptHash, self.ScriptHash)
+ stCopy.Nonce = self.Nonce
+ stCopy.state = self.state.Copy()
+ stCopy.script = make([]byte, len(self.script))
+ copy(stCopy.script, self.script)
+ stCopy.initScript = make([]byte, len(self.initScript))
+ copy(stCopy.initScript, self.initScript)
+
+ return stCopy
+}
+
// Returns the address of the contract/account
func (c *StateObject) Address() []byte {
return c.address