From b6012977bc6fff79ac2806de2a728b1dad610234 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Tue, 27 Oct 2020 13:25:55 +0300 Subject: [PATCH] [#122] Implement balance precision getter for inner ring Signed-off-by: Alex Vanin --- pkg/innerring/invoke/balance.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/pkg/innerring/invoke/balance.go b/pkg/innerring/invoke/balance.go index ef3a349f96..4e708f7de9 100644 --- a/pkg/innerring/invoke/balance.go +++ b/pkg/innerring/invoke/balance.go @@ -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 +}