aboutsummaryrefslogtreecommitdiffstats
path: root/core/vm_env.go
diff options
context:
space:
mode:
Diffstat (limited to 'core/vm_env.go')
-rw-r--r--core/vm_env.go41
1 files changed, 24 insertions, 17 deletions
diff --git a/core/vm_env.go b/core/vm_env.go
index 0fab4a090..880baa7b0 100644
--- a/core/vm_env.go
+++ b/core/vm_env.go
@@ -41,33 +41,42 @@ func GetHashFn(ref common.Hash, chain *BlockChain) func(n uint64) common.Hash {
}
type VMEnv struct {
- state *state.StateDB
- header *types.Header
- msg Message
- depth int
- chain *BlockChain
- typ vm.Type
-
- getHashFn func(uint64) common.Hash
- // structured logging
- logs []vm.StructLog
- evm *vm.Vm
+ state *state.StateDB // State to use for executing
+ evm *vm.EVM // The Ethereum Virtual Machine
+ depth int // Current execution depth
+ msg Message // Message appliod
+
+ header *types.Header // Header information
+ chain *BlockChain // Blockchain handle
+ logs []vm.StructLog // Logs for the custom structured logger
+ getHashFn func(uint64) common.Hash // getHashFn callback is used to retrieve block hashes
+
}
-func NewEnv(state *state.StateDB, chain *BlockChain, msg Message, header *types.Header) *VMEnv {
+func NewEnv(state *state.StateDB, chain *BlockChain, msg Message, header *types.Header, cfg *vm.Config) *VMEnv {
env := &VMEnv{
chain: chain,
state: state,
header: header,
msg: msg,
- typ: vm.StdVmTy,
getHashFn: GetHashFn(header.ParentHash, chain),
}
- env.evm = vm.EVM(env)
+
+ // initialise a default config if none present
+ if cfg == nil {
+ cfg = new(vm.Config)
+ }
+
+ // if no log collector is present set self as the collector
+ if cfg.Logger.Collector == nil {
+ cfg.Logger.Collector = env
+ }
+
+ env.evm = vm.New(env, cfg)
return env
}
-func (self *VMEnv) Vm() *vm.Vm { return self.evm }
+func (self *VMEnv) Vm() vm.Vm { return self.evm }
func (self *VMEnv) Origin() common.Address { f, _ := self.msg.From(); return f }
func (self *VMEnv) BlockNumber() *big.Int { return self.header.Number }
func (self *VMEnv) Coinbase() common.Address { return self.header.Coinbase }
@@ -78,8 +87,6 @@ func (self *VMEnv) Value() *big.Int { return self.msg.Value() }
func (self *VMEnv) Db() vm.Database { return self.state }
func (self *VMEnv) Depth() int { return self.depth }
func (self *VMEnv) SetDepth(i int) { self.depth = i }
-func (self *VMEnv) VmType() vm.Type { return self.typ }
-func (self *VMEnv) SetVmType(t vm.Type) { self.typ = t }
func (self *VMEnv) GetHash(n uint64) common.Hash {
return self.getHashFn(n)
}