From 97131683d8a91e1e4f4213935e46e0f2a39553a9 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 6 Mar 2020 17:22:28 +0300 Subject: [PATCH] cli: display info about imported NEP5 token --- cli/wallet/nep5.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/cli/wallet/nep5.go b/cli/wallet/nep5.go index a166c60cd..dc738325b 100644 --- a/cli/wallet/nep5.go +++ b/cli/wallet/nep5.go @@ -53,6 +53,19 @@ func newNEP5Commands() []cli.Command { }, }, }, + { + Name: "info", + Usage: "print imported NEP5 token info", + UsageText: "print --path [--token ]", + 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 {