neo-go/pkg/vm/vm.go
BlockChainDev 80fd427517 - Add Op to handleOP func signature
- Add PushNBytes OPcode
2019-03-15 23:37:54 +00:00

39 lines
784 B
Go

package vm
import (
"fmt"
"github.com/CityOfZion/neo-go/pkg/vm/stack"
)
// VM represents an instance of a Neo Virtual Machine
type VM struct {
InvocationStack stack.Invocation
state vmstate
}
//NewVM loads in a script
// uses the script to initiate a Context object
// pushes the context to the invocation stack
func NewVM(script []byte) *VM {
ctx := stack.NewContext(script)
v := &VM{
state: NONE,
}
v.InvocationStack.Push(ctx)
return v
}
// 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(op, ctx, &v.InvocationStack)
if err != nil {
return err
}
return nil
}