cli/wallet: print token symbol and name in balance output
Make it a bit more user-friendly.
This commit is contained in:
parent
c6a9e652b4
commit
aba9c9c0a8
2 changed files with 17 additions and 5 deletions
|
@ -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())
|
||||
})
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue