aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeffrey Wilcke <jeffrey@ethereum.org>2015-10-21 18:54:59 +0800
committerJeffrey Wilcke <jeffrey@ethereum.org>2015-10-21 18:54:59 +0800
commitdba15d9c3609bcddfc7a4f0fe8f01c48a8bbfbc8 (patch)
tree298cd91b9102053a65cfb18ae4e43ca7980fb8f3
parent796952a49ac12caa3949587e22a7a03c30a8910c (diff)
parent80f26086eeb126cb87000f283cb5ccc3df95dbcc (diff)
downloaddexon-dba15d9c3609bcddfc7a4f0fe8f01c48a8bbfbc8.tar
dexon-dba15d9c3609bcddfc7a4f0fe8f01c48a8bbfbc8.tar.gz
dexon-dba15d9c3609bcddfc7a4f0fe8f01c48a8bbfbc8.tar.bz2
dexon-dba15d9c3609bcddfc7a4f0fe8f01c48a8bbfbc8.tar.lz
dexon-dba15d9c3609bcddfc7a4f0fe8f01c48a8bbfbc8.tar.xz
dexon-dba15d9c3609bcddfc7a4f0fe8f01c48a8bbfbc8.tar.zst
dexon-dba15d9c3609bcddfc7a4f0fe8f01c48a8bbfbc8.zip
Merge pull request #1918 from obscuren/get-hash-fix
core, tests: get_hash fix
-rw-r--r--core/vm/environment.go2
-rw-r--r--core/vm_env.go6
-rw-r--r--tests/util.go12
3 files changed, 10 insertions, 10 deletions
diff --git a/core/vm/environment.go b/core/vm/environment.go
index ec739b26c..299d12674 100644
--- a/core/vm/environment.go
+++ b/core/vm/environment.go
@@ -39,7 +39,7 @@ type Environment interface {
// The block number this VM is invoken on
BlockNumber() *big.Int
// The n'th hash ago from this block number
- GetHash(n uint64) common.Hash
+ GetHash(uint64) common.Hash
// The handler's address
Coinbase() common.Address
// The current time (block time)
diff --git a/core/vm_env.go b/core/vm_env.go
index 715fde52f..c8b50debc 100644
--- a/core/vm_env.go
+++ b/core/vm_env.go
@@ -59,8 +59,10 @@ 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 {
- if block := self.chain.GetBlockByNumber(n); block != nil {
- return block.Hash()
+ for block := self.chain.GetBlock(self.header.ParentHash); block != nil; block = self.chain.GetBlock(block.ParentHash()) {
+ if block.NumberU64() == n {
+ return block.Hash()
+ }
}
return common.Hash{}
diff --git a/tests/util.go b/tests/util.go
index bbc671169..571161683 100644
--- a/tests/util.go
+++ b/tests/util.go
@@ -131,8 +131,8 @@ type Env struct {
initial bool
Gas *big.Int
- origin common.Address
- //parent common.Hash
+ origin common.Address
+ parent common.Hash
coinbase common.Address
number *big.Int
@@ -163,7 +163,7 @@ func NewEnvFromMap(state *state.StateDB, envValues map[string]string, exeValues
env := NewEnv(state)
env.origin = common.HexToAddress(exeValues["caller"])
- //env.parent = common.Hex2Bytes(envValues["previousHash"])
+ env.parent = common.HexToHash(envValues["previousHash"])
env.coinbase = common.HexToAddress(envValues["currentCoinbase"])
env.number = common.Big(envValues["currentNumber"])
env.time = common.Big(envValues["currentTimestamp"])
@@ -174,10 +174,8 @@ func NewEnvFromMap(state *state.StateDB, envValues map[string]string, exeValues
return env
}
-func (self *Env) Origin() common.Address { return self.origin }
-func (self *Env) BlockNumber() *big.Int { return self.number }
-
-//func (self *Env) PrevHash() []byte { return self.parent }
+func (self *Env) Origin() common.Address { return self.origin }
+func (self *Env) BlockNumber() *big.Int { return self.number }
func (self *Env) Coinbase() common.Address { return self.coinbase }
func (self *Env) Time() *big.Int { return self.time }
func (self *Env) Difficulty() *big.Int { return self.difficulty }