2021-04-22 15:21:18 +00:00
|
|
|
package wallet
|
|
|
|
|
|
|
|
import (
|
2022-02-04 16:18:35 +00:00
|
|
|
"encoding/hex"
|
2021-04-23 15:42:59 +00:00
|
|
|
"errors"
|
|
|
|
"fmt"
|
2024-08-23 21:07:41 +00:00
|
|
|
"slices"
|
2022-08-19 07:37:22 +00:00
|
|
|
"strconv"
|
2021-04-23 15:42:59 +00:00
|
|
|
|
2022-08-05 10:32:37 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/cli/cmdargs"
|
2021-04-23 15:42:59 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/cli/flags"
|
|
|
|
"github.com/nspcc-dev/neo-go/cli/options"
|
2022-10-06 19:59:47 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/cli/txctx"
|
2022-08-19 07:37:22 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/config"
|
2021-04-23 15:42:59 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
2022-08-29 19:39:13 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient"
|
2022-08-19 07:37:22 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/nep11"
|
2021-04-22 15:21:18 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
|
2022-08-29 19:39:13 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
2021-04-26 14:09:37 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
2021-04-23 15:42:59 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/wallet"
|
2024-07-09 18:24:39 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
2021-04-22 15:21:18 +00:00
|
|
|
)
|
|
|
|
|
2024-07-09 18:24:39 +00:00
|
|
|
func newNEP11Commands() []*cli.Command {
|
2022-08-19 07:37:22 +00:00
|
|
|
maxIters := strconv.Itoa(config.DefaultMaxIteratorResultItems)
|
2024-07-09 18:24:39 +00:00
|
|
|
tokenAddressFlag := &flags.AddressFlag{
|
2024-07-04 22:34:40 +00:00
|
|
|
Name: "token",
|
|
|
|
Usage: "Token contract address or hash in LE",
|
|
|
|
Required: true,
|
2021-04-27 14:55:01 +00:00
|
|
|
}
|
2024-07-09 18:24:39 +00:00
|
|
|
ownerAddressFlag := &flags.AddressFlag{
|
2024-07-04 22:34:40 +00:00
|
|
|
Name: "address",
|
|
|
|
Usage: "NFT owner address or hash in LE",
|
|
|
|
Required: true,
|
2021-04-28 14:50:12 +00:00
|
|
|
}
|
2024-07-09 18:24:39 +00:00
|
|
|
tokenID := &cli.StringFlag{
|
2021-04-23 15:42:59 +00:00
|
|
|
Name: "id",
|
2022-02-04 16:18:35 +00:00
|
|
|
Usage: "Hex-encoded token ID",
|
2021-04-23 15:42:59 +00:00
|
|
|
}
|
|
|
|
|
2024-08-23 21:07:41 +00:00
|
|
|
balanceFlags := slices.Clone(baseBalanceFlags)
|
2021-04-23 15:42:59 +00:00
|
|
|
balanceFlags = append(balanceFlags, tokenID)
|
|
|
|
balanceFlags = append(balanceFlags, options.RPC...)
|
2024-08-23 21:07:41 +00:00
|
|
|
|
|
|
|
transferFlags := slices.Clone(baseTransferFlags)
|
2021-04-23 16:00:45 +00:00
|
|
|
transferFlags = append(transferFlags, tokenID)
|
|
|
|
transferFlags = append(transferFlags, options.RPC...)
|
2024-07-09 18:24:39 +00:00
|
|
|
return []*cli.Command{
|
2021-04-23 15:42:59 +00:00
|
|
|
{
|
|
|
|
Name: "balance",
|
2024-07-03 12:35:18 +00:00
|
|
|
Usage: "Get address balance",
|
2024-11-02 16:25:10 +00:00
|
|
|
UsageText: "balance [-w wallet] [--wallet-config path] --rpc-endpoint <node> [--timeout <time>] [--address <address>] [--token <hash-or-name>] [--id <token-id>]",
|
|
|
|
Description: `Prints NEP-11 balances for address and assets/IDs specified. One of wallet
|
|
|
|
or address must be specified, passing both is valid too. If a wallet is
|
|
|
|
given without an address all tokens (NFT contracts) for all accounts in
|
2022-08-29 19:39:13 +00:00
|
|
|
the specified wallet are listed with all tokens (actual NFTs) insied. A
|
|
|
|
single account can be chosen with the address option and/or a single NFT
|
|
|
|
contract can be selected with the token option. Further, you can specify a
|
|
|
|
particular NFT ID (hex-encoded) to display (which is mostly useful for
|
|
|
|
divisible NFTs). Tokens can be specified by hash, address, name or symbol.
|
|
|
|
Hashes and addresses always work (as long as they belong to a correct NEP-11
|
|
|
|
contract), while names or symbols are matched against the token data
|
|
|
|
stored in the wallet (see import command) or balance data returned from the
|
|
|
|
server. If the token is not specified directly (with hash/address) and is
|
|
|
|
not found in the wallet then depending on the balances data from the server
|
|
|
|
this command can print no data at all or print multiple tokens for one
|
|
|
|
account (if they use the same names/symbols).
|
|
|
|
`,
|
|
|
|
Action: getNEP11Balance,
|
|
|
|
Flags: balanceFlags,
|
2021-04-23 15:42:59 +00:00
|
|
|
},
|
2021-04-22 15:21:18 +00:00
|
|
|
{
|
|
|
|
Name: "import",
|
2024-07-03 12:35:18 +00:00
|
|
|
Usage: "Import NEP-11 token to a wallet",
|
2024-07-04 22:34:40 +00:00
|
|
|
UsageText: "import -w wallet [--wallet-config path] --rpc-endpoint <node> [--timeout <time>] --token <hash>",
|
2021-04-22 15:21:18 +00:00
|
|
|
Action: importNEP11Token,
|
|
|
|
Flags: importFlags,
|
|
|
|
},
|
2021-04-23 10:37:59 +00:00
|
|
|
{
|
|
|
|
Name: "info",
|
2024-07-03 12:35:18 +00:00
|
|
|
Usage: "Print imported NEP-11 token info",
|
2022-08-05 15:27:24 +00:00
|
|
|
UsageText: "print -w wallet [--wallet-config path] [--token <hash-or-name>]",
|
2021-04-23 10:37:59 +00:00
|
|
|
Action: printNEP11Info,
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
walletPathFlag,
|
2022-06-23 13:50:21 +00:00
|
|
|
walletConfigFlag,
|
2021-04-23 10:37:59 +00:00
|
|
|
tokenFlag,
|
|
|
|
},
|
|
|
|
},
|
2021-04-23 15:08:47 +00:00
|
|
|
{
|
|
|
|
Name: "remove",
|
2024-07-03 12:35:18 +00:00
|
|
|
Usage: "Remove NEP-11 token from the wallet",
|
2022-08-05 15:27:24 +00:00
|
|
|
UsageText: "remove -w wallet [--wallet-config path] --token <hash-or-name>",
|
2021-04-23 15:08:47 +00:00
|
|
|
Action: removeNEP11Token,
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
walletPathFlag,
|
2022-06-23 13:50:21 +00:00
|
|
|
walletConfigFlag,
|
2021-04-23 15:08:47 +00:00
|
|
|
tokenFlag,
|
2022-10-06 19:59:47 +00:00
|
|
|
txctx.ForceFlag,
|
2021-04-23 15:08:47 +00:00
|
|
|
},
|
|
|
|
},
|
2021-04-23 16:00:45 +00:00
|
|
|
{
|
|
|
|
Name: "transfer",
|
2024-07-03 12:35:18 +00:00
|
|
|
Usage: "Transfer NEP-11 tokens",
|
2024-07-04 22:34:40 +00:00
|
|
|
UsageText: "transfer -w wallet [--wallet-config path] --rpc-endpoint <node> [--timeout <time>] --from <addr> --to <addr> --token <hash-or-name> --id <token-id> [--amount string] [--await] [data] [-- <cosigner1:Scope> [<cosigner2> [...]]]",
|
2021-04-23 16:00:45 +00:00
|
|
|
Action: transferNEP11,
|
|
|
|
Flags: transferFlags,
|
2021-11-18 13:37:42 +00:00
|
|
|
Description: `Transfers specified NEP-11 token with optional cosigners list attached to
|
|
|
|
the transfer. Amount should be specified for divisible NEP-11
|
|
|
|
tokens and omitted for non-divisible NEP-11 tokens. See
|
2021-04-23 16:00:45 +00:00
|
|
|
'contract testinvokefunction' documentation for the details
|
|
|
|
about cosigners syntax. If no cosigners are given then the
|
|
|
|
sender with CalledByEntry scope will be used as the only
|
2023-12-28 11:58:38 +00:00
|
|
|
signer. If --await flag is set then the command will wait
|
|
|
|
for the transaction to be included in a block.
|
2021-04-23 16:00:45 +00:00
|
|
|
`,
|
|
|
|
},
|
2021-04-26 14:09:37 +00:00
|
|
|
{
|
|
|
|
Name: "properties",
|
2024-07-03 12:35:18 +00:00
|
|
|
Usage: "Print properties of NEP-11 token",
|
2022-09-08 16:05:32 +00:00
|
|
|
UsageText: "properties --rpc-endpoint <node> [--timeout <time>] --token <hash> --id <token-id> [--historic <block/hash>]",
|
2021-04-26 14:09:37 +00:00
|
|
|
Action: printNEP11Properties,
|
|
|
|
Flags: append([]cli.Flag{
|
|
|
|
tokenAddressFlag,
|
|
|
|
tokenID,
|
2022-09-08 16:05:32 +00:00
|
|
|
options.Historic,
|
2021-04-26 14:09:37 +00:00
|
|
|
}, options.RPC...),
|
|
|
|
},
|
2021-04-27 14:55:01 +00:00
|
|
|
{
|
|
|
|
Name: "ownerOf",
|
2024-07-03 12:35:18 +00:00
|
|
|
Usage: "Print owner of non-divisible NEP-11 token with the specified ID",
|
2022-09-08 16:05:32 +00:00
|
|
|
UsageText: "ownerOf --rpc-endpoint <node> [--timeout <time>] --token <hash> --id <token-id> [--historic <block/hash>]",
|
2022-02-04 16:18:35 +00:00
|
|
|
Action: printNEP11NDOwner,
|
|
|
|
Flags: append([]cli.Flag{
|
|
|
|
tokenAddressFlag,
|
|
|
|
tokenID,
|
2022-09-08 16:05:32 +00:00
|
|
|
options.Historic,
|
2022-02-04 16:18:35 +00:00
|
|
|
}, options.RPC...),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "ownerOfD",
|
2024-07-03 12:35:18 +00:00
|
|
|
Usage: "Print set of owners of divisible NEP-11 token with the specified ID (" + maxIters + " will be printed at max)",
|
2022-09-08 16:05:32 +00:00
|
|
|
UsageText: "ownerOfD --rpc-endpoint <node> [--timeout <time>] --token <hash> --id <token-id> [--historic <block/hash>]",
|
2022-02-04 16:18:35 +00:00
|
|
|
Action: printNEP11DOwner,
|
2021-04-27 14:55:01 +00:00
|
|
|
Flags: append([]cli.Flag{
|
|
|
|
tokenAddressFlag,
|
|
|
|
tokenID,
|
2022-09-08 16:05:32 +00:00
|
|
|
options.Historic,
|
2021-04-27 14:55:01 +00:00
|
|
|
}, options.RPC...),
|
|
|
|
},
|
2021-04-28 14:50:12 +00:00
|
|
|
{
|
|
|
|
Name: "tokensOf",
|
2024-07-03 12:35:18 +00:00
|
|
|
Usage: "Print list of tokens IDs for the specified NFT owner (" + maxIters + " will be printed at max)",
|
2022-09-08 16:05:32 +00:00
|
|
|
UsageText: "tokensOf --rpc-endpoint <node> [--timeout <time>] --token <hash> --address <addr> [--historic <block/hash>]",
|
2021-04-28 14:50:12 +00:00
|
|
|
Action: printNEP11TokensOf,
|
|
|
|
Flags: append([]cli.Flag{
|
|
|
|
tokenAddressFlag,
|
|
|
|
ownerAddressFlag,
|
2022-09-08 16:05:32 +00:00
|
|
|
options.Historic,
|
2021-04-28 14:50:12 +00:00
|
|
|
}, options.RPC...),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "tokens",
|
2024-07-03 12:35:18 +00:00
|
|
|
Usage: "Print list of tokens IDs minted by the specified NFT (optional method; " + maxIters + " will be printed at max)",
|
2022-09-08 16:05:32 +00:00
|
|
|
UsageText: "tokens --rpc-endpoint <node> [--timeout <time>] --token <hash> [--historic <block/hash>]",
|
2021-04-28 14:50:12 +00:00
|
|
|
Action: printNEP11Tokens,
|
|
|
|
Flags: append([]cli.Flag{
|
|
|
|
tokenAddressFlag,
|
2022-09-08 16:05:32 +00:00
|
|
|
options.Historic,
|
2021-04-28 14:50:12 +00:00
|
|
|
}, options.RPC...),
|
|
|
|
},
|
2021-04-22 15:21:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func importNEP11Token(ctx *cli.Context) error {
|
|
|
|
return importNEPToken(ctx, manifest.NEP11StandardName)
|
|
|
|
}
|
2021-04-23 10:37:59 +00:00
|
|
|
|
|
|
|
func printNEP11Info(ctx *cli.Context) error {
|
|
|
|
return printNEPInfo(ctx, manifest.NEP11StandardName)
|
|
|
|
}
|
2021-04-23 15:08:47 +00:00
|
|
|
|
|
|
|
func removeNEP11Token(ctx *cli.Context) error {
|
|
|
|
return removeNEPToken(ctx, manifest.NEP11StandardName)
|
|
|
|
}
|
2021-04-23 15:42:59 +00:00
|
|
|
|
|
|
|
func getNEP11Balance(ctx *cli.Context) error {
|
2022-08-29 19:39:13 +00:00
|
|
|
return getNEPBalance(ctx, manifest.NEP11StandardName, func(ctx *cli.Context, c *rpcclient.Client, addrHash util.Uint160, name string, token *wallet.Token, nftID string) error {
|
|
|
|
balances, err := c.GetNEP11Balances(addrHash)
|
2021-04-23 15:42:59 +00:00
|
|
|
if err != nil {
|
2022-08-29 19:39:13 +00:00
|
|
|
return err
|
2021-04-23 15:42:59 +00:00
|
|
|
}
|
2022-08-29 19:39:13 +00:00
|
|
|
var tokenFound bool
|
|
|
|
for i := range balances.Balances {
|
|
|
|
curToken := tokenFromNEP11Balance(&balances.Balances[i])
|
|
|
|
if tokenMatch(curToken, token, name) {
|
|
|
|
printNFTBalance(ctx, balances.Balances[i], nftID)
|
|
|
|
tokenFound = true
|
|
|
|
}
|
2021-04-23 15:42:59 +00:00
|
|
|
}
|
2022-08-29 19:39:13 +00:00
|
|
|
if name == "" || tokenFound {
|
|
|
|
return nil
|
2021-04-23 15:42:59 +00:00
|
|
|
}
|
2022-08-29 19:39:13 +00:00
|
|
|
if token != nil {
|
|
|
|
// We have an exact token, but there is no balance data for it -> print without NFTs.
|
|
|
|
printNFTBalance(ctx, result.NEP11AssetBalance{
|
|
|
|
Asset: token.Hash,
|
|
|
|
Decimals: int(token.Decimals),
|
|
|
|
Name: token.Name,
|
|
|
|
Symbol: token.Symbol,
|
|
|
|
}, "")
|
2021-04-23 15:42:59 +00:00
|
|
|
} else {
|
2022-08-29 19:39:13 +00:00
|
|
|
// We have no data for this token at all, maybe it's not even correct -> complain.
|
|
|
|
fmt.Fprintf(ctx.App.Writer, "Can't find data for %q token\n", name)
|
2021-04-23 15:42:59 +00:00
|
|
|
}
|
2022-08-29 19:39:13 +00:00
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
2021-04-23 15:42:59 +00:00
|
|
|
|
2022-08-29 19:39:13 +00:00
|
|
|
func printNFTBalance(ctx *cli.Context, balance result.NEP11AssetBalance, nftID string) {
|
|
|
|
fmt.Fprintf(ctx.App.Writer, "%s: %s (%s)\n", balance.Symbol, balance.Name, balance.Asset.StringLE())
|
|
|
|
for _, tok := range balance.Tokens {
|
|
|
|
if len(nftID) > 0 && nftID != tok.ID {
|
|
|
|
continue
|
2021-04-23 15:42:59 +00:00
|
|
|
}
|
2022-08-29 19:39:13 +00:00
|
|
|
fmt.Fprintf(ctx.App.Writer, "\tToken: %s\n", tok.ID)
|
|
|
|
fmt.Fprintf(ctx.App.Writer, "\t\tAmount: %s\n", decimalAmount(tok.Amount, balance.Decimals))
|
|
|
|
fmt.Fprintf(ctx.App.Writer, "\t\tUpdated: %d\n", tok.LastUpdated)
|
2021-04-23 15:42:59 +00:00
|
|
|
}
|
|
|
|
}
|
2021-04-23 16:00:45 +00:00
|
|
|
|
|
|
|
func transferNEP11(ctx *cli.Context) error {
|
|
|
|
return transferNEP(ctx, manifest.NEP11StandardName)
|
|
|
|
}
|
|
|
|
|
2022-02-04 16:18:35 +00:00
|
|
|
func printNEP11NDOwner(ctx *cli.Context) error {
|
|
|
|
return printNEP11Owner(ctx, false)
|
|
|
|
}
|
|
|
|
|
|
|
|
func printNEP11DOwner(ctx *cli.Context) error {
|
|
|
|
return printNEP11Owner(ctx, true)
|
|
|
|
}
|
|
|
|
|
|
|
|
func printNEP11Owner(ctx *cli.Context, divisible bool) error {
|
2021-04-27 14:55:01 +00:00
|
|
|
var err error
|
2022-08-05 10:32:37 +00:00
|
|
|
if err := cmdargs.EnsureNone(ctx); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-04-27 14:55:01 +00:00
|
|
|
tokenHash := ctx.Generic("token").(*flags.Address)
|
|
|
|
tokenID := ctx.String("id")
|
|
|
|
if tokenID == "" {
|
2024-07-09 18:24:39 +00:00
|
|
|
return cli.Exit(errors.New("token ID should be specified"), 1)
|
2021-04-27 14:55:01 +00:00
|
|
|
}
|
2022-02-04 16:18:35 +00:00
|
|
|
tokenIDBytes, err := hex.DecodeString(tokenID)
|
|
|
|
if err != nil {
|
2024-07-09 18:24:39 +00:00
|
|
|
return cli.Exit(fmt.Errorf("invalid tokenID bytes: %w", err), 1)
|
2022-02-04 16:18:35 +00:00
|
|
|
}
|
2021-04-27 14:55:01 +00:00
|
|
|
|
|
|
|
gctx, cancel := options.GetTimeoutContext(ctx)
|
|
|
|
defer cancel()
|
|
|
|
|
2022-09-08 16:05:32 +00:00
|
|
|
_, inv, err := options.GetRPCWithInvoker(gctx, ctx, nil)
|
2021-04-27 14:55:01 +00:00
|
|
|
if err != nil {
|
2022-09-08 16:05:32 +00:00
|
|
|
return err
|
2021-04-27 14:55:01 +00:00
|
|
|
}
|
|
|
|
|
2022-02-04 16:18:35 +00:00
|
|
|
if divisible {
|
2022-09-08 16:05:32 +00:00
|
|
|
n11 := nep11.NewDivisibleReader(inv, tokenHash.Uint160())
|
2022-08-19 07:37:22 +00:00
|
|
|
result, err := n11.OwnerOfExpanded(tokenIDBytes, config.DefaultMaxIteratorResultItems)
|
2022-02-04 16:18:35 +00:00
|
|
|
if err != nil {
|
2024-07-09 18:24:39 +00:00
|
|
|
return cli.Exit(fmt.Sprintf("failed to call NEP-11 divisible `ownerOf` method: %s", err.Error()), 1)
|
2022-02-04 16:18:35 +00:00
|
|
|
}
|
|
|
|
for _, h := range result {
|
|
|
|
fmt.Fprintln(ctx.App.Writer, address.Uint160ToString(h))
|
|
|
|
}
|
|
|
|
} else {
|
2022-09-08 16:05:32 +00:00
|
|
|
n11 := nep11.NewNonDivisibleReader(inv, tokenHash.Uint160())
|
2022-08-19 07:37:22 +00:00
|
|
|
result, err := n11.OwnerOf(tokenIDBytes)
|
2022-02-04 16:18:35 +00:00
|
|
|
if err != nil {
|
2024-07-09 18:24:39 +00:00
|
|
|
return cli.Exit(fmt.Sprintf("failed to call NEP-11 non-divisible `ownerOf` method: %s", err.Error()), 1)
|
2022-02-04 16:18:35 +00:00
|
|
|
}
|
|
|
|
fmt.Fprintln(ctx.App.Writer, address.Uint160ToString(result))
|
2021-04-27 14:55:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2021-04-28 14:50:12 +00:00
|
|
|
|
|
|
|
func printNEP11TokensOf(ctx *cli.Context) error {
|
|
|
|
var err error
|
|
|
|
tokenHash := ctx.Generic("token").(*flags.Address)
|
|
|
|
acc := ctx.Generic("address").(*flags.Address)
|
|
|
|
gctx, cancel := options.GetTimeoutContext(ctx)
|
|
|
|
defer cancel()
|
|
|
|
|
2022-09-08 16:05:32 +00:00
|
|
|
_, inv, err := options.GetRPCWithInvoker(gctx, ctx, nil)
|
2021-04-28 14:50:12 +00:00
|
|
|
if err != nil {
|
2022-09-08 16:05:32 +00:00
|
|
|
return err
|
2021-04-28 14:50:12 +00:00
|
|
|
}
|
|
|
|
|
2022-09-08 16:05:32 +00:00
|
|
|
n11 := nep11.NewBaseReader(inv, tokenHash.Uint160())
|
2022-08-19 07:37:22 +00:00
|
|
|
result, err := n11.TokensOfExpanded(acc.Uint160(), config.DefaultMaxIteratorResultItems)
|
2021-04-28 14:50:12 +00:00
|
|
|
if err != nil {
|
2024-07-09 18:24:39 +00:00
|
|
|
return cli.Exit(fmt.Sprintf("failed to call NEP-11 `tokensOf` method: %s", err.Error()), 1)
|
2021-04-28 14:50:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for i := range result {
|
2022-02-04 16:18:35 +00:00
|
|
|
fmt.Fprintln(ctx.App.Writer, hex.EncodeToString(result[i]))
|
2021-04-28 14:50:12 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func printNEP11Tokens(ctx *cli.Context) error {
|
|
|
|
var err error
|
2022-08-05 10:32:37 +00:00
|
|
|
if err := cmdargs.EnsureNone(ctx); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-04-28 14:50:12 +00:00
|
|
|
tokenHash := ctx.Generic("token").(*flags.Address)
|
|
|
|
gctx, cancel := options.GetTimeoutContext(ctx)
|
|
|
|
defer cancel()
|
|
|
|
|
2022-09-08 16:05:32 +00:00
|
|
|
_, inv, err := options.GetRPCWithInvoker(gctx, ctx, nil)
|
2021-04-28 14:50:12 +00:00
|
|
|
if err != nil {
|
2022-09-08 16:05:32 +00:00
|
|
|
return err
|
2021-04-28 14:50:12 +00:00
|
|
|
}
|
|
|
|
|
2022-09-08 16:05:32 +00:00
|
|
|
n11 := nep11.NewBaseReader(inv, tokenHash.Uint160())
|
2022-08-19 07:37:22 +00:00
|
|
|
result, err := n11.TokensExpanded(config.DefaultMaxIteratorResultItems)
|
2021-04-28 14:50:12 +00:00
|
|
|
if err != nil {
|
2024-07-09 18:24:39 +00:00
|
|
|
return cli.Exit(fmt.Sprintf("failed to call optional NEP-11 `tokens` method: %s", err.Error()), 1)
|
2021-04-28 14:50:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for i := range result {
|
2022-02-04 16:18:35 +00:00
|
|
|
fmt.Fprintln(ctx.App.Writer, hex.EncodeToString(result[i]))
|
2021-04-28 14:50:12 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2021-04-26 14:09:37 +00:00
|
|
|
|
|
|
|
func printNEP11Properties(ctx *cli.Context) error {
|
|
|
|
var err error
|
2022-08-05 10:32:37 +00:00
|
|
|
if err := cmdargs.EnsureNone(ctx); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-04-26 14:09:37 +00:00
|
|
|
tokenHash := ctx.Generic("token").(*flags.Address)
|
|
|
|
tokenID := ctx.String("id")
|
|
|
|
if tokenID == "" {
|
2024-07-09 18:24:39 +00:00
|
|
|
return cli.Exit(errors.New("token ID should be specified"), 1)
|
2021-04-26 14:09:37 +00:00
|
|
|
}
|
2022-02-04 16:18:35 +00:00
|
|
|
tokenIDBytes, err := hex.DecodeString(tokenID)
|
|
|
|
if err != nil {
|
2024-07-09 18:24:39 +00:00
|
|
|
return cli.Exit(fmt.Errorf("invalid tokenID bytes: %w", err), 1)
|
2022-02-04 16:18:35 +00:00
|
|
|
}
|
2021-04-26 14:09:37 +00:00
|
|
|
|
|
|
|
gctx, cancel := options.GetTimeoutContext(ctx)
|
|
|
|
defer cancel()
|
|
|
|
|
2022-09-08 16:05:32 +00:00
|
|
|
_, inv, err := options.GetRPCWithInvoker(gctx, ctx, nil)
|
2021-04-26 14:09:37 +00:00
|
|
|
if err != nil {
|
2022-09-08 16:05:32 +00:00
|
|
|
return err
|
2021-04-26 14:09:37 +00:00
|
|
|
}
|
|
|
|
|
2022-09-08 16:05:32 +00:00
|
|
|
n11 := nep11.NewBaseReader(inv, tokenHash.Uint160())
|
2022-08-19 07:37:22 +00:00
|
|
|
result, err := n11.Properties(tokenIDBytes)
|
2021-04-26 14:09:37 +00:00
|
|
|
if err != nil {
|
2024-07-09 18:24:39 +00:00
|
|
|
return cli.Exit(fmt.Sprintf("failed to call NEP-11 `properties` method: %s", err.Error()), 1)
|
2021-04-26 14:09:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bytes, err := stackitem.ToJSON(result)
|
|
|
|
if err != nil {
|
2024-07-09 18:24:39 +00:00
|
|
|
return cli.Exit(fmt.Sprintf("failed to convert result to JSON: %s", err), 1)
|
2021-04-26 14:09:37 +00:00
|
|
|
}
|
|
|
|
fmt.Fprintln(ctx.App.Writer, string(bytes))
|
|
|
|
return nil
|
|
|
|
}
|