aboutsummaryrefslogtreecommitdiffstats
path: root/ethchain
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-07-14 06:38:20 +0800
committerobscuren <geffobscura@gmail.com>2014-07-14 06:38:20 +0800
commit5a0c4ce29509046e7de801e96bee893c82bfc1e8 (patch)
tree793c2b1c1a48c6f53f9c2ddfbde233ed5d03da3b /ethchain
parent04f8c455e2d8585902e2c9f0cfb8717ef74a65ca (diff)
downloaddexon-5a0c4ce29509046e7de801e96bee893c82bfc1e8.tar.gz
dexon-5a0c4ce29509046e7de801e96bee893c82bfc1e8.tar.zst
dexon-5a0c4ce29509046e7de801e96bee893c82bfc1e8.zip
Fixed "Copy" to also copy over the pending storage changes
Diffstat (limited to 'ethchain')
-rw-r--r--ethchain/state_object.go23
1 files changed, 18 insertions, 5 deletions
diff --git a/ethchain/state_object.go b/ethchain/state_object.go
index ebc050863..f4adc4c80 100644
--- a/ethchain/state_object.go
+++ b/ethchain/state_object.go
@@ -15,6 +15,18 @@ func (self Code) String() string {
return strings.Join(Disassemble(self), " ")
}
+type Storage map[string]*ethutil.Value
+
+func (self Storage) Copy() Storage {
+ cpy := make(Storage)
+ for key, value := range self {
+ // XXX Do we need a 'value' copy or is this sufficient?
+ cpy[key] = value
+ }
+
+ return cpy
+}
+
type StateObject struct {
// Address of the object
address []byte
@@ -27,7 +39,7 @@ type StateObject struct {
script Code
initScript Code
- storage map[string]*ethutil.Value
+ storage Storage
// Total gas pool is the total amount of gas currently
// left if this object is the coinbase. Gas is directly
@@ -41,7 +53,7 @@ type StateObject struct {
}
func (self *StateObject) Reset() {
- self.storage = make(map[string]*ethutil.Value)
+ self.storage = make(Storage)
}
// Converts an transaction in to a state object
@@ -95,7 +107,7 @@ func NewStateObjectFromBytes(address, data []byte) *StateObject {
func (self *StateObject) MarkForDeletion() {
self.remove = true
- statelogger.Infof("%x: #%d %v (deletion)\n", self.Address(), self.Nonce, self.Amount)
+ statelogger.DebugDetailf("%x: #%d %v (deletion)\n", self.Address(), self.Nonce, self.Amount)
}
func (c *StateObject) GetAddr(addr []byte) *ethutil.Value {
@@ -154,13 +166,13 @@ func (c *StateObject) GetInstr(pc *big.Int) *ethutil.Value {
func (c *StateObject) AddAmount(amount *big.Int) {
c.SetAmount(new(big.Int).Add(c.Amount, amount))
- statelogger.Infof("%x: #%d %v (+ %v)\n", c.Address(), c.Nonce, c.Amount, amount)
+ statelogger.DebugDetailf("%x: #%d %v (+ %v)\n", c.Address(), c.Nonce, c.Amount, amount)
}
func (c *StateObject) SubAmount(amount *big.Int) {
c.SetAmount(new(big.Int).Sub(c.Amount, amount))
- statelogger.Infof("%x: #%d %v (- %v)\n", c.Address(), c.Nonce, c.Amount, amount)
+ statelogger.DebugDetailf("%x: #%d %v (- %v)\n", c.Address(), c.Nonce, c.Amount, amount)
}
func (c *StateObject) SetAmount(amount *big.Int) {
@@ -222,6 +234,7 @@ func (self *StateObject) Copy() *StateObject {
}
stateObject.script = ethutil.CopyBytes(self.script)
stateObject.initScript = ethutil.CopyBytes(self.initScript)
+ stateObject.storage = self.storage.Copy()
return stateObject
}