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 // EQUAL pushes true to the stack
// If the two top items on the stack are equal // 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) itemA, itemB, err := popTwoByteArrays(ctx)
if err != nil { if err != nil {

View file

@ -12,7 +12,7 @@ import (
// does not evaluate to true // does not evaluate to true
// For specific logic on how a number of bytearray is evaluated can be seen // For specific logic on how a number of bytearray is evaluated can be seen
// from the boolean conversion methods on the stack items // 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 // Pop item from top of stack
item, err := ctx.Estack.Pop() item, err := ctx.Estack.Pop()
@ -27,7 +27,7 @@ func THROWIFNOT(op stack.Instruction, ctx *stack.Context, istack *stack.Invocati
// If false, throw // If false, throw
if !ok.Value() { 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 return NONE, nil
} }

View file

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

View file

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

View file

@ -7,7 +7,7 @@ import (
// Stack Manipulation Opcodes // Stack Manipulation Opcodes
// PushNBytes will Read N Bytes from the script and push it onto the stack // 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)) val, err := ctx.ReadBytes(int(op))
if err != nil { if err != nil {