From 5d63ff100e94febb247e70763c26db9696c399c8 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Thu, 25 Jun 2020 17:25:05 +0300 Subject: [PATCH] vm/cli: add support for loadbase64 command Neo3 outputs scripts in base64 for transactions and contracts, to quickly parse them add a special `loadbase64` command. --- pkg/vm/cli/cli.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/pkg/vm/cli/cli.go b/pkg/vm/cli/cli.go index 433917335..6355491c6 100644 --- a/pkg/vm/cli/cli.go +++ b/pkg/vm/cli/cli.go @@ -2,6 +2,7 @@ package cli import ( "bytes" + "encoding/base64" "encoding/hex" "errors" "fmt" @@ -73,6 +74,14 @@ var commands = []*ishell.Cmd{ > load /path/to/script.avm`, Func: handleLoadAVM, }, + { + Name: "loadbase64", + Help: "Load a base64-encoded script string into the VM", + LongHelp: `Usage: loadbase64 + is mandatory parameter, example: +> loadbase64 AwAQpdToAAAADBQV9ehtQR1OrVZVhtHtoUHRfoE+agwUzmFvf3Rhfg/EuAVYOvJgKiON9j8TwAwIdHJhbnNmZXIMFDt9NxHG8Mz5sdypA9G/odiW8SOMQWJ9W1I4`, + Func: handleLoadBase64, + }, { Name: "loadhex", Help: "Load a hex-encoded script string into the VM", @@ -242,6 +251,18 @@ func handleLoadAVM(c *ishell.Context) { changePrompt(c, v) } +func handleLoadBase64(c *ishell.Context) { + v := getVMFromContext(c) + b, err := base64.StdEncoding.DecodeString(c.Args[0]) + if err != nil { + c.Err(err) + return + } + v.Load(b) + c.Printf("READY: loaded %d instructions\n", v.Context().LenInstr()) + changePrompt(c, v) +} + func handleLoadHex(c *ishell.Context) { v := getVMFromContext(c) b, err := hex.DecodeString(c.Args[0])