aboutsummaryrefslogtreecommitdiffstats
path: root/ethchain
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-07-02 05:59:18 +0800
committerobscuren <geffobscura@gmail.com>2014-07-02 05:59:18 +0800
commit00d3935aac3f5d50bae56650c45e49a8b8705099 (patch)
treeda01968d729f41fa7f4470c2a4323b2dd422304b /ethchain
parentbb2433ca1a953e610396707a67ca5eb73574e81f (diff)
downloaddexon-00d3935aac3f5d50bae56650c45e49a8b8705099.tar
dexon-00d3935aac3f5d50bae56650c45e49a8b8705099.tar.gz
dexon-00d3935aac3f5d50bae56650c45e49a8b8705099.tar.bz2
dexon-00d3935aac3f5d50bae56650c45e49a8b8705099.tar.lz
dexon-00d3935aac3f5d50bae56650c45e49a8b8705099.tar.xz
dexon-00d3935aac3f5d50bae56650c45e49a8b8705099.tar.zst
dexon-00d3935aac3f5d50bae56650c45e49a8b8705099.zip
Removed old method
Diffstat (limited to 'ethchain')
-rw-r--r--ethchain/closure.go6
-rw-r--r--ethchain/state.go6
-rw-r--r--ethchain/state_object.go67
3 files changed, 36 insertions, 43 deletions
diff --git a/ethchain/closure.go b/ethchain/closure.go
index 32b297e90..966e8254a 100644
--- a/ethchain/closure.go
+++ b/ethchain/closure.go
@@ -10,7 +10,7 @@ import (
type ClosureRef interface {
ReturnGas(*big.Int, *big.Int, *State)
Address() []byte
- GetMem(*big.Int) *ethutil.Value
+ GetStorage(*big.Int) *ethutil.Value
SetStorage(*big.Int, *ethutil.Value)
N() *big.Int
}
@@ -43,8 +43,8 @@ func NewClosure(caller ClosureRef, object *StateObject, script []byte, state *St
}
// Retuns the x element in data slice
-func (c *Closure) GetMem(x *big.Int) *ethutil.Value {
- m := c.object.GetMem(x)
+func (c *Closure) GetStorage(x *big.Int) *ethutil.Value {
+ m := c.object.GetStorage(x)
if m == nil {
return ethutil.EmptyValue()
}
diff --git a/ethchain/state.go b/ethchain/state.go
index 8b6c2efb8..3d05ff582 100644
--- a/ethchain/state.go
+++ b/ethchain/state.go
@@ -66,7 +66,11 @@ func (self *State) Empty() {
func (self *State) Update() {
for _, stateObject := range self.stateObjects {
- self.UpdateStateObject(stateObject)
+ if stateObject.remove {
+ self.trie.Delete(string(stateObject.Address()))
+ } else {
+ self.UpdateStateObject(stateObject)
+ }
}
}
diff --git a/ethchain/state_object.go b/ethchain/state_object.go
index 35928c899..cc9a801f9 100644
--- a/ethchain/state_object.go
+++ b/ethchain/state_object.go
@@ -31,6 +31,11 @@ type StateObject struct {
// left if this object is the coinbase. Gas is directly
// purchased of the coinbase.
gasPool *big.Int
+
+ // Mark for deletion
+ // When an object is marked for deletion it will be delete from the trie
+ // during the "update" phase of the state transition
+ remove bool
}
// Converts an transaction in to a state object
@@ -77,15 +82,11 @@ func NewStateObjectFromBytes(address, data []byte) *StateObject {
return object
}
-func (c *StateObject) State() *State {
- return c.state
-}
-
-func (c *StateObject) N() *big.Int {
- return big.NewInt(int64(c.Nonce))
+func (self *StateObject) MarkForDeletion() {
+ self.remove = true
}
-func (c *StateObject) Addr(addr []byte) *ethutil.Value {
+func (c *StateObject) GetAddr(addr []byte) *ethutil.Value {
return ethutil.NewValueFromBytes([]byte(c.state.trie.Get(string(addr))))
}
@@ -108,12 +109,7 @@ func (c *StateObject) SetStorage(num *big.Int, val *ethutil.Value) {
func (c *StateObject) GetStorage(num *big.Int) *ethutil.Value {
nb := ethutil.BigToBytes(num, 256)
- return c.Addr(nb)
-}
-
-/* DEPRECATED */
-func (c *StateObject) GetMem(num *big.Int) *ethutil.Value {
- return c.GetStorage(num)
+ return c.GetAddr(nb)
}
func (c *StateObject) GetInstr(pc *big.Int) *ethutil.Value {
@@ -124,14 +120,6 @@ func (c *StateObject) GetInstr(pc *big.Int) *ethutil.Value {
return ethutil.NewValueFromBytes([]byte{c.script[pc.Int64()]})
}
-// Return the gas back to the origin. Used by the Virtual machine or Closures
-func (c *StateObject) ReturnGas(gas, price *big.Int, state *State) {
- /*
- remainder := new(big.Int).Mul(gas, price)
- c.AddAmount(remainder)
- */
-}
-
func (c *StateObject) AddAmount(amount *big.Int) {
c.SetAmount(new(big.Int).Add(c.Amount, amount))
@@ -148,6 +136,12 @@ func (c *StateObject) SetAmount(amount *big.Int) {
c.Amount = amount
}
+//
+// Gas setters and getters
+//
+
+// Return the gas back to the origin. Used by the Virtual machine or Closures
+func (c *StateObject) ReturnGas(gas, price *big.Int, state *State) {}
func (c *StateObject) ConvertGas(gas, price *big.Int) error {
total := new(big.Int).Mul(gas, price)
if total.Cmp(c.Amount) > 0 {
@@ -206,26 +200,17 @@ func (self *StateObject) Set(stateObject *StateObject) {
self = stateObject
}
-/*
-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
- if self.state != nil {
- 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)
+//
+// Attribute accessors
+//
+
+func (c *StateObject) State() *State {
+ return c.state
+}
- return stCopy
+func (c *StateObject) N() *big.Int {
+ return big.NewInt(int64(c.Nonce))
}
-*/
// Returns the address of the contract/account
func (c *StateObject) Address() []byte {
@@ -242,6 +227,10 @@ func (c *StateObject) Init() Code {
return c.initScript
}
+//
+// Encoding
+//
+
// State object encoding methods
func (c *StateObject) RlpEncode() []byte {
var root interface{}