core: Added EVM configuration options

The EVM is now initialised with an additional configured object that
allows you to turn on debugging options.
This commit is contained in:
Jeffrey Wilcke
2016-02-03 23:46:27 +01:00
committed by Jeffrey Wilcke
parent 342ae7ce7d
commit 14013372ae
30 changed files with 408 additions and 230 deletions

View File

@ -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
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
getHashFn func(uint64) common.Hash
// structured logging
logs []vm.StructLog
evm *vm.Vm
}
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)
}