refactor handlers to have rstack as argument
This commit is contained in:
BlockChainDev 2019-03-18 21:14:03 +00:00
parent 38ad4572c4
commit c177e5577e
5 changed files with 13 additions and 11 deletions

View file

@ -6,7 +6,7 @@ import "github.com/CityOfZion/neo-go/pkg/vm/stack"
// EQUAL pushes true to the stack
// If the two top items on the stack are equal
func EQUAL(op stack.Instruction, ctx *stack.Context, istack *stack.Invocation) (Vmstate, error) {
func EQUAL(op stack.Instruction, ctx *stack.Context, istack *stack.Invocation, rstack *stack.RandomAccess) (Vmstate, error) {
itemA, itemB, err := popTwoByteArrays(ctx)
if err != nil {

View file

@ -12,7 +12,7 @@ import (
// does not evaluate to true
// For specific logic on how a number of bytearray is evaluated can be seen
// from the boolean conversion methods on the stack items
func THROWIFNOT(op stack.Instruction, ctx *stack.Context, istack *stack.Invocation) (Vmstate, error) {
func THROWIFNOT(op stack.Instruction, ctx *stack.Context, istack *stack.Invocation, rstack *stack.RandomAccess) (Vmstate, error) {
// Pop item from top of stack
item, err := ctx.Estack.Pop()
@ -27,7 +27,7 @@ func THROWIFNOT(op stack.Instruction, ctx *stack.Context, istack *stack.Invocati
// If false, throw
if !ok.Value() {
return FAULT, errors.New("Item on top of stack evaluates to false")
return FAULT, errors.New("item on top of stack evaluates to false")
}
return NONE, nil
}

View file

@ -8,17 +8,19 @@ import (
// RET Returns from the current context
// Returns HALT if there are nomore context's to run
func RET(op stack.Instruction, ctx *stack.Context, istack *stack.Invocation) (Vmstate, error) {
func RET(op stack.Instruction, ctx *stack.Context, istack *stack.Invocation, rstack *stack.RandomAccess) (Vmstate, error) {
// Pop current context from the Inovation stack
err := istack.RemoveCurrentContext()
ctx, err := istack.PopCurrentContext()
if err != nil {
return FAULT, err
}
// If there are no-more context's left to ran, then we HALT
// If this was the last context, then we copy over the evaluation stack to the resultstack
// As the program is about to terminate, once we remove the context
if istack.Len() == 0 {
return HALT, nil
err = ctx.Estack.CopyTo(rstack)
return HALT, err
}
return NONE, nil

View file

@ -7,7 +7,7 @@ import (
// Add adds two stack Items together.
// Returns an error if either items cannot be casted to an integer
// or if integers cannot be added together
func Add(op stack.Instruction, ctx *stack.Context, istack *stack.Invocation) (Vmstate, error) {
func Add(op stack.Instruction, ctx *stack.Context, istack *stack.Invocation, rstack *stack.RandomAccess) (Vmstate, error) {
operandA, operandB, err := popTwoIntegers(ctx)
if err != nil {
@ -26,7 +26,7 @@ func Add(op stack.Instruction, ctx *stack.Context, istack *stack.Invocation) (Vm
// Sub subtracts two stack Items.
// Returns an error if either items cannot be casted to an integer
// or if integers cannot be subtracted together
func Sub(op stack.Instruction, ctx *stack.Context, istack *stack.Invocation) (Vmstate, error) {
func Sub(op stack.Instruction, ctx *stack.Context, istack *stack.Invocation, rstack *stack.RandomAccess) (Vmstate, error) {
operandA, operandB, err := popTwoIntegers(ctx)
if err != nil {

View file

@ -7,7 +7,7 @@ import (
// Stack Manipulation Opcodes
// PushNBytes will Read N Bytes from the script and push it onto the stack
func PushNBytes(op stack.Instruction, ctx *stack.Context, istack *stack.Invocation) (Vmstate, error) {
func PushNBytes(op stack.Instruction, ctx *stack.Context, istack *stack.Invocation, rstack *stack.RandomAccess) (Vmstate, error) {
val, err := ctx.ReadBytes(int(op))
if err != nil {