From 3fc7c978277051391f8ea7831559e9f4f83c3166 Mon Sep 17 00:00:00 2001 From: Jeffrey Wilcke Date: Tue, 6 Dec 2016 02:16:03 +0100 Subject: core, core/vm: implemented a generic environment (#3348) Environment is now a struct (not an interface). This reduces a lot of tech-debt throughout the codebase where a virtual machine environment had to be implemented in order to test or run it. The new environment is suitable to be used en the json tests, core consensus and light client. --- core/vm/contract.go | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'core/vm/contract.go') diff --git a/core/vm/contract.go b/core/vm/contract.go index 70455a4c2..dfa93ab18 100644 --- a/core/vm/contract.go +++ b/core/vm/contract.go @@ -24,7 +24,7 @@ import ( // ContractRef is a reference to the contract's backing object type ContractRef interface { - ReturnGas(*big.Int, *big.Int) + ReturnGas(*big.Int) Address() common.Address Value() *big.Int SetCode(common.Hash, []byte) @@ -48,7 +48,7 @@ type Contract struct { CodeAddr *common.Address Input []byte - value, Gas, UsedGas, Price *big.Int + value, Gas, UsedGas *big.Int Args []byte @@ -56,7 +56,7 @@ type Contract struct { } // NewContract returns a new contract environment for the execution of EVM. -func NewContract(caller ContractRef, object ContractRef, value, gas, price *big.Int) *Contract { +func NewContract(caller ContractRef, object ContractRef, value, gas *big.Int) *Contract { c := &Contract{CallerAddress: caller.Address(), caller: caller, self: object, Args: nil} if parent, ok := caller.(*Contract); ok { @@ -70,9 +70,6 @@ func NewContract(caller ContractRef, object ContractRef, value, gas, price *big. // This pointer will be off the state transition c.Gas = gas //new(big.Int).Set(gas) c.value = new(big.Int).Set(value) - // In most cases price and value are pointers to transaction objects - // and we don't want the transaction's values to change. - c.Price = new(big.Int).Set(price) c.UsedGas = new(big.Int) return c @@ -114,7 +111,7 @@ func (c *Contract) Caller() common.Address { // caller. func (c *Contract) Finalise() { // Return the remaining gas to the caller - c.caller.ReturnGas(c.Gas, c.Price) + c.caller.ReturnGas(c.Gas) } // UseGas attempts the use gas and subtracts it and returns true on success @@ -127,7 +124,7 @@ func (c *Contract) UseGas(gas *big.Int) (ok bool) { } // ReturnGas adds the given gas back to itself. -func (c *Contract) ReturnGas(gas, price *big.Int) { +func (c *Contract) ReturnGas(gas *big.Int) { // Return the gas to the context c.Gas.Add(c.Gas, gas) c.UsedGas.Sub(c.UsedGas, gas) -- cgit v1.2.3