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"
|
|
|
|
"math/big"
|
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-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"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
|
2022-08-19 07:37:22 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/invoker"
|
|
|
|
"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"
|
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"
|
2021-04-22 15:21:18 +00:00
|
|
|
"github.com/urfave/cli"
|
|
|
|
)
|
|
|
|
|
|
|
|
func newNEP11Commands() []cli.Command {
|
2022-08-19 07:37:22 +00:00
|
|
|
maxIters := strconv.Itoa(config.DefaultMaxIteratorResultItems)
|
2021-04-27 14:55:01 +00:00
|
|
|
tokenAddressFlag := flags.AddressFlag{
|
|
|
|
Name: "token",
|
|
|
|
Usage: "Token contract address or hash in LE",
|
|
|
|
}
|
2021-04-28 14:50:12 +00:00
|
|
|
ownerAddressFlag := flags.AddressFlag{
|
|
|
|
Name: "address",
|
|
|
|
Usage: "NFT owner address or hash in LE",
|
|
|
|
}
|
2021-04-23 15:42:59 +00:00
|
|
|
tokenID := cli.StringFlag{
|
|
|
|
Name: "id",
|
2022-02-04 16:18:35 +00:00
|
|
|
Usage: "Hex-encoded token ID",
|
2021-04-23 15:42:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
balanceFlags := make([]cli.Flag, len(baseBalanceFlags))
|
|
|
|
copy(balanceFlags, baseBalanceFlags)
|
|
|
|
balanceFlags = append(balanceFlags, tokenID)
|
|
|
|
balanceFlags = append(balanceFlags, options.RPC...)
|
2021-04-23 16:00:45 +00:00
|
|
|
transferFlags := make([]cli.Flag, len(baseTransferFlags))
|
|
|
|
copy(transferFlags, baseTransferFlags)
|
|
|
|
transferFlags = append(transferFlags, tokenID)
|
|
|
|
transferFlags = append(transferFlags, options.RPC...)
|
2021-04-22 15:21:18 +00:00
|
|
|
return []cli.Command{
|
2021-04-23 15:42:59 +00:00
|
|
|
{
|
|
|
|
Name: "balance",
|
|
|
|
Usage: "get address balance",
|
2022-08-05 15:27:24 +00:00
|
|
|
UsageText: "balance -w wallet [--wallet-config path] --rpc-endpoint <node> [--timeout <time>] [--address <address>] --token <hash-or-name> [--id <token-id>]",
|
2021-04-23 15:42:59 +00:00
|
|
|
Action: getNEP11Balance,
|
|
|
|
Flags: balanceFlags,
|
|
|
|
},
|
2021-04-22 15:21:18 +00:00
|
|
|
{
|
|
|
|
Name: "import",
|
2021-11-18 13:37:42 +00:00
|
|
|
Usage: "import NEP-11 token to a wallet",
|
2022-08-05 15:27:24 +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",
|
2021-11-18 13:37:42 +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",
|
2021-11-18 13:37:42 +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,
|
|
|
|
forceFlag,
|
|
|
|
},
|
|
|
|
},
|
2021-04-23 16:00:45 +00:00
|
|
|
{
|
|
|
|
Name: "transfer",
|
2021-11-18 13:37:42 +00:00
|
|
|
Usage: "transfer NEP-11 tokens",
|
2022-08-05 15:27:24 +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] [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
|
|
|
|
signer.
|
|
|
|
`,
|
|
|
|
},
|
2021-04-26 14:09:37 +00:00
|
|
|
{
|
|
|
|
Name: "properties",
|
2021-11-18 13:37:42 +00:00
|
|
|
Usage: "print properties of NEP-11 token",
|
2021-04-26 14:09:37 +00:00
|
|
|
UsageText: "properties --rpc-endpoint <node> --timeout <time> --token <hash> --id <token-id>",
|
|
|
|
Action: printNEP11Properties,
|
|
|
|
Flags: append([]cli.Flag{
|
|
|
|
tokenAddressFlag,
|
|
|
|
tokenID,
|
|
|
|
}, options.RPC...),
|
|
|
|
},
|
2021-04-27 14:55:01 +00:00
|
|
|
{
|
|
|
|
Name: "ownerOf",
|
2021-11-18 13:37:42 +00:00
|
|
|
Usage: "print owner of non-divisible NEP-11 token with the specified ID",
|
2021-04-27 14:55:01 +00:00
|
|
|
UsageText: "ownerOf --rpc-endpoint <node> --timeout <time> --token <hash> --id <token-id>",
|
2022-02-04 16:18:35 +00:00
|
|
|
Action: printNEP11NDOwner,
|
|
|
|
Flags: append([]cli.Flag{
|
|
|
|
tokenAddressFlag,
|
|
|
|
tokenID,
|
|
|
|
}, options.RPC...),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "ownerOfD",
|
2022-08-19 07:37:22 +00:00
|
|
|
Usage: "print set of owners of divisible NEP-11 token with the specified ID (" + maxIters + " will be printed at max)",
|
2022-02-04 16:18:35 +00:00
|
|
|
UsageText: "ownerOfD --rpc-endpoint <node> --timeout <time> --token <hash> --id <token-id>",
|
|
|
|
Action: printNEP11DOwner,
|
2021-04-27 14:55:01 +00:00
|
|
|
Flags: append([]cli.Flag{
|
|
|
|
tokenAddressFlag,
|
|
|
|
tokenID,
|
|
|
|
}, options.RPC...),
|
|
|
|
},
|
2021-04-28 14:50:12 +00:00
|
|
|
{
|
|
|
|
Name: "tokensOf",
|
2022-08-19 07:37:22 +00:00
|
|
|
Usage: "print list of tokens IDs for the specified NFT owner (" + maxIters + " will be printed at max)",
|
2021-04-28 14:50:12 +00:00
|
|
|
UsageText: "tokensOf --rpc-endpoint <node> --timeout <time> --token <hash> --address <addr>",
|
|
|
|
Action: printNEP11TokensOf,
|
|
|
|
Flags: append([]cli.Flag{
|
|
|
|
tokenAddressFlag,
|
|
|
|
ownerAddressFlag,
|
|
|
|
}, options.RPC...),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "tokens",
|
2022-08-19 07:37:22 +00:00
|
|
|
Usage: "print list of tokens IDs minted by the specified NFT (optional method; " + maxIters + " will be printed at max)",
|
2021-04-28 14:50:12 +00:00
|
|
|
UsageText: "tokens --rpc-endpoint <node> --timeout <time> --token <hash>",
|
|
|
|
Action: printNEP11Tokens,
|
|
|
|
Flags: append([]cli.Flag{
|
|
|
|
tokenAddressFlag,
|
|
|
|
}, 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 {
|
|
|
|
var accounts []*wallet.Account
|
|
|
|
|
2022-08-05 10:32:37 +00:00
|
|
|
if err := cmdargs.EnsureNone(ctx); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-06-23 13:50:21 +00:00
|
|
|
wall, _, err := readWallet(ctx)
|
2021-04-23 15:42:59 +00:00
|
|
|
if err != nil {
|
|
|
|
return cli.NewExitError(fmt.Errorf("bad wallet: %w", err), 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
addrFlag := ctx.Generic("address").(*flags.Address)
|
|
|
|
if addrFlag.IsSet {
|
|
|
|
addrHash := addrFlag.Uint160()
|
|
|
|
acc := wall.GetAccount(addrHash)
|
|
|
|
if acc == nil {
|
|
|
|
return cli.NewExitError(fmt.Errorf("can't find account for the address: %s", address.Uint160ToString(addrHash)), 1)
|
|
|
|
}
|
|
|
|
accounts = append(accounts, acc)
|
|
|
|
} else {
|
|
|
|
if len(wall.Accounts) == 0 {
|
|
|
|
return cli.NewExitError(errors.New("no accounts in the wallet"), 1)
|
|
|
|
}
|
|
|
|
accounts = wall.Accounts
|
|
|
|
}
|
|
|
|
|
|
|
|
gctx, cancel := options.GetTimeoutContext(ctx)
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
c, err := options.GetRPCClient(gctx, ctx)
|
|
|
|
if err != nil {
|
|
|
|
return cli.NewExitError(err, 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
name := ctx.String("token")
|
|
|
|
if name == "" {
|
|
|
|
return cli.NewExitError("token hash or name should be specified", 1)
|
|
|
|
}
|
|
|
|
token, err := getMatchingToken(ctx, wall, name, manifest.NEP11StandardName)
|
|
|
|
if err != nil {
|
|
|
|
tokenHash, err := flags.ParseAddress(name)
|
|
|
|
if err != nil {
|
2021-06-17 08:29:16 +00:00
|
|
|
return cli.NewExitError(fmt.Errorf("can't fetch matching token from RPC-node: %w", err), 1)
|
2021-04-23 15:42:59 +00:00
|
|
|
}
|
|
|
|
token, err = c.NEP11TokenInfo(tokenHash)
|
|
|
|
if err != nil {
|
|
|
|
return cli.NewExitError(err.Error(), 1)
|
|
|
|
}
|
|
|
|
}
|
2022-08-19 07:37:22 +00:00
|
|
|
// Always initialize divisible token to be able to use both balanceOf methods.
|
|
|
|
n11 := nep11.NewDivisibleReader(invoker.New(c, nil), token.Hash)
|
2021-04-23 15:42:59 +00:00
|
|
|
|
|
|
|
tokenID := ctx.String("id")
|
2022-02-04 16:18:35 +00:00
|
|
|
tokenIDBytes, err := hex.DecodeString(tokenID)
|
|
|
|
if err != nil {
|
|
|
|
return cli.NewExitError(fmt.Errorf("invalid tokenID bytes: %w", err), 1)
|
|
|
|
}
|
2021-04-23 15:42:59 +00:00
|
|
|
for k, acc := range accounts {
|
|
|
|
addrHash, err := address.StringToUint160(acc.Address)
|
|
|
|
if err != nil {
|
|
|
|
return cli.NewExitError(fmt.Errorf("invalid account address: %w", err), 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
if k != 0 {
|
|
|
|
fmt.Fprintln(ctx.App.Writer)
|
|
|
|
}
|
|
|
|
fmt.Fprintf(ctx.App.Writer, "Account %s\n", acc.Address)
|
|
|
|
|
2022-08-19 07:37:22 +00:00
|
|
|
var amount *big.Int
|
2022-02-04 16:18:35 +00:00
|
|
|
if len(tokenIDBytes) == 0 {
|
2022-08-19 07:37:22 +00:00
|
|
|
amount, err = n11.BalanceOf(addrHash)
|
2021-04-23 15:42:59 +00:00
|
|
|
} else {
|
2022-08-19 07:37:22 +00:00
|
|
|
amount, err = n11.BalanceOfD(addrHash, tokenIDBytes)
|
2021-04-23 15:42:59 +00:00
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
continue
|
|
|
|
}
|
2022-08-19 07:37:22 +00:00
|
|
|
amountStr := fixedn.ToString(amount, int(token.Decimals))
|
2021-04-23 15:42:59 +00:00
|
|
|
|
|
|
|
format := "%s: %s (%s)\n"
|
|
|
|
formatArgs := []interface{}{token.Symbol, token.Name, token.Hash.StringLE()}
|
2022-02-04 16:18:35 +00:00
|
|
|
if len(tokenIDBytes) != 0 {
|
2021-04-23 15:42:59 +00:00
|
|
|
format = "%s: %s (%s, %s)\n"
|
|
|
|
formatArgs = append(formatArgs, tokenID)
|
|
|
|
}
|
|
|
|
fmt.Fprintf(ctx.App.Writer, format, formatArgs...)
|
|
|
|
fmt.Fprintf(ctx.App.Writer, "\tAmount : %s\n", amountStr)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
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)
|
|
|
|
if !tokenHash.IsSet {
|
|
|
|
return cli.NewExitError("token contract hash was not set", 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
tokenID := ctx.String("id")
|
|
|
|
if tokenID == "" {
|
|
|
|
return cli.NewExitError(errors.New("token ID should be specified"), 1)
|
|
|
|
}
|
2022-02-04 16:18:35 +00:00
|
|
|
tokenIDBytes, err := hex.DecodeString(tokenID)
|
|
|
|
if err != nil {
|
|
|
|
return cli.NewExitError(fmt.Errorf("invalid tokenID bytes: %w", err), 1)
|
|
|
|
}
|
2021-04-27 14:55:01 +00:00
|
|
|
|
|
|
|
gctx, cancel := options.GetTimeoutContext(ctx)
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
c, err := options.GetRPCClient(gctx, ctx)
|
|
|
|
if err != nil {
|
|
|
|
return cli.NewExitError(err, 1)
|
|
|
|
}
|
|
|
|
|
2022-02-04 16:18:35 +00:00
|
|
|
if divisible {
|
2022-08-19 07:37:22 +00:00
|
|
|
n11 := nep11.NewDivisibleReader(invoker.New(c, nil), tokenHash.Uint160())
|
|
|
|
result, err := n11.OwnerOfExpanded(tokenIDBytes, config.DefaultMaxIteratorResultItems)
|
2022-02-04 16:18:35 +00:00
|
|
|
if err != nil {
|
|
|
|
return cli.NewExitError(fmt.Sprintf("failed to call NEP-11 divisible `ownerOf` method: %s", err.Error()), 1)
|
|
|
|
}
|
|
|
|
for _, h := range result {
|
|
|
|
fmt.Fprintln(ctx.App.Writer, address.Uint160ToString(h))
|
|
|
|
}
|
|
|
|
} else {
|
2022-08-19 07:37:22 +00:00
|
|
|
n11 := nep11.NewNonDivisibleReader(invoker.New(c, nil), tokenHash.Uint160())
|
|
|
|
result, err := n11.OwnerOf(tokenIDBytes)
|
2022-02-04 16:18:35 +00:00
|
|
|
if err != nil {
|
|
|
|
return cli.NewExitError(fmt.Sprintf("failed to call NEP-11 non-divisible `ownerOf` method: %s", err.Error()), 1)
|
|
|
|
}
|
|
|
|
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)
|
|
|
|
if !tokenHash.IsSet {
|
|
|
|
return cli.NewExitError("token contract hash was not set", 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
acc := ctx.Generic("address").(*flags.Address)
|
|
|
|
if !acc.IsSet {
|
|
|
|
return cli.NewExitError("owner address flag was not set", 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
gctx, cancel := options.GetTimeoutContext(ctx)
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
c, err := options.GetRPCClient(gctx, ctx)
|
|
|
|
if err != nil {
|
|
|
|
return cli.NewExitError(err, 1)
|
|
|
|
}
|
|
|
|
|
2022-08-19 07:37:22 +00:00
|
|
|
n11 := nep11.NewBaseReader(invoker.New(c, nil), tokenHash.Uint160())
|
|
|
|
result, err := n11.TokensOfExpanded(acc.Uint160(), config.DefaultMaxIteratorResultItems)
|
2021-04-28 14:50:12 +00:00
|
|
|
if err != nil {
|
2021-11-18 13:37:42 +00:00
|
|
|
return cli.NewExitError(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)
|
|
|
|
if !tokenHash.IsSet {
|
|
|
|
return cli.NewExitError("token contract hash was not set", 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
gctx, cancel := options.GetTimeoutContext(ctx)
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
c, err := options.GetRPCClient(gctx, ctx)
|
|
|
|
if err != nil {
|
|
|
|
return cli.NewExitError(err, 1)
|
|
|
|
}
|
|
|
|
|
2022-08-19 07:37:22 +00:00
|
|
|
n11 := nep11.NewBaseReader(invoker.New(c, nil), tokenHash.Uint160())
|
|
|
|
result, err := n11.TokensExpanded(config.DefaultMaxIteratorResultItems)
|
2021-04-28 14:50:12 +00:00
|
|
|
if err != nil {
|
2021-11-18 13:37:42 +00:00
|
|
|
return cli.NewExitError(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)
|
|
|
|
if !tokenHash.IsSet {
|
|
|
|
return cli.NewExitError("token contract hash was not set", 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
tokenID := ctx.String("id")
|
|
|
|
if tokenID == "" {
|
|
|
|
return cli.NewExitError(errors.New("token ID should be specified"), 1)
|
|
|
|
}
|
2022-02-04 16:18:35 +00:00
|
|
|
tokenIDBytes, err := hex.DecodeString(tokenID)
|
|
|
|
if err != nil {
|
|
|
|
return cli.NewExitError(fmt.Errorf("invalid tokenID bytes: %w", err), 1)
|
|
|
|
}
|
2021-04-26 14:09:37 +00:00
|
|
|
|
|
|
|
gctx, cancel := options.GetTimeoutContext(ctx)
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
c, err := options.GetRPCClient(gctx, ctx)
|
|
|
|
if err != nil {
|
|
|
|
return cli.NewExitError(err, 1)
|
|
|
|
}
|
|
|
|
|
2022-08-19 07:37:22 +00:00
|
|
|
n11 := nep11.NewBaseReader(invoker.New(c, nil), tokenHash.Uint160())
|
|
|
|
result, err := n11.Properties(tokenIDBytes)
|
2021-04-26 14:09:37 +00:00
|
|
|
if err != nil {
|
2021-11-18 13:37:42 +00:00
|
|
|
return cli.NewExitError(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 {
|
|
|
|
return cli.NewExitError(fmt.Sprintf("failed to convert result to JSON: %s", err), 1)
|
|
|
|
}
|
|
|
|
fmt.Fprintln(ctx.App.Writer, string(bytes))
|
|
|
|
return nil
|
|
|
|
}
|