mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-22 11:41:19 +00:00
Descriptive function names for closure getters
This commit is contained in:
parent
6d99c03d91
commit
b6cb5272de
@ -152,13 +152,6 @@ func (self *DebuggerWindow) Debug(valueStr, gasStr, gasPriceStr, scriptStr, data
|
|||||||
block := self.lib.eth.ChainManager().CurrentBlock
|
block := self.lib.eth.ChainManager().CurrentBlock
|
||||||
|
|
||||||
env := utils.NewEnv(statedb, block, account.Address(), value)
|
env := utils.NewEnv(statedb, block, account.Address(), value)
|
||||||
/*
|
|
||||||
callerClosure := vm.NewClosure(&state.Message{}, account, contract, script, gas, gasPrice)
|
|
||||||
evm := vm.NewDebugVm(env)
|
|
||||||
evm.Dbg = self.Db
|
|
||||||
self.vm = evm
|
|
||||||
self.Db.done = false
|
|
||||||
*/
|
|
||||||
|
|
||||||
self.Logf("callsize %d", len(script))
|
self.Logf("callsize %d", len(script))
|
||||||
go func() {
|
go func() {
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package vm
|
package vm
|
||||||
|
|
||||||
// TODO Re write VM to use values instead of big integers?
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
@ -17,7 +15,6 @@ type ClosureRef interface {
|
|||||||
SetStorage(*big.Int, *ethutil.Value)
|
SetStorage(*big.Int, *ethutil.Value)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Basic inline closure object which implement the 'closure' interface
|
|
||||||
type Closure struct {
|
type Closure struct {
|
||||||
caller ClosureRef
|
caller ClosureRef
|
||||||
object ClosureRef
|
object ClosureRef
|
||||||
@ -44,18 +41,8 @@ func NewClosure(msg *state.Message, caller ClosureRef, object ClosureRef, code [
|
|||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retuns the x element in data slice
|
func (c *Closure) GetValue(x *big.Int) *ethutil.Value {
|
||||||
func (c *Closure) GetStorage(x *big.Int) *ethutil.Value {
|
return c.GetRangeValue(x, big.NewInt(1))
|
||||||
m := c.object.GetStorage(x)
|
|
||||||
if m == nil {
|
|
||||||
return ethutil.EmptyValue()
|
|
||||||
}
|
|
||||||
|
|
||||||
return m
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Closure) Get(x *big.Int) *ethutil.Value {
|
|
||||||
return c.Gets(x, big.NewInt(1))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Closure) GetOp(x int) OpCode {
|
func (c *Closure) GetOp(x int) OpCode {
|
||||||
@ -78,7 +65,7 @@ func (c *Closure) GetBytes(x, y int) []byte {
|
|||||||
return c.Code[x : x+y]
|
return c.Code[x : x+y]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Closure) Gets(x, y *big.Int) *ethutil.Value {
|
func (c *Closure) GetRangeValue(x, y *big.Int) *ethutil.Value {
|
||||||
if x.Int64() >= int64(len(c.Code)) || y.Int64() >= int64(len(c.Code)) {
|
if x.Int64() >= int64(len(c.Code)) || y.Int64() >= int64(len(c.Code)) {
|
||||||
return ethutil.NewValue(0)
|
return ethutil.NewValue(0)
|
||||||
}
|
}
|
||||||
@ -88,27 +75,21 @@ func (c *Closure) Gets(x, y *big.Int) *ethutil.Value {
|
|||||||
return ethutil.NewValue(partial)
|
return ethutil.NewValue(partial)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *Closure) SetCode(code []byte) {
|
/*
|
||||||
self.Code = code
|
* State storage functions
|
||||||
}
|
*/
|
||||||
|
|
||||||
func (c *Closure) SetStorage(x *big.Int, val *ethutil.Value) {
|
func (c *Closure) SetStorage(x *big.Int, val *ethutil.Value) {
|
||||||
c.object.SetStorage(x, val)
|
c.object.SetStorage(x, val)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Closure) Address() []byte {
|
func (c *Closure) GetStorage(x *big.Int) *ethutil.Value {
|
||||||
return c.object.Address()
|
m := c.object.GetStorage(x)
|
||||||
|
if m == nil {
|
||||||
|
return ethutil.EmptyValue()
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
return m
|
||||||
func (c *Closure) Call(vm VirtualMachine, args []byte) ([]byte, *big.Int, error) {
|
|
||||||
c.Args = args
|
|
||||||
|
|
||||||
ret, err := vm.RunClosure(c)
|
|
||||||
|
|
||||||
return ret, c.UsedGas, err
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
func (c *Closure) Return(ret []byte) []byte {
|
func (c *Closure) Return(ret []byte) []byte {
|
||||||
// Return the remaining gas to the caller
|
// Return the remaining gas to the caller
|
||||||
@ -117,6 +98,9 @@ func (c *Closure) Return(ret []byte) []byte {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Gas functions
|
||||||
|
*/
|
||||||
func (c *Closure) UseGas(gas *big.Int) bool {
|
func (c *Closure) UseGas(gas *big.Int) bool {
|
||||||
if c.Gas.Cmp(gas) < 0 {
|
if c.Gas.Cmp(gas) < 0 {
|
||||||
return false
|
return false
|
||||||
@ -136,6 +120,17 @@ func (c *Closure) ReturnGas(gas, price *big.Int) {
|
|||||||
c.UsedGas.Sub(c.UsedGas, gas)
|
c.UsedGas.Sub(c.UsedGas, gas)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set / Get
|
||||||
|
*/
|
||||||
func (c *Closure) Caller() ClosureRef {
|
func (c *Closure) Caller() ClosureRef {
|
||||||
return c.caller
|
return c.caller
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Closure) Address() []byte {
|
||||||
|
return c.object.Address()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *Closure) SetCode(code []byte) {
|
||||||
|
self.Code = code
|
||||||
|
}
|
||||||
|
@ -737,7 +737,7 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
|
|||||||
case PUSH1, PUSH2, PUSH3, PUSH4, PUSH5, PUSH6, PUSH7, PUSH8, PUSH9, PUSH10, PUSH11, PUSH12, PUSH13, PUSH14, PUSH15, PUSH16, PUSH17, PUSH18, PUSH19, PUSH20, PUSH21, PUSH22, PUSH23, PUSH24, PUSH25, PUSH26, PUSH27, PUSH28, PUSH29, PUSH30, PUSH31, PUSH32:
|
case PUSH1, PUSH2, PUSH3, PUSH4, PUSH5, PUSH6, PUSH7, PUSH8, PUSH9, PUSH10, PUSH11, PUSH12, PUSH13, PUSH14, PUSH15, PUSH16, PUSH17, PUSH18, PUSH19, PUSH20, PUSH21, PUSH22, PUSH23, PUSH24, PUSH25, PUSH26, PUSH27, PUSH28, PUSH29, PUSH30, PUSH31, PUSH32:
|
||||||
a := big.NewInt(int64(op) - int64(PUSH1) + 1)
|
a := big.NewInt(int64(op) - int64(PUSH1) + 1)
|
||||||
pc.Add(pc, ethutil.Big1)
|
pc.Add(pc, ethutil.Big1)
|
||||||
data := closure.Gets(pc, a)
|
data := closure.GetRangeValue(pc, a)
|
||||||
val := ethutil.BigD(data.Bytes())
|
val := ethutil.BigD(data.Bytes())
|
||||||
// Push value to stack
|
// Push value to stack
|
||||||
stack.Push(val)
|
stack.Push(val)
|
||||||
@ -754,7 +754,7 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
|
|||||||
|
|
||||||
self.Printf(" => [%d] 0x%x", n, stack.Peek().Bytes())
|
self.Printf(" => [%d] 0x%x", n, stack.Peek().Bytes())
|
||||||
|
|
||||||
if OpCode(closure.Get(new(big.Int).Add(pc, ethutil.Big1)).Uint()) == POP && OpCode(closure.Get(new(big.Int).Add(pc, big.NewInt(2))).Uint()) == POP {
|
if OpCode(closure.GetValue(new(big.Int).Add(pc, ethutil.Big1)).Uint()) == POP && OpCode(closure.GetValue(new(big.Int).Add(pc, big.NewInt(2))).Uint()) == POP {
|
||||||
fmt.Println(toValue(v))
|
fmt.Println(toValue(v))
|
||||||
}
|
}
|
||||||
case SWAP1, SWAP2, SWAP3, SWAP4, SWAP5, SWAP6, SWAP7, SWAP8, SWAP9, SWAP10, SWAP11, SWAP12, SWAP13, SWAP14, SWAP15, SWAP16:
|
case SWAP1, SWAP2, SWAP3, SWAP4, SWAP5, SWAP6, SWAP7, SWAP8, SWAP9, SWAP10, SWAP11, SWAP12, SWAP13, SWAP14, SWAP15, SWAP16:
|
||||||
|
Loading…
Reference in New Issue
Block a user