diff options
Diffstat (limited to 'chain/vm_env.go')
-rw-r--r-- | chain/vm_env.go | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/chain/vm_env.go b/chain/vm_env.go index c1911ff51..c2428c234 100644 --- a/chain/vm_env.go +++ b/chain/vm_env.go @@ -12,6 +12,7 @@ type VMEnv struct { state *state.State block *types.Block tx *types.Transaction + depth int } func NewEnv(state *state.State, tx *types.Transaction, block *types.Block) *VMEnv { @@ -32,9 +33,31 @@ func (self *VMEnv) BlockHash() []byte { return self.block.Hash() } func (self *VMEnv) Value() *big.Int { return self.tx.Value } func (self *VMEnv) State() *state.State { return self.state } func (self *VMEnv) GasLimit() *big.Int { return self.block.GasLimit } +func (self *VMEnv) Depth() int { return self.depth } +func (self *VMEnv) SetDepth(i int) { self.depth = i } func (self *VMEnv) AddLog(log *state.Log) { self.state.AddLog(log) } func (self *VMEnv) Transfer(from, to vm.Account, amount *big.Int) error { return vm.Transfer(from, to, amount) } + +func (self *VMEnv) vm(addr, data []byte, gas, price, value *big.Int) *Execution { + evm := vm.New(self, vm.DebugVmTy) + + return NewExecution(evm, addr, data, gas, price, value) +} + +func (self *VMEnv) Call(me vm.ClosureRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error) { + exe := self.vm(addr, data, gas, price, value) + return exe.Call(addr, me) +} +func (self *VMEnv) CallCode(me vm.ClosureRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error) { + exe := self.vm(me.Address(), data, gas, price, value) + return exe.Call(addr, me) +} + +func (self *VMEnv) Create(me vm.ClosureRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error, vm.ClosureRef) { + exe := self.vm(addr, data, gas, price, value) + return exe.Create(me) +} |