diff options
Diffstat (limited to 'core/vm/contract.go')
-rw-r--r-- | core/vm/contract.go | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/core/vm/contract.go b/core/vm/contract.go index 091106d84..66748e821 100644 --- a/core/vm/contract.go +++ b/core/vm/contract.go @@ -25,11 +25,20 @@ import ( // ContractRef is a reference to the contract's backing object type ContractRef interface { Address() common.Address - Value() *big.Int - SetCode(common.Hash, []byte) - ForEachStorage(callback func(key, value common.Hash) bool) } +// AccountRef implements ContractRef. +// +// Account references are used during EVM initialisation and +// it's primary use is to fetch addresses. Removing this object +// proves difficult because of the cached jump destinations which +// are fetched from the parent contract (i.e. the caller), which +// is a ContractRef. +type AccountRef common.Address + +// Address casts AccountRef to a Address +func (ar AccountRef) Address() common.Address { return (common.Address)(ar) } + // Contract represents an ethereum contract in the state database. It contains // the the contract code, calling arguments. Contract implements ContractRef type Contract struct { @@ -69,7 +78,8 @@ func NewContract(caller ContractRef, object ContractRef, value *big.Int, gas uin // Gas should be a pointer so it can safely be reduced through the run // This pointer will be off the state transition c.Gas = gas - c.value = new(big.Int).Set(value) + // ensures a value is set + c.value = value return c } @@ -80,7 +90,10 @@ func (c *Contract) AsDelegate() *Contract { c.DelegateCall = true // NOTE: caller must, at all times be a contract. It should never happen // that caller is something other than a Contract. - c.CallerAddress = c.caller.(*Contract).CallerAddress + parent := c.caller.(*Contract) + c.CallerAddress = parent.CallerAddress + c.value = parent.value + return c } @@ -138,9 +151,3 @@ func (self *Contract) SetCallCode(addr *common.Address, hash common.Hash, code [ self.CodeHash = hash self.CodeAddr = addr } - -// EachStorage iterates the contract's storage and calls a method for every key -// value pair. -func (self *Contract) ForEachStorage(cb func(key, value common.Hash) bool) { - self.caller.ForEachStorage(cb) -} |