2020-08-04 06:40:06 +00:00
|
|
|
package util
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2021-09-14 12:02:54 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/cli/options"
|
2022-10-05 09:30:54 +00:00
|
|
|
vmcli "github.com/nspcc-dev/neo-go/cli/vm"
|
2020-08-04 06:40:06 +00:00
|
|
|
"github.com/urfave/cli"
|
|
|
|
)
|
|
|
|
|
2020-08-05 10:17:23 +00:00
|
|
|
// NewCommands returns util commands for neo-go CLI.
|
2020-08-04 06:40:06 +00:00
|
|
|
func NewCommands() []cli.Command {
|
2021-09-14 12:02:54 +00:00
|
|
|
txDumpFlags := append([]cli.Flag{}, options.RPC...)
|
2020-08-04 06:40:06 +00:00
|
|
|
return []cli.Command{
|
|
|
|
{
|
|
|
|
Name: "util",
|
|
|
|
Usage: "Various helper commands",
|
|
|
|
Subcommands: []cli.Command{
|
|
|
|
{
|
|
|
|
Name: "convert",
|
|
|
|
Usage: "Convert provided argument into other possible formats",
|
|
|
|
UsageText: `convert <arg>
|
|
|
|
|
|
|
|
<arg> is an argument which is tried to be interpreted as an item of different types
|
|
|
|
and converted to other formats. Strings are escaped and output in quotes.`,
|
|
|
|
Action: handleParse,
|
|
|
|
},
|
2022-08-31 19:38:35 +00:00
|
|
|
{
|
|
|
|
Name: "sendtx",
|
|
|
|
Usage: "Send complete transaction stored in a context file",
|
|
|
|
UsageText: "sendtx [-r <endpoint>] <file.in>",
|
|
|
|
Description: `Sends the transaction from the given context file to the given RPC node if it's
|
|
|
|
completely signed and ready. This command expects a ContractParametersContext
|
|
|
|
JSON file for input, it can't handle binary (or hex- or base64-encoded)
|
|
|
|
transactions.
|
|
|
|
`,
|
|
|
|
Action: sendTx,
|
|
|
|
Flags: txDumpFlags,
|
|
|
|
},
|
2021-09-14 12:02:54 +00:00
|
|
|
{
|
|
|
|
Name: "txdump",
|
|
|
|
Usage: "Dump transaction stored in file",
|
|
|
|
UsageText: "txdump [-r <endpoint>] <file.in>",
|
|
|
|
Action: txDump,
|
|
|
|
Flags: txDumpFlags,
|
|
|
|
},
|
2020-08-04 06:40:06 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func handleParse(ctx *cli.Context) error {
|
|
|
|
res, err := vmcli.Parse(ctx.Args())
|
|
|
|
if err != nil {
|
|
|
|
return cli.NewExitError(err, 1)
|
|
|
|
}
|
2020-08-28 09:11:19 +00:00
|
|
|
fmt.Fprint(ctx.App.Writer, res)
|
2020-08-04 06:40:06 +00:00
|
|
|
return nil
|
|
|
|
}
|