diff --git a/pkg/vm/vm_ops.go b/pkg/vm/vm_ops.go new file mode 100644 index 000000000..456552597 --- /dev/null +++ b/pkg/vm/vm_ops.go @@ -0,0 +1,7 @@ +package vm + +import "github.com/CityOfZion/neo-go/pkg/vm/stack" + +var opFunc = map[stack.Instruction]func(ctx *stack.Context, istack *stack.Invocation) error{ + stack.ADD: Add, +} diff --git a/pkg/vm/vm_ops_maths.go b/pkg/vm/vm_ops_maths.go new file mode 100644 index 000000000..f31aab6ec --- /dev/null +++ b/pkg/vm/vm_ops_maths.go @@ -0,0 +1,25 @@ +package vm + +import "github.com/CityOfZion/neo-go/pkg/vm/stack" + +// 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(ctx *stack.Context, istack *stack.Invocation) error { + operandA, err := ctx.Estack.PopInt() + if err != nil { + return err + } + operandB, err := ctx.Estack.PopInt() + if err != nil { + return err + } + res, err := operandA.Add(operandB) + if err != nil { + return err + } + + ctx.Estack.Push(res) + + return nil +}