From 515d9432fcef8c574627049d437d6898b56c2829 Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 17 Mar 2015 11:19:23 +0100 Subject: converted vm --- vm/context.go | 4 ++-- vm/environment.go | 6 +++--- vm/vm.go | 10 ++++++---- 3 files changed, 11 insertions(+), 9 deletions(-) (limited to 'vm') diff --git a/vm/context.go b/vm/context.go index 93a0102d4..c846aad89 100644 --- a/vm/context.go +++ b/vm/context.go @@ -18,7 +18,7 @@ type Context struct { self ContextRef Code []byte - CodeAddr common.Address + CodeAddr *common.Address value, Gas, UsedGas, Price *big.Int @@ -108,7 +108,7 @@ func (self *Context) SetCode(code []byte) { self.Code = code } -func (self *Context) SetCallCode(addr common.Address, code []byte) { +func (self *Context) SetCallCode(addr *common.Address, code []byte) { self.Code = code self.CodeAddr = addr } diff --git a/vm/environment.go b/vm/environment.go index 9de2fd80a..6976d6749 100644 --- a/vm/environment.go +++ b/vm/environment.go @@ -16,8 +16,8 @@ type Environment interface { Origin() common.Address BlockNumber() *big.Int - GetHash(n uint64) []byte - Coinbase() []byte + GetHash(n uint64) common.Hash + Coinbase() common.Address Time() int64 Difficulty() *big.Int GasLimit() *big.Int @@ -38,7 +38,7 @@ type Account interface { SubBalance(amount *big.Int) AddBalance(amount *big.Int) Balance() *big.Int - Address() []byte + Address() common.Address } // generic transfer method diff --git a/vm/vm.go b/vm/vm.go index 796a55ad3..706a3e108 100644 --- a/vm/vm.go +++ b/vm/vm.go @@ -58,8 +58,10 @@ func (self *Vm) Run(context *Context, callData []byte) (ret []byte, err error) { }() } - if p := Precompiled[context.CodeAddr.Str()]; p != nil { - return self.RunPrecompiled(p, callData, context) + if context.CodeAddr != nil { + if p := Precompiled[context.CodeAddr.Str()]; p != nil { + return self.RunPrecompiled(p, callData, context) + } } var ( @@ -500,7 +502,7 @@ func (self *Vm) Run(context *Context, callData []byte) (ret []byte, err error) { n := new(big.Int).Sub(self.env.BlockNumber(), common.Big257) if num.Cmp(n) > 0 && num.Cmp(self.env.BlockNumber()) < 0 { - stack.push(common.BigD(self.env.GetHash(num.Uint64()))) + stack.push(self.env.GetHash(num.Uint64()).Big()) } else { stack.push(common.Big0) } @@ -509,7 +511,7 @@ func (self *Vm) Run(context *Context, callData []byte) (ret []byte, err error) { case COINBASE: coinbase := self.env.Coinbase() - stack.push(common.BigD(coinbase)) + stack.push(coinbase.Big()) self.Printf(" => 0x%x", coinbase) case TIMESTAMP: -- cgit v1.2.3