Skip to content

Commit dba15d9

Browse files
committed
Merge pull request #1918 from obscuren/get-hash-fix
core, tests: get_hash fix
2 parents 796952a + 80f2608 commit dba15d9

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

core/vm/environment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type Environment interface {
3939
// The block number this VM is invoken on
4040
BlockNumber() *big.Int
4141
// The n'th hash ago from this block number
42-
GetHash(n uint64) common.Hash
42+
GetHash(uint64) common.Hash
4343
// The handler's address
4444
Coinbase() common.Address
4545
// The current time (block time)

core/vm_env.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,10 @@ func (self *VMEnv) SetDepth(i int) { self.depth = i }
5959
func (self *VMEnv) VmType() vm.Type { return self.typ }
6060
func (self *VMEnv) SetVmType(t vm.Type) { self.typ = t }
6161
func (self *VMEnv) GetHash(n uint64) common.Hash {
62-
if block := self.chain.GetBlockByNumber(n); block != nil {
63-
return block.Hash()
62+
for block := self.chain.GetBlock(self.header.ParentHash); block != nil; block = self.chain.GetBlock(block.ParentHash()) {
63+
if block.NumberU64() == n {
64+
return block.Hash()
65+
}
6466
}
6567

6668
return common.Hash{}

tests/util.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ type Env struct {
131131
initial bool
132132
Gas *big.Int
133133

134-
origin common.Address
135-
//parent common.Hash
134+
origin common.Address
135+
parent common.Hash
136136
coinbase common.Address
137137

138138
number *big.Int
@@ -163,7 +163,7 @@ func NewEnvFromMap(state *state.StateDB, envValues map[string]string, exeValues
163163
env := NewEnv(state)
164164

165165
env.origin = common.HexToAddress(exeValues["caller"])
166-
//env.parent = common.Hex2Bytes(envValues["previousHash"])
166+
env.parent = common.HexToHash(envValues["previousHash"])
167167
env.coinbase = common.HexToAddress(envValues["currentCoinbase"])
168168
env.number = common.Big(envValues["currentNumber"])
169169
env.time = common.Big(envValues["currentTimestamp"])
@@ -174,10 +174,8 @@ func NewEnvFromMap(state *state.StateDB, envValues map[string]string, exeValues
174174
return env
175175
}
176176

177-
func (self *Env) Origin() common.Address { return self.origin }
178-
func (self *Env) BlockNumber() *big.Int { return self.number }
179-
180-
//func (self *Env) PrevHash() []byte { return self.parent }
177+
func (self *Env) Origin() common.Address { return self.origin }
178+
func (self *Env) BlockNumber() *big.Int { return self.number }
181179
func (self *Env) Coinbase() common.Address { return self.coinbase }
182180
func (self *Env) Time() *big.Int { return self.time }
183181
func (self *Env) Difficulty() *big.Int { return self.difficulty }

0 commit comments

Comments
 (0)