aboutsummaryrefslogtreecommitdiffstats
path: root/core/vm_env.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-01-04 00:18:43 +0800
committerobscuren <geffobscura@gmail.com>2015-01-04 00:18:43 +0800
commitca1b2a1a91401255ab4e26cec7eb575b99ecb8da (patch)
tree87b3c8fed57f688c138288ed5d90a0a3a1e3274b /core/vm_env.go
parent16f417f5af16de8f1c2c140f8b249bd989200bd3 (diff)
downloaddexon-ca1b2a1a91401255ab4e26cec7eb575b99ecb8da.tar.gz
dexon-ca1b2a1a91401255ab4e26cec7eb575b99ecb8da.tar.zst
dexon-ca1b2a1a91401255ab4e26cec7eb575b99ecb8da.zip
Changed prev_hash to block_hash, state transition now uses vm env
* PREVHASH => BLOCKHASH( N ) * State transition object uses VMEnv as it's query interface * Updated vm.Enviroment has GetHash( n ) for BLOCKHASH instruction * Added GetHash to xeth, core, utils & test environments
Diffstat (limited to 'core/vm_env.go')
-rw-r--r--core/vm_env.go13
1 files changed, 10 insertions, 3 deletions
diff --git a/core/vm_env.go b/core/vm_env.go
index 4e0315ff3..624a63333 100644
--- a/core/vm_env.go
+++ b/core/vm_env.go
@@ -13,10 +13,12 @@ type VMEnv struct {
block *types.Block
msg Message
depth int
+ chain *ChainManager
}
-func NewEnv(state *state.StateDB, msg Message, block *types.Block) *VMEnv {
+func NewEnv(state *state.StateDB, chain *ChainManager, msg Message, block *types.Block) *VMEnv {
return &VMEnv{
+ chain: chain,
state: state,
block: block,
msg: msg,
@@ -25,16 +27,21 @@ func NewEnv(state *state.StateDB, msg Message, block *types.Block) *VMEnv {
func (self *VMEnv) Origin() []byte { return self.msg.From() }
func (self *VMEnv) BlockNumber() *big.Int { return self.block.Number() }
-func (self *VMEnv) PrevHash() []byte { return self.block.ParentHash() }
func (self *VMEnv) Coinbase() []byte { return self.block.Coinbase() }
func (self *VMEnv) Time() int64 { return self.block.Time() }
func (self *VMEnv) Difficulty() *big.Int { return self.block.Difficulty() }
-func (self *VMEnv) BlockHash() []byte { return self.block.Hash() }
func (self *VMEnv) GasLimit() *big.Int { return self.block.GasLimit() }
func (self *VMEnv) Value() *big.Int { return self.msg.Value() }
func (self *VMEnv) State() *state.StateDB { return self.state }
func (self *VMEnv) Depth() int { return self.depth }
func (self *VMEnv) SetDepth(i int) { self.depth = i }
+func (self *VMEnv) GetHash(n uint64) []byte {
+ if block := self.chain.GetBlockByNumber(n); block != nil {
+ return block.Hash()
+ }
+
+ return nil
+}
func (self *VMEnv) AddLog(log state.Log) {
self.state.AddLog(log)
}