[#122] Implement balance precision getter for inner ring

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2020-10-27 13:25:55 +03:00 committed by Alex Vanin
parent 7db40eafe0
commit b6012977bc

View file

@ -36,6 +36,7 @@ const (
lockMethod = "lock"
mintMethod = "mint"
burnMethod = "burn"
precisionMethod = "decimals"
)
// TransferBalanceX invokes transferX method.
@ -92,3 +93,22 @@ func LockAsset(cli *client.Client, con util.Uint160, p *LockParams) error {
int64(p.Until),
)
}
// BalancePrecision invokes Decimal method that returns precision of NEP-5 contract.
func BalancePrecision(cli *client.Client, con util.Uint160) (uint32, error) {
if cli == nil {
return 0, client.ErrNilClient
}
v, err := cli.TestInvoke(con, precisionMethod)
if err != nil {
return 0, err
}
precision, err := client.IntFromStackItem(v[0])
if err != nil {
return 0, err
}
return uint32(precision), nil
}