From aba9c9c0a8cd23548001198052bc86968a6943f7 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Mon, 28 Sep 2020 16:47:47 +0300 Subject: [PATCH] cli/wallet: print token symbol and name in balance output Make it a bit more user-friendly. --- cli/nep5_test.go | 4 ++-- cli/wallet/nep5.go | 18 +++++++++++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/cli/nep5_test.go b/cli/nep5_test.go index 2f879ecc3..c99f3cda1 100644 --- a/cli/nep5_test.go +++ b/cli/nep5_test.go @@ -27,7 +27,7 @@ func TestNEP5Balance(t *testing.T) { t.Run("NEO", func(t *testing.T) { b, index := e.Chain.GetGoverningTokenBalance(validatorHash) checkResult := func(t *testing.T) { - e.checkNextLine(t, "^\\s*TokenHash:\\s*"+e.Chain.GoverningTokenHash().StringLE()) + e.checkNextLine(t, "^\\s*NEO:\\s+NEO \\("+e.Chain.GoverningTokenHash().StringLE()+"\\)") e.checkNextLine(t, "^\\s*Amount\\s*:\\s*"+b.String()) e.checkNextLine(t, "^\\s*Updated\\s*:\\s*"+strconv.FormatUint(uint64(index), 10)) e.checkEOF(t) @@ -43,7 +43,7 @@ func TestNEP5Balance(t *testing.T) { }) t.Run("GAS", func(t *testing.T) { e.Run(t, append(cmd, "--token", "gas")...) - e.checkNextLine(t, "^\\s*TokenHash:\\s*"+e.Chain.UtilityTokenHash().StringLE()) + e.checkNextLine(t, "^\\s*GAS:\\s+GAS \\("+e.Chain.UtilityTokenHash().StringLE()+"\\)") b := e.Chain.GetUtilityTokenBalance(validatorHash) e.checkNextLine(t, "^\\s*Amount\\s*:\\s*"+util.Fixed8(b.Int64()).String()) }) diff --git a/cli/wallet/nep5.go b/cli/wallet/nep5.go index ffaea7232..106857e6a 100644 --- a/cli/wallet/nep5.go +++ b/cli/wallet/nep5.go @@ -177,11 +177,23 @@ func getNEP5Balance(ctx *cli.Context) error { } for i := range balances.Balances { + var tokenName, tokenSymbol string + asset := balances.Balances[i].Asset if name != "" && !token.Hash.Equals(asset) { continue } - fmt.Fprintf(ctx.App.Writer, "TokenHash: %s\n", asset.StringLE()) + token, err := getMatchingToken(ctx, wall, asset.StringLE()) + if err != nil { + token, err = c.NEP5TokenInfo(asset) + } + if err == nil { + tokenName = token.Name + tokenSymbol = token.Symbol + } else { + tokenSymbol = "UNKNOWN" + } + fmt.Fprintf(ctx.App.Writer, "%s: %s (%s)\n", strings.ToUpper(tokenSymbol), tokenName, asset.StringLE()) fmt.Fprintf(ctx.App.Writer, "\tAmount : %s\n", balances.Balances[i].Amount) fmt.Fprintf(ctx.App.Writer, "\tUpdated: %d\n", balances.Balances[i].LastUpdated) } @@ -190,9 +202,9 @@ func getNEP5Balance(ctx *cli.Context) error { func getMatchingToken(ctx *cli.Context, w *wallet.Wallet, name string) (*wallet.Token, error) { switch strings.ToLower(name) { - case "neo": + case "neo", client.NeoContractHash.StringLE(): return neoToken, nil - case "gas": + case "gas", client.GasContractHash.StringLE(): return gasToken, nil } return getMatchingTokenAux(ctx, func(i int) *wallet.Token {