mirror of https://github.com/status-im/op-geth.git
Fixed contract running
This commit is contained in:
parent
681eacaa7f
commit
18cc35338a
|
@ -321,19 +321,20 @@ func (bm *BlockManager) ProcContract(tx *Transaction, block *Block, cb TxCallbac
|
||||||
|
|
||||||
stepcount := 0
|
stepcount := 0
|
||||||
totalFee := new(big.Int)
|
totalFee := new(big.Int)
|
||||||
|
|
||||||
|
// helper function for getting a contract's memory address
|
||||||
|
getMem := func(num int) *ethutil.Value {
|
||||||
|
nb := ethutil.BigToBytes(big.NewInt(int64(num)), 256)
|
||||||
|
return contract.Addr(nb)
|
||||||
|
}
|
||||||
out:
|
out:
|
||||||
for {
|
for {
|
||||||
stepcount++
|
stepcount++
|
||||||
// The base big int for all calculations. Use this for any results.
|
// The base big int for all calculations. Use this for any results.
|
||||||
base := new(big.Int)
|
base := new(big.Int)
|
||||||
// XXX Should Instr return big int slice instead of string slice?
|
val := getMem(pc)
|
||||||
// Get the next instruction from the contract
|
|
||||||
nb := ethutil.BigToBytes(big.NewInt(int64(pc)), 256)
|
|
||||||
r := contract.State().Get(string(nb))
|
|
||||||
v := ethutil.NewValueFromBytes([]byte(r))
|
|
||||||
//fmt.Printf("%x = %d, %v %x\n", r, len(r), v, nb)
|
//fmt.Printf("%x = %d, %v %x\n", r, len(r), v, nb)
|
||||||
o := v.Uint()
|
op := OpCode(val.Uint())
|
||||||
op := OpCode(o)
|
|
||||||
|
|
||||||
var fee *big.Int = new(big.Int)
|
var fee *big.Int = new(big.Int)
|
||||||
var fee2 *big.Int = new(big.Int)
|
var fee2 *big.Int = new(big.Int)
|
||||||
|
@ -378,6 +379,7 @@ out:
|
||||||
|
|
||||||
switch op {
|
switch op {
|
||||||
case oSTOP:
|
case oSTOP:
|
||||||
|
fmt.Println("")
|
||||||
break out
|
break out
|
||||||
case oADD:
|
case oADD:
|
||||||
x, y := bm.stack.Popn()
|
x, y := bm.stack.Popn()
|
||||||
|
@ -580,7 +582,7 @@ out:
|
||||||
case oECVALID:
|
case oECVALID:
|
||||||
case oPUSH:
|
case oPUSH:
|
||||||
pc++
|
pc++
|
||||||
bm.stack.Push(bm.mem[strconv.Itoa(pc)])
|
bm.stack.Push(getMem(pc).BigInt())
|
||||||
case oPOP:
|
case oPOP:
|
||||||
// Pop current value of the stack
|
// Pop current value of the stack
|
||||||
bm.stack.Pop()
|
bm.stack.Pop()
|
||||||
|
|
|
@ -22,7 +22,6 @@ func TestVm(t *testing.T) {
|
||||||
"1",
|
"1",
|
||||||
"PUSH",
|
"PUSH",
|
||||||
"2",
|
"2",
|
||||||
|
|
||||||
"STOP",
|
"STOP",
|
||||||
})
|
})
|
||||||
bm.ApplyTransactions(block, []*Transaction{ctrct})
|
bm.ApplyTransactions(block, []*Transaction{ctrct})
|
||||||
|
|
Loading…
Reference in New Issue