cli/wallet: search for NEP-11 token name in balances

In the same way we do for NEP-17 tokens. This code predates "getnep11balances"
call, so this wasn't possible back then, but now we can improve the situation
(allow specifying names/symbols instead of hashes only).
This commit is contained in:
Roman Khimov 2022-08-26 23:12:22 +03:00
parent ed6ed61712
commit e28bf55ebb

View file

@ -315,15 +315,15 @@ func getMatchingTokenRPC(ctx *cli.Context, c *rpcclient.Client, addr util.Uint16
}
return getMatchingTokenAux(ctx, get, len(bs.Balances), name, standard)
case manifest.NEP11StandardName:
tokenHash, err := flags.ParseAddress(name)
bs, err := c.GetNEP11Balances(addr)
if err != nil {
return nil, fmt.Errorf("valid token adress or hash in LE should be specified for %s RPC-node request: %s", standard, err.Error())
return nil, err
}
get := func(i int) *wallet.Token {
t, _ := getTokenWithStandard(c, tokenHash, standard)
t, _ := getTokenWithStandard(c, bs.Balances[i].Asset, standard)
return t
}
return getMatchingTokenAux(ctx, get, 1, name, standard)
return getMatchingTokenAux(ctx, get, len(bs.Balances), name, standard)
default:
return nil, fmt.Errorf("unsupported %s token", standard)
}