cli: display info about imported NEP5 token

This commit is contained in:
Evgenii Stratonikov 2020-03-06 17:22:28 +03:00
parent 053b779be7
commit 97131683d8

View file

@ -53,6 +53,19 @@ func newNEP5Commands() []cli.Command {
},
},
},
{
Name: "info",
Usage: "print imported NEP5 token info",
UsageText: "print --path <path> [--token <hash-or-name>]",
Action: printNEP5Info,
Flags: []cli.Flag{
walletPathFlag,
cli.StringFlag{
Name: "token",
Usage: "Token name or hash",
},
},
},
{
Name: "transfer",
Usage: "transfer NEP5 tokens",
@ -222,6 +235,31 @@ func printTokenInfo(tok *wallet.Token) {
fmt.Printf("Address: %s\n", tok.Address)
}
func printNEP5Info(ctx *cli.Context) error {
wall, err := openWallet(ctx.String("path"))
if err != nil {
return cli.NewExitError(err, 1)
}
defer wall.Close()
if name := ctx.String("token"); name != "" {
token, err := getMatchingToken(wall, name)
if err != nil {
return cli.NewExitError(err, 1)
}
printTokenInfo(token)
return nil
}
for i, t := range wall.Extra.Tokens {
if i > 0 {
fmt.Println()
}
printTokenInfo(t)
}
return nil
}
func transferNEP5(ctx *cli.Context) error {
wall, err := openWallet(ctx.String("path"))
if err != nil {