rpc: implement (*Client).NEP5TokenInfo()
It can be useful to receive all NEP5 token info at once.
This commit is contained in:
parent
564a8e429d
commit
22e99a5b3e
1 changed files with 18 additions and 0 deletions
|
@ -7,6 +7,7 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
|
"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.
|
// 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)
|
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) {
|
func topIntFromStack(st []smartcontract.Parameter) (int64, error) {
|
||||||
index := len(st) - 1 // top stack element is last in the array
|
index := len(st) - 1 // top stack element is last in the array
|
||||||
var decimals int64
|
var decimals int64
|
||||||
|
|
Loading…
Reference in a new issue