mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-02-21 05:28:05 +00:00
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
|
# NEO-GO-VM
|
||||||
|
|
||||||
A cross platform virtual machine implementation for `avm` compatible programs.
|
A cross platform virtual machine implementation for `NEF` compatible programs.
|
||||||
|
|
||||||
# Installation
|
# Installation
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ Commands:
|
||||||
help display help
|
help display help
|
||||||
ip Show current instruction
|
ip Show current instruction
|
||||||
istack Show invocation stack contents
|
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
|
loadgo Compile and load a Go file into the VM
|
||||||
loadhex Load a hex-encoded script string into the VM
|
loadhex Load a hex-encoded script string into the VM
|
||||||
ops Dump opcodes of the current loaded program
|
ops Dump opcodes of the current loaded program
|
||||||
|
@ -70,10 +70,10 @@ Usage: step [<n>]
|
||||||
|
|
||||||
## Loading in your script
|
## 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
|
READY: loaded 36 instructions
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -67,12 +67,12 @@ var commands = []*ishell.Cmd{
|
||||||
Func: handleXStack,
|
Func: handleXStack,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "loadavm",
|
Name: "loadnef",
|
||||||
Help: "Load an avm script into the VM",
|
Help: "Load a NEF-consistent script into the VM",
|
||||||
LongHelp: `Usage: loadavm <file>
|
LongHelp: `Usage: loadnef <file>
|
||||||
<file> is mandatory parameter, example:
|
<file> is mandatory parameter, example:
|
||||||
> load /path/to/script.avm`,
|
> load /path/to/script.nef`,
|
||||||
Func: handleLoadAVM,
|
Func: handleLoadNEF,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "loadbase64",
|
Name: "loadbase64",
|
||||||
|
@ -241,7 +241,7 @@ func handleXStack(c *ishell.Context) {
|
||||||
c.Println(v.Stack(c.Cmd.Name))
|
c.Println(v.Stack(c.Cmd.Name))
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleLoadAVM(c *ishell.Context) {
|
func handleLoadNEF(c *ishell.Context) {
|
||||||
v := getVMFromContext(c)
|
v := getVMFromContext(c)
|
||||||
if len(c.Args) < 1 {
|
if len(c.Args) < 1 {
|
||||||
c.Err(errors.New("missing parameter <file>"))
|
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/crypto/keys"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/encoding/bigint"
|
"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"
|
||||||
|
"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/smartcontract/trigger"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
||||||
|
@ -86,7 +87,7 @@ type VM struct {
|
||||||
keys map[string]*keys.PublicKey
|
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 {
|
func New() *VM {
|
||||||
return NewWithTrigger(trigger.System)
|
return NewWithTrigger(trigger.System)
|
||||||
}
|
}
|
||||||
|
@ -235,13 +236,17 @@ func (v *VM) AddBreakPointRel(n int) {
|
||||||
v.AddBreakPoint(ctx.ip + n)
|
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 {
|
func (v *VM) LoadFile(path string) error {
|
||||||
b, err := ioutil.ReadFile(path)
|
b, err := ioutil.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
v.Load(b)
|
f, err := nef.FileFromBytes(b)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
v.Load(f.Script)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue