2018-03-30 16:15:06 +00:00
|
|
|
package vm
|
|
|
|
|
|
|
|
import (
|
2019-10-03 13:56:48 +00:00
|
|
|
"errors"
|
|
|
|
"io/ioutil"
|
|
|
|
|
|
|
|
"github.com/CityOfZion/neo-go/pkg/vm"
|
2018-03-30 16:15:06 +00:00
|
|
|
vmcli "github.com/CityOfZion/neo-go/pkg/vm/cli"
|
|
|
|
"github.com/urfave/cli"
|
|
|
|
)
|
|
|
|
|
|
|
|
// NewCommand creates a new VM command.
|
|
|
|
func NewCommand() cli.Command {
|
|
|
|
return cli.Command{
|
|
|
|
Name: "vm",
|
|
|
|
Usage: "start the virtual machine",
|
|
|
|
Action: startVMPrompt,
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
cli.BoolFlag{Name: "debug, d"},
|
|
|
|
},
|
2019-10-03 13:56:48 +00:00
|
|
|
Subcommands: []cli.Command{
|
|
|
|
{
|
|
|
|
Name: "inspect",
|
|
|
|
Usage: "dump instructions of the avm file given",
|
|
|
|
Action: inspect,
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
cli.StringFlag{
|
|
|
|
Name: "in, i",
|
|
|
|
Usage: "input file of the program (AVM)",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-03-30 16:15:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func startVMPrompt(ctx *cli.Context) error {
|
|
|
|
p := vmcli.New()
|
|
|
|
return p.Run()
|
|
|
|
}
|
2019-10-03 13:56:48 +00:00
|
|
|
|
|
|
|
func inspect(ctx *cli.Context) error {
|
|
|
|
avm := ctx.String("in")
|
|
|
|
if len(avm) == 0 {
|
|
|
|
return cli.NewExitError(errors.New("no input file given"), 1)
|
|
|
|
}
|
|
|
|
b, err := ioutil.ReadFile(avm)
|
|
|
|
if err != nil {
|
|
|
|
return cli.NewExitError(err, 1)
|
|
|
|
}
|
|
|
|
v := vm.New(0)
|
|
|
|
v.LoadScript(b)
|
|
|
|
v.PrintOps()
|
|
|
|
return nil
|
|
|
|
}
|