aboutsummaryrefslogtreecommitdiffstats
path: root/core/vm_env.go
diff options
context:
space:
mode:
authorJeffrey Wilcke <jeffrey@ethereum.org>2016-03-24 06:20:51 +0800
committerJeffrey Wilcke <jeffrey@ethereum.org>2016-03-24 06:20:51 +0800
commit75c86f8646ed6a21116d6c5f5e400dd966bb218d (patch)
tree6c979fd121e7721328b9502f1855387b602dcd87 /core/vm_env.go
parent9866f19d6af607f629be311cb1c879e8f6472773 (diff)
parent0cfa21fc7f34d9da93abc41541dd4a98d70eb9dd (diff)
downloaddexon-75c86f8646ed6a21116d6c5f5e400dd966bb218d.tar
dexon-75c86f8646ed6a21116d6c5f5e400dd966bb218d.tar.gz
dexon-75c86f8646ed6a21116d6c5f5e400dd966bb218d.tar.bz2
dexon-75c86f8646ed6a21116d6c5f5e400dd966bb218d.tar.lz
dexon-75c86f8646ed6a21116d6c5f5e400dd966bb218d.tar.xz
dexon-75c86f8646ed6a21116d6c5f5e400dd966bb218d.tar.zst
dexon-75c86f8646ed6a21116d6c5f5e400dd966bb218d.zip
Merge pull request #2141 from obscuren/evm-init
core, core/vm, tests: changed the initialisation behaviour of the EVM
Diffstat (limited to 'core/vm_env.go')
-rw-r--r--core/vm_env.go41
1 files changed, 26 insertions, 15 deletions
diff --git a/core/vm_env.go b/core/vm_env.go
index 7b9a1a0f9..880baa7b0 100644
--- a/core/vm_env.go
+++ b/core/vm_env.go
@@ -41,29 +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
+ 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 {
- return &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),
}
+
+ // 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) 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 }
@@ -74,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)
}