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
This commit is contained in:
@ -14,11 +14,10 @@ type Environment interface {
|
||||
|
||||
Origin() []byte
|
||||
BlockNumber() *big.Int
|
||||
PrevHash() []byte
|
||||
GetHash(n uint64) []byte
|
||||
Coinbase() []byte
|
||||
Time() int64
|
||||
Difficulty() *big.Int
|
||||
BlockHash() []byte
|
||||
GasLimit() *big.Int
|
||||
Transfer(from, to Account, amount *big.Int) error
|
||||
AddLog(state.Log)
|
||||
|
@ -59,7 +59,7 @@ const (
|
||||
const (
|
||||
|
||||
// 0x40 range - block operations
|
||||
PREVHASH OpCode = 0x40 + iota
|
||||
BLOCKHASH OpCode = 0x40 + iota
|
||||
COINBASE
|
||||
TIMESTAMP
|
||||
NUMBER
|
||||
@ -216,7 +216,7 @@ var opCodeToString = map[OpCode]string{
|
||||
GASPRICE: "TXGASPRICE",
|
||||
|
||||
// 0x40 range - block operations
|
||||
PREVHASH: "PREVHASH",
|
||||
BLOCKHASH: "BLOCKHASH",
|
||||
COINBASE: "COINBASE",
|
||||
TIMESTAMP: "TIMESTAMP",
|
||||
NUMBER: "NUMBER",
|
||||
|
@ -42,9 +42,9 @@ func (self *DebugVm) Run(me, caller ContextRef, code []byte, value, gas, price *
|
||||
|
||||
msg := self.env.State().Manifest().AddMessage(&state.Message{
|
||||
To: me.Address(), From: caller.Address(),
|
||||
Input: callData,
|
||||
Origin: self.env.Origin(),
|
||||
Block: self.env.BlockHash(), Timestamp: self.env.Time(), Coinbase: self.env.Coinbase(), Number: self.env.BlockNumber(),
|
||||
Input: callData,
|
||||
Origin: self.env.Origin(),
|
||||
Timestamp: self.env.Time(), Coinbase: self.env.Coinbase(), Number: self.env.BlockNumber(),
|
||||
Value: value,
|
||||
})
|
||||
context := NewContext(msg, caller, me, code, gas, price)
|
||||
@ -516,12 +516,15 @@ func (self *DebugVm) Run(me, caller ContextRef, code []byte, value, gas, price *
|
||||
self.Printf(" => %v", context.Price)
|
||||
|
||||
// 0x40 range
|
||||
case PREVHASH:
|
||||
prevHash := self.env.PrevHash()
|
||||
case BLOCKHASH:
|
||||
num := stack.Pop()
|
||||
if num.Cmp(new(big.Int).Sub(self.env.BlockNumber(), ethutil.Big256)) < 0 {
|
||||
stack.Push(ethutil.Big0)
|
||||
} else {
|
||||
stack.Push(ethutil.BigD(self.env.GetHash(num.Uint64())))
|
||||
}
|
||||
|
||||
stack.Push(ethutil.BigD(prevHash))
|
||||
|
||||
self.Printf(" => 0x%x", prevHash)
|
||||
self.Printf(" => 0x%x", stack.Peek().Bytes())
|
||||
case COINBASE:
|
||||
coinbase := self.env.Coinbase()
|
||||
|
||||
|
Reference in New Issue
Block a user