From 194933a5cc068746d1d6e3f3e98ffe67bf40b237 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Fri, 19 Aug 2022 10:37:22 +0300 Subject: [PATCH] rpcclient: provide nep11 package for NEP-11 tokens Unfortunately Go doesn't allow to easily reuse readers in full packages, still we can have this wrapper with a little overhead (the alternative is to move specific methods into types of their own, but I'm not sure how it's going to be accepted user-side). --- cli/wallet/nep11.go | 40 +-- pkg/rpcclient/nep11.go | 48 ++++ pkg/rpcclient/nep11/base.go | 247 ++++++++++++++++++ pkg/rpcclient/nep11/base_test.go | 305 +++++++++++++++++++++++ pkg/rpcclient/nep11/divisible.go | 157 ++++++++++++ pkg/rpcclient/nep11/divisible_test.go | 218 ++++++++++++++++ pkg/rpcclient/nep11/nondivisible.go | 39 +++ pkg/rpcclient/nep11/nondivisible_test.go | 49 ++++ pkg/rpcclient/rpc.go | 2 +- pkg/services/rpcsrv/client_test.go | 84 ++++--- 10 files changed, 1144 insertions(+), 45 deletions(-) create mode 100644 pkg/rpcclient/nep11/base.go create mode 100644 pkg/rpcclient/nep11/base_test.go create mode 100644 pkg/rpcclient/nep11/divisible.go create mode 100644 pkg/rpcclient/nep11/divisible_test.go create mode 100644 pkg/rpcclient/nep11/nondivisible.go create mode 100644 pkg/rpcclient/nep11/nondivisible_test.go diff --git a/cli/wallet/nep11.go b/cli/wallet/nep11.go index 82154e056..3b81dfc39 100644 --- a/cli/wallet/nep11.go +++ b/cli/wallet/nep11.go @@ -5,16 +5,20 @@ import ( "errors" "fmt" "math/big" + "strconv" "github.com/nspcc-dev/neo-go/cli/cmdargs" "github.com/nspcc-dev/neo-go/cli/flags" "github.com/nspcc-dev/neo-go/cli/input" "github.com/nspcc-dev/neo-go/cli/options" "github.com/nspcc-dev/neo-go/cli/paramcontext" + "github.com/nspcc-dev/neo-go/pkg/config" "github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/encoding/address" "github.com/nspcc-dev/neo-go/pkg/encoding/fixedn" "github.com/nspcc-dev/neo-go/pkg/rpcclient" + "github.com/nspcc-dev/neo-go/pkg/rpcclient/invoker" + "github.com/nspcc-dev/neo-go/pkg/rpcclient/nep11" "github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest" "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" @@ -23,6 +27,7 @@ import ( ) func newNEP11Commands() []cli.Command { + maxIters := strconv.Itoa(config.DefaultMaxIteratorResultItems) tokenAddressFlag := flags.AddressFlag{ Name: "token", Usage: "Token contract address or hash in LE", @@ -119,7 +124,7 @@ func newNEP11Commands() []cli.Command { }, { Name: "ownerOfD", - Usage: "print set of owners of divisible NEP-11 token with the specified ID (the default MaxIteratorResultItems will be printed at max)", + Usage: "print set of owners of divisible NEP-11 token with the specified ID (" + maxIters + " will be printed at max)", UsageText: "ownerOfD --rpc-endpoint --timeout