mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-23 03:41:34 +00:00
- Add Op
to handleOP func signature
- Add PushNBytes OPcode
This commit is contained in:
parent
9a59755745
commit
80fd427517
4 changed files with 34 additions and 6 deletions
|
@ -26,11 +26,12 @@ func NewVM(script []byte) *VM {
|
|||
|
||||
// ExecuteOp will execute one opcode for a given context
|
||||
func (v *VM) ExecuteOp(op stack.Instruction, ctx *stack.Context) error {
|
||||
|
||||
handleOp, ok := opFunc[op]
|
||||
if !ok {
|
||||
return fmt.Errorf("unknown opcode entered %v", op)
|
||||
}
|
||||
err := handleOp(ctx, &v.InvocationStack)
|
||||
err := handleOp(op, ctx, &v.InvocationStack)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -2,7 +2,15 @@ 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,
|
||||
stack.SUB: Sub,
|
||||
var opFunc = map[stack.Instruction]func(op stack.Instruction, ctx *stack.Context, istack *stack.Invocation) error{
|
||||
stack.ADD: Add,
|
||||
stack.SUB: Sub,
|
||||
stack.PUSHBYTES1: PushNBytes,
|
||||
stack.PUSHBYTES75: PushNBytes,
|
||||
}
|
||||
|
||||
func init() {
|
||||
for i := int(stack.PUSHBYTES1); i <= int(stack.PUSHBYTES75); i++ {
|
||||
opFunc[stack.Instruction(i)] = PushNBytes
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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(ctx *stack.Context, istack *stack.Invocation) error {
|
||||
func Add(op stack.Instruction, ctx *stack.Context, istack *stack.Invocation) error {
|
||||
|
||||
operandA, operandB, err := popTwoIntegers(ctx)
|
||||
|
||||
|
@ -24,7 +24,7 @@ func Add(ctx *stack.Context, istack *stack.Invocation) error {
|
|||
// 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(ctx *stack.Context, istack *stack.Invocation) error {
|
||||
func Sub(op stack.Instruction, ctx *stack.Context, istack *stack.Invocation) error {
|
||||
|
||||
operandA, operandB, err := popTwoIntegers(ctx)
|
||||
|
||||
|
|
19
pkg/vm/vm_ops_stackmani.go
Normal file
19
pkg/vm/vm_ops_stackmani.go
Normal file
|
@ -0,0 +1,19 @@
|
|||
package vm
|
||||
|
||||
import (
|
||||
"github.com/CityOfZion/neo-go/pkg/vm/stack"
|
||||
)
|
||||
|
||||
// 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) error {
|
||||
|
||||
val, err := ctx.ReadBytes(int(op))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ba := stack.NewByteArray(val)
|
||||
ctx.Estack.Push(ba)
|
||||
return nil
|
||||
}
|
Loading…
Reference in a new issue