func (self *Env) CallCode(caller vm.ContextRef, addr common.Address, data []byte, gas, price, value *big.Int) ([]byte, error) { if self.vmTest && self.depth > 0 { caller.ReturnGas(gas, price) return nil, nil } caddr := caller.Address() exe := self.vm(&caddr, data, gas, price, value) return exe.Call(addr, caller) }
func (self *Env) Create(caller vm.ContextRef, data []byte, gas, price, value *big.Int) ([]byte, error, vm.ContextRef) { exe := self.vm(nil, data, gas, price, value) if self.vmTest { caller.ReturnGas(gas, price) nonce := self.state.GetNonce(caller.Address()) obj := self.state.GetOrNewStateObject(crypto.CreateAddress(caller.Address(), nonce)) return nil, nil, obj } else { return exe.Create(caller) } }
func (self *Env) Call(caller vm.ContextRef, addr common.Address, data []byte, gas, price, value *big.Int) ([]byte, error) { if self.vmTest && self.depth > 0 { caller.ReturnGas(gas, price) return nil, nil } exe := self.vm(&addr, data, gas, price, value) ret, err := exe.Call(addr, caller) self.Gas = exe.Gas return ret, err }
// exec executes the given code and executes within the contextAddr context. func (self *Execution) exec(contextAddr *common.Address, code []byte, caller vm.ContextRef) (ret []byte, err error) { env := self.env evm := self.evm // Depth check execution. Fail if we're trying to execute above the // limit. if env.Depth() > int(params.CallCreateDepth.Int64()) { caller.ReturnGas(self.Gas, self.price) return nil, vm.DepthError } if !env.CanTransfer(env.State().GetStateObject(caller.Address()), self.value) { caller.ReturnGas(self.Gas, self.price) return nil, ValueTransferErr("insufficient funds to transfer value. Req %v, has %v", self.value, env.State().GetBalance(caller.Address())) } var createAccount bool if self.address == nil { // Generate a new address nonce := env.State().GetNonce(caller.Address()) env.State().SetNonce(caller.Address(), nonce+1) addr := crypto.CreateAddress(caller.Address(), nonce) self.address = &addr createAccount = true } snapshot := env.State().Copy() var ( from = env.State().GetStateObject(caller.Address()) to *state.StateObject ) if createAccount { to = env.State().CreateAccount(*self.address) } else { to = env.State().GetOrNewStateObject(*self.address) } vm.Transfer(from, to, self.value) context := vm.NewContext(caller, to, self.value, self.Gas, self.price) context.SetCallCode(contextAddr, code) ret, err = evm.Run(context, self.input) if err != nil { env.State().Set(snapshot) } return }