mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-22 19:29:39 +00:00
513821cfff
Close #2528. Also, add new simple testchain as an analogue for basicchain.
48 lines
1.2 KiB
Go
48 lines
1.2 KiB
Go
package vm
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/chzyer/readline"
|
|
"github.com/nspcc-dev/neo-go/cli/cmdargs"
|
|
"github.com/nspcc-dev/neo-go/cli/options"
|
|
"github.com/nspcc-dev/neo-go/pkg/core/storage/dbconfig"
|
|
"github.com/urfave/cli"
|
|
)
|
|
|
|
// NewCommands returns 'vm' command.
|
|
func NewCommands() []cli.Command {
|
|
cfgFlags := []cli.Flag{options.Config}
|
|
cfgFlags = append(cfgFlags, options.Network...)
|
|
return []cli.Command{{
|
|
Name: "vm",
|
|
Usage: "start the virtual machine",
|
|
Action: startVMPrompt,
|
|
Flags: cfgFlags,
|
|
}}
|
|
}
|
|
|
|
func startVMPrompt(ctx *cli.Context) error {
|
|
if err := cmdargs.EnsureNone(ctx); err != nil {
|
|
return err
|
|
}
|
|
|
|
cfg, err := options.GetConfigFromContext(ctx)
|
|
if err != nil {
|
|
return cli.NewExitError(err, 1)
|
|
}
|
|
if ctx.NumFlags() == 0 {
|
|
cfg.ApplicationConfiguration.DBConfiguration.Type = dbconfig.InMemoryDB
|
|
}
|
|
if cfg.ApplicationConfiguration.DBConfiguration.Type != dbconfig.InMemoryDB {
|
|
cfg.ApplicationConfiguration.DBConfiguration.LevelDBOptions.ReadOnly = true
|
|
cfg.ApplicationConfiguration.DBConfiguration.BoltDBOptions.ReadOnly = true
|
|
}
|
|
|
|
p, err := NewWithConfig(true, os.Exit, &readline.Config{}, cfg)
|
|
if err != nil {
|
|
return cli.NewExitError(fmt.Errorf("failed to create VM CLI: %w", err), 1)
|
|
}
|
|
return p.Run()
|
|
}
|