vm: switch from .avm to .nef
This commit is contained in:
parent
c7746da023
commit
b387deaa05
3 changed files with 18 additions and 13 deletions
|
@ -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 [<n>]
|
|||
|
||||
## 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
|
||||
```
|
||||
|
||||
|
|
|
@ -67,12 +67,12 @@ var commands = []*ishell.Cmd{
|
|||
Func: handleXStack,
|
||||
},
|
||||
{
|
||||
Name: "loadavm",
|
||||
Help: "Load an avm script into the VM",
|
||||
LongHelp: `Usage: loadavm <file>
|
||||
Name: "loadnef",
|
||||
Help: "Load a NEF-consistent script into the VM",
|
||||
LongHelp: `Usage: loadnef <file>
|
||||
<file> 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 <file>"))
|
||||
|
|
11
pkg/vm/vm.go
11
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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue