diff --git a/docs/vm.md b/docs/vm.md index c9454c3b5..73d062797 100644 --- a/docs/vm.md +++ b/docs/vm.md @@ -1,6 +1,6 @@ # NEO-GO-VM -A cross platform virtual machine implementation for `avm` compatible programs. +A cross platform virtual machine implementation for `NEF` compatible programs. # Installation @@ -46,7 +46,7 @@ Commands: help display help ip Show current instruction istack Show invocation stack contents - loadavm Load an avm script into the VM + loadnef Load an avm script in NEF format into the VM loadgo Compile and load a Go file into the VM loadhex Load a hex-encoded script string into the VM ops Dump opcodes of the current loaded program @@ -70,10 +70,10 @@ Usage: step [] ## Loading in your script -To load an avm script into the VM: +To load an avm script in NEF format into the VM: ``` -NEO-GO-VM > loadavm ../contract.avm +NEO-GO-VM > loadnef ../contract.nef READY: loaded 36 instructions ``` diff --git a/pkg/vm/cli/cli.go b/pkg/vm/cli/cli.go index efe793255..4724ff123 100644 --- a/pkg/vm/cli/cli.go +++ b/pkg/vm/cli/cli.go @@ -67,12 +67,12 @@ var commands = []*ishell.Cmd{ Func: handleXStack, }, { - Name: "loadavm", - Help: "Load an avm script into the VM", - LongHelp: `Usage: loadavm + Name: "loadnef", + Help: "Load a NEF-consistent script into the VM", + LongHelp: `Usage: loadnef is mandatory parameter, example: -> load /path/to/script.avm`, - Func: handleLoadAVM, +> load /path/to/script.nef`, + Func: handleLoadNEF, }, { Name: "loadbase64", @@ -241,7 +241,7 @@ func handleXStack(c *ishell.Context) { c.Println(v.Stack(c.Cmd.Name)) } -func handleLoadAVM(c *ishell.Context) { +func handleLoadNEF(c *ishell.Context) { v := getVMFromContext(c) if len(c.Args) < 1 { c.Err(errors.New("missing parameter ")) diff --git a/pkg/vm/vm.go b/pkg/vm/vm.go index 90d16014b..02b9bed71 100644 --- a/pkg/vm/vm.go +++ b/pkg/vm/vm.go @@ -14,6 +14,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/encoding/bigint" "github.com/nspcc-dev/neo-go/pkg/smartcontract" + "github.com/nspcc-dev/neo-go/pkg/smartcontract/nef" "github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger" "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/vm/opcode" @@ -86,7 +87,7 @@ type VM struct { keys map[string]*keys.PublicKey } -// New returns a new VM object ready to load .avm bytecode scripts. +// New returns a new VM object ready to load AVM bytecode scripts. func New() *VM { return NewWithTrigger(trigger.System) } @@ -235,13 +236,17 @@ func (v *VM) AddBreakPointRel(n int) { v.AddBreakPoint(ctx.ip + n) } -// LoadFile loads a program from the given path, ready to execute it. +// LoadFile loads a program in NEF format from the given path, ready to execute it. func (v *VM) LoadFile(path string) error { b, err := ioutil.ReadFile(path) if err != nil { return err } - v.Load(b) + f, err := nef.FileFromBytes(b) + if err != nil { + return err + } + v.Load(f.Script) return nil }