forked from TrueCloudLab/neoneo-go
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.
This commit is contained in:
parent
3d6ff3559e
commit
5d63ff100e
1 changed files with 21 additions and 0 deletions
|
@ -2,6 +2,7 @@ package cli
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"encoding/base64"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -73,6 +74,14 @@ var commands = []*ishell.Cmd{
|
||||||
> load /path/to/script.avm`,
|
> load /path/to/script.avm`,
|
||||||
Func: handleLoadAVM,
|
Func: handleLoadAVM,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "loadbase64",
|
||||||
|
Help: "Load a base64-encoded script string into the VM",
|
||||||
|
LongHelp: `Usage: loadbase64 <string>
|
||||||
|
<string> is mandatory parameter, example:
|
||||||
|
> loadbase64 AwAQpdToAAAADBQV9ehtQR1OrVZVhtHtoUHRfoE+agwUzmFvf3Rhfg/EuAVYOvJgKiON9j8TwAwIdHJhbnNmZXIMFDt9NxHG8Mz5sdypA9G/odiW8SOMQWJ9W1I4`,
|
||||||
|
Func: handleLoadBase64,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Name: "loadhex",
|
Name: "loadhex",
|
||||||
Help: "Load a hex-encoded script string into the VM",
|
Help: "Load a hex-encoded script string into the VM",
|
||||||
|
@ -242,6 +251,18 @@ func handleLoadAVM(c *ishell.Context) {
|
||||||
changePrompt(c, v)
|
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) {
|
func handleLoadHex(c *ishell.Context) {
|
||||||
v := getVMFromContext(c)
|
v := getVMFromContext(c)
|
||||||
b, err := hex.DecodeString(c.Args[0])
|
b, err := hex.DecodeString(c.Args[0])
|
||||||
|
|
Loading…
Add table
Reference in a new issue