From 22e99a5b3e2900859db483fe40734d9d900c4cae Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 6 Mar 2020 16:20:23 +0300 Subject: [PATCH] rpc: implement (*Client).NEP5TokenInfo() It can be useful to receive all NEP5 token info at once. --- pkg/rpc/client/nep5.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/pkg/rpc/client/nep5.go b/pkg/rpc/client/nep5.go index 7970f03ce..9f6acbd2e 100644 --- a/pkg/rpc/client/nep5.go +++ b/pkg/rpc/client/nep5.go @@ -7,6 +7,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/smartcontract" "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/vm/emit" + "github.com/nspcc-dev/neo-go/pkg/wallet" ) // NEP5Decimals invokes `decimals` NEP5 method on a specified contract. @@ -69,6 +70,23 @@ func (c *Client) NEP5BalanceOf(tokenHash util.Uint160) (int64, error) { return topIntFromStack(result.Stack) } +// NEP5TokenInfo returns full NEP5 token info. +func (c *Client) NEP5TokenInfo(tokenHash util.Uint160) (*wallet.Token, error) { + name, err := c.NEP5Name(tokenHash) + if err != nil { + return nil, err + } + symbol, err := c.NEP5Symbol(tokenHash) + if err != nil { + return nil, err + } + decimals, err := c.NEP5Decimals(tokenHash) + if err != nil { + return nil, err + } + return wallet.NewToken(tokenHash, name, symbol, decimals), nil +} + func topIntFromStack(st []smartcontract.Parameter) (int64, error) { index := len(st) - 1 // top stack element is last in the array var decimals int64