From 6b21ad9922ac7333b072f264f14ece5d7cd601c4 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Mon, 3 Apr 2023 13:34:24 +0300 Subject: [PATCH] *: replace `interface{}` with `any` keyword Everywhere including examples, external interop APIs, bindings generators code and in other valuable places. A couple of `interface{}` usages are intentionally left in the CHANGELOG.md, documentation and tests. --- cli/cmdargs/parser.go | 4 +- cli/server/server.go | 2 +- cli/smartcontract/generate_test.go | 10 +- cli/smartcontract/permission.go | 14 +- cli/smartcontract/smart_contract.go | 10 +- cli/smartcontract/smart_contract_test.go | 2 +- cli/smartcontract/testdata/deploy/main.go | 8 +- cli/smartcontract/testdata/deploy/sub/put.go | 2 +- cli/smartcontract/testdata/nameservice/nns.go | 12 +- cli/smartcontract/testdata/nex/nex.go | 12 +- cli/smartcontract/testdata/nonepiter/iter.go | 4 +- .../testdata/structs/rpcbindings.out | 6 +- .../testdata/types/rpcbindings.out | 6 +- cli/smartcontract/testdata/types/types.go | 2 +- cli/smartcontract/testdata/verify.go | 4 +- .../testdata/verifyrpc/verify.go | 6 +- cli/vm/cli.go | 2 +- cli/vm/cli_test.go | 14 +- examples/iterator/iterator.go | 2 +- examples/nft-d/nft.go | 10 +- examples/nft-nd-nns/nns.go | 10 +- examples/nft-nd-nns/nns_test.go | 10 +- examples/nft-nd/nft.go | 6 +- examples/oracle/oracle.go | 2 +- examples/runtime/runtime.go | 4 +- examples/storage/storage.go | 4 +- examples/timer/timer.go | 2 +- examples/token/nep17/nep17.go | 2 +- examples/token/token.go | 2 +- internal/basicchain/basic.go | 6 +- .../testdata/storage/storage_contract.go | 2 +- internal/basicchain/testdata/test_contract.go | 4 +- internal/contracts/oracle_contract/oracle.go | 8 +- internal/fakechain/fakechain.go | 6 +- internal/testserdes/testing.go | 4 +- pkg/compiler/compiler.go | 2 +- pkg/compiler/compiler_test.go | 24 +- pkg/compiler/convert_test.go | 18 +- pkg/compiler/debug.go | 8 +- pkg/compiler/debug_test.go | 2 +- pkg/compiler/for_test.go | 4 +- pkg/compiler/function_call_test.go | 17 +- pkg/compiler/global_test.go | 60 +-- pkg/compiler/interop_test.go | 6 +- pkg/compiler/native_test.go | 2 +- pkg/compiler/nilcheck_test.go | 4 +- pkg/compiler/return_test.go | 2 +- pkg/compiler/syscall_test.go | 2 +- pkg/compiler/testdata/util/equals.go | 2 +- pkg/compiler/vardecl_test.go | 12 +- pkg/compiler/vm_test.go | 12 +- pkg/consensus/consensus.go | 2 +- pkg/consensus/payload.go | 4 +- pkg/core/block/block_test.go | 12 +- pkg/core/block/helper_test.go | 4 +- pkg/core/blockchain.go | 12 +- pkg/core/blockchain_neotest_test.go | 12 +- pkg/core/interop/contract/account_test.go | 10 +- pkg/core/interop/contract/call_test.go | 6 +- pkg/core/interop/crypto/ecdsa_test.go | 2 +- pkg/core/interop/runtime/engine_test.go | 4 +- pkg/core/interop/runtime/ext_test.go | 8 +- pkg/core/interop/storage/interops_test.go | 2 +- pkg/core/mempool/mem_pool.go | 10 +- pkg/core/mempool/mem_pool_test.go | 2 +- pkg/core/mempoolevent/event.go | 2 +- pkg/core/mpt/empty.go | 2 +- pkg/core/mpt/extension.go | 2 +- pkg/core/native/crypto_test.go | 2 +- pkg/core/native/native_test/common_test.go | 2 +- pkg/core/native/native_test/designate_test.go | 4 +- pkg/core/native/native_test/gas_test.go | 4 +- .../native/native_test/management_test.go | 8 +- pkg/core/native/native_test/notary_test.go | 26 +- pkg/core/native/native_test/oracle_test.go | 4 +- pkg/core/native/oracle_types_test.go | 2 +- pkg/core/native/std_test.go | 6 +- pkg/core/transaction/attribute.go | 4 +- pkg/core/transaction/conflicts.go | 2 +- pkg/core/transaction/not_valid_before.go | 2 +- pkg/core/transaction/notary_assisted.go | 2 +- pkg/core/transaction/oracle.go | 2 +- pkg/core/transaction/oracle_test.go | 2 +- pkg/core/transaction/reserved.go | 2 +- pkg/core/transaction/witness_condition.go | 2 +- pkg/crypto/keys/publickey.go | 2 +- pkg/encoding/fixedn/fixed8.go | 4 +- pkg/interop/contract/contract.go | 2 +- pkg/interop/convert/convert.go | 8 +- pkg/interop/doc.go | 1 + pkg/interop/iterator/iterator.go | 2 +- pkg/interop/lib/contract/contract.go | 2 +- pkg/interop/native/gas/gas.go | 2 +- pkg/interop/native/ledger/block.go | 2 +- pkg/interop/native/ledger/ledger.go | 4 +- .../native/ledger/transaction_signer.go | 2 +- pkg/interop/native/management/contract.go | 2 +- pkg/interop/native/management/management.go | 4 +- pkg/interop/native/neo/neo.go | 2 +- pkg/interop/native/oracle/oracle.go | 4 +- pkg/interop/native/std/std.go | 9 +- pkg/interop/neogointernal/call.go | 4 +- pkg/interop/neogointernal/opcode.go | 8 +- pkg/interop/neogointernal/syscall.go | 18 +- pkg/interop/runtime/runtime.go | 8 +- pkg/interop/storage/storage.go | 16 +- pkg/interop/types.go | 20 +- pkg/interop/util/util.go | 4 +- pkg/io/binaryReader.go | 2 +- pkg/io/binaryWriter.go | 2 +- pkg/io/size.go | 2 +- pkg/io/size_test.go | 4 +- pkg/neorpc/result/validate_address.go | 4 +- pkg/neorpc/rpcevent/filter.go | 4 +- pkg/neorpc/rpcevent/filter_test.go | 8 +- pkg/neorpc/types.go | 10 +- pkg/neotest/basic.go | 14 +- pkg/neotest/client.go | 14 +- pkg/network/server.go | 8 +- pkg/rpcclient/actor/actor.go | 4 +- pkg/rpcclient/actor/maker.go | 6 +- pkg/rpcclient/actor/waiter.go | 4 +- pkg/rpcclient/client.go | 4 +- pkg/rpcclient/gas/gas_test.go | 2 +- pkg/rpcclient/helper.go | 2 +- pkg/rpcclient/invoker/invoker.go | 6 +- pkg/rpcclient/local.go | 2 +- pkg/rpcclient/management/management.go | 18 +- pkg/rpcclient/management/management_test.go | 14 +- pkg/rpcclient/neo/neo.go | 10 +- pkg/rpcclient/neo/neo_test.go | 10 +- pkg/rpcclient/nep.go | 2 +- pkg/rpcclient/nep11.go | 6 +- pkg/rpcclient/nep11/base.go | 10 +- pkg/rpcclient/nep11/base_test.go | 6 +- pkg/rpcclient/nep11/divisible.go | 6 +- pkg/rpcclient/nep11/divisible_test.go | 2 +- pkg/rpcclient/nep17.go | 6 +- pkg/rpcclient/nep17/nep17.go | 8 +- pkg/rpcclient/nep17/nep17_test.go | 12 +- pkg/rpcclient/neptoken/base.go | 2 +- pkg/rpcclient/neptoken/base_test.go | 2 +- pkg/rpcclient/nns/contract_test.go | 4 +- pkg/rpcclient/notary/contract.go | 8 +- pkg/rpcclient/notary/contract_test.go | 8 +- pkg/rpcclient/oracle/oracle.go | 8 +- pkg/rpcclient/oracle/oracle_test.go | 8 +- pkg/rpcclient/policy/policy.go | 8 +- pkg/rpcclient/policy/policy_test.go | 8 +- pkg/rpcclient/rolemgmt/roles.go | 8 +- pkg/rpcclient/rolemgmt/roles_test.go | 8 +- pkg/rpcclient/rpc.go | 100 ++--- pkg/rpcclient/rpc_test.go | 408 +++++++++--------- pkg/rpcclient/unwrap/unwrap_test.go | 42 +- pkg/rpcclient/wsclient.go | 74 ++-- .../helpers/rpcbroadcaster/broadcaster.go | 6 +- pkg/services/helpers/rpcbroadcaster/client.go | 6 +- pkg/services/notary/core_test.go | 6 +- pkg/services/oracle/broadcaster/oracle.go | 4 +- pkg/services/oracle/filter.go | 2 +- pkg/services/oracle/jsonpath/jsonpath.go | 44 +- pkg/services/oracle/jsonpath/jsonpath_test.go | 4 +- pkg/services/oracle/oracle_test.go | 8 +- pkg/services/rpcsrv/client_test.go | 2 +- pkg/services/rpcsrv/error.go | 2 +- pkg/services/rpcsrv/params/param.go | 4 +- pkg/services/rpcsrv/params/params.go | 2 +- pkg/services/rpcsrv/params/params_test.go | 4 +- pkg/services/rpcsrv/server.go | 136 +++--- pkg/services/rpcsrv/server_test.go | 254 +++++------ pkg/services/rpcsrv/subscription.go | 4 +- pkg/services/rpcsrv/subscription_test.go | 62 +-- pkg/services/rpcsrv/tokens.go | 6 +- pkg/services/stateroot/service_test.go | 6 +- pkg/smartcontract/binding/generate.go | 8 +- pkg/smartcontract/binding/override.go | 4 +- pkg/smartcontract/builder.go | 4 +- pkg/smartcontract/callflag/call_flags.go | 4 +- pkg/smartcontract/entry.go | 6 +- pkg/smartcontract/manifest/manifest.go | 2 +- pkg/smartcontract/manifest/permission.go | 6 +- pkg/smartcontract/manifest/permission_test.go | 2 +- pkg/smartcontract/param_type.go | 6 +- pkg/smartcontract/param_type_test.go | 2 +- pkg/smartcontract/parameter.go | 12 +- pkg/smartcontract/parameter_test.go | 12 +- pkg/smartcontract/rpcbinding/binding.go | 22 +- pkg/util/uint160.go | 4 +- pkg/vm/emit/emit.go | 6 +- pkg/vm/emit/emit_test.go | 2 +- pkg/vm/exception.go | 2 +- pkg/vm/json_test.go | 2 +- pkg/vm/opcodebench_test.go | 20 +- pkg/vm/stack.go | 6 +- pkg/vm/stackitem/item.go | 30 +- pkg/vm/stackitem/item_test.go | 4 +- pkg/vm/stackitem/json_test.go | 2 +- pkg/vm/vm.go | 6 +- pkg/vm/vm_test.go | 160 +++---- 199 files changed, 1256 insertions(+), 1231 deletions(-) diff --git a/cli/cmdargs/parser.go b/cli/cmdargs/parser.go index b90fa60d7..b26c2ee91 100644 --- a/cli/cmdargs/parser.go +++ b/cli/cmdargs/parser.go @@ -230,9 +230,9 @@ func parseCosigner(c string) (transaction.Signer, error) { } // GetDataFromContext returns data parameter from context args. -func GetDataFromContext(ctx *cli.Context) (int, interface{}, *cli.ExitError) { +func GetDataFromContext(ctx *cli.Context) (int, any, *cli.ExitError) { var ( - data interface{} + data any offset int params []smartcontract.Parameter err error diff --git a/cli/server/server.go b/cli/server/server.go index 2856c4f57..bcea6b115 100644 --- a/cli/server/server.go +++ b/cli/server/server.go @@ -662,7 +662,7 @@ func initBlockChain(cfg config.Config, log *zap.Logger) (*core.Blockchain, stora chain, err := core.NewBlockchain(store, cfg.Blockchain(), log) if err != nil { errText := "could not initialize blockchain: %w" - errArgs := []interface{}{err} + errArgs := []any{err} closeErr := store.Close() if closeErr != nil { errText += "; failed to close the DB: %w" diff --git a/cli/smartcontract/generate_test.go b/cli/smartcontract/generate_test.go index 1b60f830e..ae0ef741f 100644 --- a/cli/smartcontract/generate_test.go +++ b/cli/smartcontract/generate_test.go @@ -187,7 +187,7 @@ func Zum(typev int, typev_ int, funcv int) int { } // JustExecute invokes ` + "`justExecute`" + ` method of contract. -func JustExecute(arr []interface{}) { +func JustExecute(arr []any) { neogointernal.CallWithTokenNoRet(Hash, "justExecute", int(contract.All), arr) } @@ -197,7 +197,7 @@ func GetPublicKey() interop.PublicKey { } // OtherTypes invokes ` + "`otherTypes`" + ` method of contract. -func OtherTypes(ctr interop.Hash160, tx interop.Hash256, sig interop.Signature, data interface{}) bool { +func OtherTypes(ctr interop.Hash160, tx interop.Hash256, sig interop.Signature, data any) bool { return neogointernal.CallWithToken(Hash, "otherTypes", int(contract.All), ctr, tx, sig, data).(bool) } @@ -212,8 +212,8 @@ func GetFromMap(intMap map[string]int, indices []string) []int { } // DoSomething invokes ` + "`doSomething`" + ` method of contract. -func DoSomething(bytes []byte, str string) interface{} { - return neogointernal.CallWithToken(Hash, "doSomething", int(contract.ReadStates), bytes, str).(interface{}) +func DoSomething(bytes []byte, str string) any { + return neogointernal.CallWithToken(Hash, "doSomething", int(contract.ReadStates), bytes, str).(any) } // GetBlockWrapper invokes ` + "`getBlockWrapper`" + ` method of contract. @@ -303,7 +303,7 @@ var Hash = util.Uint160{0x4, 0x8, 0x15, 0x16, 0x23, 0x42, 0x43, 0x44, 0x0, 0x1, // Invoker is used by ContractReader to call various safe methods. type Invoker interface { - Call(contract util.Uint160, operation string, params ...interface{}) (*result.Invoke, error) + Call(contract util.Uint160, operation string, params ...any) (*result.Invoke, error) } // ContractReader implements safe contract methods. diff --git a/cli/smartcontract/permission.go b/cli/smartcontract/permission.go index 0c4608b84..cfb28ad0b 100644 --- a/cli/smartcontract/permission.go +++ b/cli/smartcontract/permission.go @@ -19,7 +19,7 @@ const ( permMethodKey = "methods" ) -func (p permission) MarshalYAML() (interface{}, error) { +func (p permission) MarshalYAML() (any, error) { m := yaml.Node{Kind: yaml.MappingNode} switch p.Contract.Type { case manifest.PermissionWildcard: @@ -36,7 +36,7 @@ func (p permission) MarshalYAML() (interface{}, error) { return nil, fmt.Errorf("invalid permission type: %d", p.Contract.Type) } - var val interface{} = "*" + var val any = "*" if !p.Methods.IsWildcard() { val = p.Methods.Value } @@ -53,8 +53,8 @@ func (p permission) MarshalYAML() (interface{}, error) { return m, nil } -func (p *permission) UnmarshalYAML(unmarshal func(interface{}) error) error { - var m map[string]interface{} +func (p *permission) UnmarshalYAML(unmarshal func(any) error) error { + var m map[string]any if err := unmarshal(&m); err != nil { return err } @@ -66,7 +66,7 @@ func (p *permission) UnmarshalYAML(unmarshal func(interface{}) error) error { return p.fillMethods(m) } -func (p *permission) fillType(m map[string]interface{}) error { +func (p *permission) fillType(m map[string]any) error { vh, ok1 := m[permHashKey] vg, ok2 := m[permGroupKey] switch { @@ -104,7 +104,7 @@ func (p *permission) fillType(m map[string]interface{}) error { return nil } -func (p *permission) fillMethods(m map[string]interface{}) error { +func (p *permission) fillMethods(m map[string]any) error { methods, ok := m[permMethodKey] if !ok { return errors.New("'methods' field is missing from permission") @@ -116,7 +116,7 @@ func (p *permission) fillMethods(m map[string]interface{}) error { p.Methods.Value = nil return nil } - case []interface{}: + case []any: ms := make([]string, len(mt)) for i := range mt { ms[i], ok = mt[i].(string) diff --git a/cli/smartcontract/smart_contract.go b/cli/smartcontract/smart_contract.go index 61d026bc9..818f07ac2 100644 --- a/cli/smartcontract/smart_contract.go +++ b/cli/smartcontract/smart_contract.go @@ -81,7 +81,7 @@ func init() { } // RuntimeNotify sends runtime notification with "Hello world!" name -func RuntimeNotify(args []interface{}) { +func RuntimeNotify(args []any) { runtime.Notify(notificationName, args) }` ) @@ -495,7 +495,7 @@ func invokeInternal(ctx *cli.Context, signAndPush bool) error { err error exitErr *cli.ExitError operation string - params []interface{} + params []any paramsStart = 1 scParams []smartcontract.Parameter cosigners []transaction.Signer @@ -521,7 +521,7 @@ func invokeInternal(ctx *cli.Context, signAndPush bool) error { if err != nil { return cli.NewExitError(err, 1) } - params = make([]interface{}, len(scParams)) + params = make([]any, len(scParams)) for i := range scParams { params[i] = scParams[i] } @@ -548,7 +548,7 @@ func invokeInternal(ctx *cli.Context, signAndPush bool) error { return invokeWithArgs(ctx, acc, w, script, operation, params, cosigners) } -func invokeWithArgs(ctx *cli.Context, acc *wallet.Account, wall *wallet.Wallet, script util.Uint160, operation string, params []interface{}, cosigners []transaction.Signer) error { +func invokeWithArgs(ctx *cli.Context, acc *wallet.Account, wall *wallet.Wallet, script util.Uint160, operation string, params []any, cosigners []transaction.Signer) error { var ( err error signersAccounts []actor.SignerAccount @@ -787,7 +787,7 @@ func contractDeploy(ctx *cli.Context) error { return cli.NewExitError(fmt.Errorf("failed to read manifest file: %w", err), 1) } - var appCallParams = []interface{}{f, manifestBytes} + var appCallParams = []any{f, manifestBytes} signOffset, data, err := cmdargs.ParseParams(ctx.Args(), true) if err != nil { diff --git a/cli/smartcontract/smart_contract_test.go b/cli/smartcontract/smart_contract_test.go index a2b119dfe..cd89b16f6 100644 --- a/cli/smartcontract/smart_contract_test.go +++ b/cli/smartcontract/smart_contract_test.go @@ -51,7 +51,7 @@ func init() { } // RuntimeNotify sends runtime notification with "Hello world!" name -func RuntimeNotify(args []interface{}) { +func RuntimeNotify(args []any) { runtime.Notify(notificationName, args) }`, string(main)) diff --git a/cli/smartcontract/testdata/deploy/main.go b/cli/smartcontract/testdata/deploy/main.go index 42bf4c06f..c45b459e0 100644 --- a/cli/smartcontract/testdata/deploy/main.go +++ b/cli/smartcontract/testdata/deploy/main.go @@ -13,7 +13,7 @@ var key = "key" const mgmtKey = "mgmt" -func _deploy(data interface{}, isUpdate bool) { +func _deploy(data any, isUpdate bool) { var value string ctx := storage.GetContext() @@ -25,7 +25,7 @@ func _deploy(data interface{}, isUpdate bool) { storage.Put(ctx, mgmtKey, sh) if data != nil { - arr := data.([]interface{}) + arr := data.([]any) for i := 0; i < len(arr)-1; i += 2 { storage.Put(ctx, arr[i], arr[i+1]) } @@ -70,12 +70,12 @@ func GetValueWithKey(key string) string { } // TestFind finds items with the specified prefix. -func TestFind(f storage.FindFlags) []interface{} { +func TestFind(f storage.FindFlags) []any { ctx := storage.GetContext() storage.Put(ctx, "findkey1", "value1") storage.Put(ctx, "findkey2", "value2") - var result []interface{} + var result []any iter := storage.Find(ctx, "findkey", f) for iterator.Next(iter) { result = append(result, iterator.Value(iter)) diff --git a/cli/smartcontract/testdata/deploy/sub/put.go b/cli/smartcontract/testdata/deploy/sub/put.go index e21b3cbcf..08f634741 100644 --- a/cli/smartcontract/testdata/deploy/sub/put.go +++ b/cli/smartcontract/testdata/deploy/sub/put.go @@ -4,7 +4,7 @@ import "github.com/nspcc-dev/neo-go/pkg/interop/storage" var Key = "sub" -func _deploy(data interface{}, isUpdate bool) { +func _deploy(data any, isUpdate bool) { ctx := storage.GetContext() value := "sub create" if isUpdate { diff --git a/cli/smartcontract/testdata/nameservice/nns.go b/cli/smartcontract/testdata/nameservice/nns.go index d156d985c..efdfcabfe 100644 --- a/cli/smartcontract/testdata/nameservice/nns.go +++ b/cli/smartcontract/testdata/nameservice/nns.go @@ -27,11 +27,11 @@ type Actor interface { nep11.Actor - MakeCall(contract util.Uint160, method string, params ...interface{}) (*transaction.Transaction, error) + MakeCall(contract util.Uint160, method string, params ...any) (*transaction.Transaction, error) MakeRun(script []byte) (*transaction.Transaction, error) - MakeUnsignedCall(contract util.Uint160, method string, attrs []transaction.Attribute, params ...interface{}) (*transaction.Transaction, error) + MakeUnsignedCall(contract util.Uint160, method string, attrs []transaction.Attribute, params ...any) (*transaction.Transaction, error) MakeUnsignedRun(script []byte, attrs []transaction.Attribute) (*transaction.Transaction, error) - SendCall(contract util.Uint160, method string, params ...interface{}) (util.Uint256, uint32, error) + SendCall(contract util.Uint160, method string, params ...any) (util.Uint256, uint32, error) SendRun(script []byte) (util.Uint256, uint32, error) } @@ -155,14 +155,14 @@ func (c *Contract) AddRootUnsigned(root string) (*transaction.Transaction, error // SetPrice creates a transaction invoking `setPrice` method of the contract. // This transaction is signed and immediately sent to the network. // The values returned are its hash, ValidUntilBlock value and error if any. -func (c *Contract) SetPrice(priceList []interface{}) (util.Uint256, uint32, error) { +func (c *Contract) SetPrice(priceList []any) (util.Uint256, uint32, error) { return c.actor.SendCall(Hash, "setPrice", priceList) } // SetPriceTransaction creates a transaction invoking `setPrice` method of the contract. // This transaction is signed, but not sent to the network, instead it's // returned to the caller. -func (c *Contract) SetPriceTransaction(priceList []interface{}) (*transaction.Transaction, error) { +func (c *Contract) SetPriceTransaction(priceList []any) (*transaction.Transaction, error) { return c.actor.MakeCall(Hash, "setPrice", priceList) } @@ -170,7 +170,7 @@ func (c *Contract) SetPriceTransaction(priceList []interface{}) (*transaction.Tr // This transaction is not signed, it's simply returned to the caller. // Any fields of it that do not affect fees can be changed (ValidUntilBlock, // Nonce), fee values (NetworkFee, SystemFee) can be increased as well. -func (c *Contract) SetPriceUnsigned(priceList []interface{}) (*transaction.Transaction, error) { +func (c *Contract) SetPriceUnsigned(priceList []any) (*transaction.Transaction, error) { return c.actor.MakeUnsignedCall(Hash, "setPrice", nil, priceList) } diff --git a/cli/smartcontract/testdata/nex/nex.go b/cli/smartcontract/testdata/nex/nex.go index 2ad6941db..4a4a46de4 100644 --- a/cli/smartcontract/testdata/nex/nex.go +++ b/cli/smartcontract/testdata/nex/nex.go @@ -24,11 +24,11 @@ type Actor interface { nep17.Actor - MakeCall(contract util.Uint160, method string, params ...interface{}) (*transaction.Transaction, error) + MakeCall(contract util.Uint160, method string, params ...any) (*transaction.Transaction, error) MakeRun(script []byte) (*transaction.Transaction, error) - MakeUnsignedCall(contract util.Uint160, method string, attrs []transaction.Attribute, params ...interface{}) (*transaction.Transaction, error) + MakeUnsignedCall(contract util.Uint160, method string, attrs []transaction.Attribute, params ...any) (*transaction.Transaction, error) MakeUnsignedRun(script []byte, attrs []transaction.Attribute) (*transaction.Transaction, error) - SendCall(contract util.Uint160, method string, params ...interface{}) (util.Uint256, uint32, error) + SendCall(contract util.Uint160, method string, params ...any) (util.Uint256, uint32, error) SendRun(script []byte) (util.Uint256, uint32, error) } @@ -168,14 +168,14 @@ func (c *Contract) MaxSupplyUnsigned() (*transaction.Transaction, error) { // Mint creates a transaction invoking `mint` method of the contract. // This transaction is signed and immediately sent to the network. // The values returned are its hash, ValidUntilBlock value and error if any. -func (c *Contract) Mint(from util.Uint160, to util.Uint160, amount *big.Int, swapId *big.Int, signature []byte, data interface{}) (util.Uint256, uint32, error) { +func (c *Contract) Mint(from util.Uint160, to util.Uint160, amount *big.Int, swapId *big.Int, signature []byte, data any) (util.Uint256, uint32, error) { return c.actor.SendCall(Hash, "mint", from, to, amount, swapId, signature, data) } // MintTransaction creates a transaction invoking `mint` method of the contract. // This transaction is signed, but not sent to the network, instead it's // returned to the caller. -func (c *Contract) MintTransaction(from util.Uint160, to util.Uint160, amount *big.Int, swapId *big.Int, signature []byte, data interface{}) (*transaction.Transaction, error) { +func (c *Contract) MintTransaction(from util.Uint160, to util.Uint160, amount *big.Int, swapId *big.Int, signature []byte, data any) (*transaction.Transaction, error) { return c.actor.MakeCall(Hash, "mint", from, to, amount, swapId, signature, data) } @@ -183,7 +183,7 @@ func (c *Contract) MintTransaction(from util.Uint160, to util.Uint160, amount *b // This transaction is not signed, it's simply returned to the caller. // Any fields of it that do not affect fees can be changed (ValidUntilBlock, // Nonce), fee values (NetworkFee, SystemFee) can be increased as well. -func (c *Contract) MintUnsigned(from util.Uint160, to util.Uint160, amount *big.Int, swapId *big.Int, signature []byte, data interface{}) (*transaction.Transaction, error) { +func (c *Contract) MintUnsigned(from util.Uint160, to util.Uint160, amount *big.Int, swapId *big.Int, signature []byte, data any) (*transaction.Transaction, error) { return c.actor.MakeUnsignedCall(Hash, "mint", nil, from, to, amount, swapId, signature, data) } diff --git a/cli/smartcontract/testdata/nonepiter/iter.go b/cli/smartcontract/testdata/nonepiter/iter.go index c7323fb56..e04f6953c 100644 --- a/cli/smartcontract/testdata/nonepiter/iter.go +++ b/cli/smartcontract/testdata/nonepiter/iter.go @@ -14,8 +14,8 @@ var Hash = util.Uint160{0x33, 0x22, 0x11, 0x0, 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xa // Invoker is used by ContractReader to call various safe methods. type Invoker interface { - Call(contract util.Uint160, operation string, params ...interface{}) (*result.Invoke, error) - CallAndExpandIterator(contract util.Uint160, method string, maxItems int, params ...interface{}) (*result.Invoke, error) + Call(contract util.Uint160, operation string, params ...any) (*result.Invoke, error) + CallAndExpandIterator(contract util.Uint160, method string, maxItems int, params ...any) (*result.Invoke, error) TerminateSession(sessionID uuid.UUID) error TraverseIterator(sessionID uuid.UUID, iterator *result.Iterator, num int) ([]stackitem.Item, error) } diff --git a/cli/smartcontract/testdata/structs/rpcbindings.out b/cli/smartcontract/testdata/structs/rpcbindings.out index a8330072b..cbe2a6e67 100644 --- a/cli/smartcontract/testdata/structs/rpcbindings.out +++ b/cli/smartcontract/testdata/structs/rpcbindings.out @@ -69,7 +69,7 @@ type LedgerTransactionSigner struct { // LedgerWitnessCondition is a contract-specific ledger.WitnessCondition type used by its methods. type LedgerWitnessCondition struct { Type *big.Int - Value interface{} + Value any } // LedgerWitnessRule is a contract-specific ledger.WitnessRule type used by its methods. @@ -114,7 +114,7 @@ type ManagementManifest struct { ABI *ManagementABI Permissions []*ManagementPermission Trusts []util.Uint160 - Extra interface{} + Extra any } // ManagementMethod is a contract-specific management.Method type used by its methods. @@ -156,7 +156,7 @@ type StructsInternal struct { } // Invoker is used by ContractReader to call various safe methods. type Invoker interface { - Call(contract util.Uint160, operation string, params ...interface{}) (*result.Invoke, error) + Call(contract util.Uint160, operation string, params ...any) (*result.Invoke, error) } // ContractReader implements safe contract methods. diff --git a/cli/smartcontract/testdata/types/rpcbindings.out b/cli/smartcontract/testdata/types/rpcbindings.out index 2b419a2ad..e6a14ecea 100644 --- a/cli/smartcontract/testdata/types/rpcbindings.out +++ b/cli/smartcontract/testdata/types/rpcbindings.out @@ -18,7 +18,7 @@ var Hash = util.Uint160{0x33, 0x22, 0x11, 0x0, 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xa // Invoker is used by ContractReader to call various safe methods. type Invoker interface { - Call(contract util.Uint160, operation string, params ...interface{}) (*result.Invoke, error) + Call(contract util.Uint160, operation string, params ...any) (*result.Invoke, error) } // ContractReader implements safe contract methods. @@ -91,8 +91,8 @@ func (c *ContractReader) AAAStrings(s [][][]string) ([][][]string, error) { } // Any invokes `any` method of contract. -func (c *ContractReader) Any(a interface{}) (interface{}, error) { - return func (item stackitem.Item, err error) (interface{}, error) { +func (c *ContractReader) Any(a any) (any, error) { + return func (item stackitem.Item, err error) (any, error) { if err != nil { return nil, err } diff --git a/cli/smartcontract/testdata/types/types.go b/cli/smartcontract/testdata/types/types.go index f59aac0e8..c8d819dd5 100644 --- a/cli/smartcontract/testdata/types/types.go +++ b/cli/smartcontract/testdata/types/types.go @@ -20,7 +20,7 @@ func String(s string) string { return "" } -func Any(a interface{}) interface{} { +func Any(a any) any { return nil } diff --git a/cli/smartcontract/testdata/verify.go b/cli/smartcontract/testdata/verify.go index 3f399c9f6..dabc0ab7a 100644 --- a/cli/smartcontract/testdata/verify.go +++ b/cli/smartcontract/testdata/verify.go @@ -9,12 +9,12 @@ func Verify() bool { return true } -func OnNEP17Payment(from interop.Hash160, amount int, data interface{}) { +func OnNEP17Payment(from interop.Hash160, amount int, data any) { } // OnNEP11Payment notifies about NEP-11 payment. You don't call this method directly, // instead it's called by NEP-11 contract when you transfer funds from your address // to the address of this NFT contract. -func OnNEP11Payment(from interop.Hash160, amount int, token []byte, data interface{}) { +func OnNEP11Payment(from interop.Hash160, amount int, token []byte, data any) { runtime.Notify("OnNEP11Payment", from, amount, token, data) } diff --git a/cli/smartcontract/testdata/verifyrpc/verify.go b/cli/smartcontract/testdata/verifyrpc/verify.go index 8b8f07961..4a9af0156 100644 --- a/cli/smartcontract/testdata/verifyrpc/verify.go +++ b/cli/smartcontract/testdata/verifyrpc/verify.go @@ -12,11 +12,11 @@ var Hash = util.Uint160{0x33, 0x22, 0x11, 0x0, 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xa // Actor is used by Contract to call state-changing methods. type Actor interface { - MakeCall(contract util.Uint160, method string, params ...interface{}) (*transaction.Transaction, error) + MakeCall(contract util.Uint160, method string, params ...any) (*transaction.Transaction, error) MakeRun(script []byte) (*transaction.Transaction, error) - MakeUnsignedCall(contract util.Uint160, method string, attrs []transaction.Attribute, params ...interface{}) (*transaction.Transaction, error) + MakeUnsignedCall(contract util.Uint160, method string, attrs []transaction.Attribute, params ...any) (*transaction.Transaction, error) MakeUnsignedRun(script []byte, attrs []transaction.Attribute) (*transaction.Transaction, error) - SendCall(contract util.Uint160, method string, params ...interface{}) (util.Uint256, uint32, error) + SendCall(contract util.Uint160, method string, params ...any) (util.Uint256, uint32, error) SendRun(script []byte) (util.Uint256, uint32, error) } diff --git a/cli/vm/cli.go b/cli/vm/cli.go index d7a3c07f8..a8c246b66 100644 --- a/cli/vm/cli.go +++ b/cli/vm/cli.go @@ -483,7 +483,7 @@ func NewWithConfig(printLogotype bool, onExit func(int), c *readline.Config, cfg shell: ctl, } - vmcli.shell.Metadata = map[string]interface{}{ + vmcli.shell.Metadata = map[string]any{ chainKey: chain, chainCfgKey: cfg, icKey: ic, diff --git a/cli/vm/cli_test.go b/cli/vm/cli_test.go index bd95b0df7..60f0647c3 100644 --- a/cli/vm/cli_test.go +++ b/cli/vm/cli_test.go @@ -180,9 +180,9 @@ func (e *executor) checkError(t *testing.T, expectedErr error) { require.True(t, strings.HasPrefix(line, expected), fmt.Errorf("expected `%s`, got `%s`", expected, line)) } -func (e *executor) checkStack(t *testing.T, items ...interface{}) { +func (e *executor) checkStack(t *testing.T, items ...any) { d := json.NewDecoder(e.out) - var actual interface{} + var actual any require.NoError(t, d.Decode(&actual)) rawActual, err := json.Marshal(actual) require.NoError(t, err) @@ -210,7 +210,7 @@ func (e *executor) checkEvents(t *testing.T, isKeywordExpected bool, events ...s e.checkNextLine(t, "Events:") } d := json.NewDecoder(e.out) - var actual interface{} + var actual any require.NoError(t, d.Decode(&actual)) rawActual, err := json.Marshal(actual) require.NoError(t, err) @@ -249,9 +249,9 @@ func (e *executor) checkChange(t *testing.T, c storageChange) { } } -func (e *executor) checkSlot(t *testing.T, items ...interface{}) { +func (e *executor) checkSlot(t *testing.T, items ...any) { d := json.NewDecoder(e.out) - var actual interface{} + var actual any require.NoError(t, d.Decode(&actual)) rawActual, err := json.Marshal(actual) require.NoError(t, err) @@ -532,7 +532,7 @@ func TestRunWithDifferentArguments(t *testing.T) { func GetString(arg string) string { return arg } - func GetArr(arg []interface{}) []interface{}{ + func GetArr(arg []any) []any{ return arg }` @@ -933,7 +933,7 @@ func TestEvents(t *testing.T) { script := io.NewBufBinWriter() h, err := e.cli.chain.GetContractScriptHash(2) // examples/runtime/runtime.go require.NoError(t, err) - emit.AppCall(script.BinWriter, h, "notify", callflag.All, []interface{}{true, 5}) + emit.AppCall(script.BinWriter, h, "notify", callflag.All, []any{true, 5}) e.runProg(t, "loadhex "+hex.EncodeToString(script.Bytes()), "run", diff --git a/examples/iterator/iterator.go b/examples/iterator/iterator.go index fe53881b8..f5e91ea37 100644 --- a/examples/iterator/iterator.go +++ b/examples/iterator/iterator.go @@ -7,7 +7,7 @@ import ( ) // _deploy primes contract's storage with some data to be used later. -func _deploy(_ interface{}, _ bool) { +func _deploy(_ any, _ bool) { ctx := storage.GetContext() // RW context. storage.Put(ctx, "foo1", "1") storage.Put(ctx, "foo2", "2") diff --git a/examples/nft-d/nft.go b/examples/nft-d/nft.go index 66afd2ef6..7a1d1e8f0 100644 --- a/examples/nft-d/nft.go +++ b/examples/nft-d/nft.go @@ -172,7 +172,7 @@ func tokensOf(ctx storage.Context, holder interop.Hash160) iterator.Iterator { // Transfer token from its owner to another user, if there's one owner of the token. // It will return false if token is shared between multiple owners. -func Transfer(to interop.Hash160, token []byte, data interface{}) bool { +func Transfer(to interop.Hash160, token []byte, data any) bool { if len(to) != interop.Hash160Len { panic("invalid 'to' address") } @@ -215,7 +215,7 @@ func Transfer(to interop.Hash160, token []byte, data interface{}) bool { } // postTransfer emits Transfer event and calls onNEP11Payment if needed. -func postTransfer(from interop.Hash160, to interop.Hash160, token []byte, amount int, data interface{}) { +func postTransfer(from interop.Hash160, to interop.Hash160, token []byte, amount int, data any) { runtime.Notify("Transfer", from, to, amount, token) if management.GetContract(to) != nil { contract.Call(to, "onNEP11Payment", contract.All, from, amount, token, data) @@ -263,7 +263,7 @@ func isTokenValid(ctx storage.Context, tokenID []byte) bool { // TransferDivisible token from its owner to another user, notice that it only has three // parameters because token owner can be deduced from token ID itself. -func TransferDivisible(from, to interop.Hash160, amount int, token []byte, data interface{}) bool { +func TransferDivisible(from, to interop.Hash160, amount int, token []byte, data any) bool { if len(from) != interop.Hash160Len { panic("invalid 'from' address") } @@ -350,7 +350,7 @@ func removeOwner(ctx storage.Context, token []byte, holder interop.Hash160) { // OnNEP17Payment mints tokens if at least 10 GAS is provided. You don't call // this method directly, instead it's called by GAS contract when you transfer // GAS from your address to the address of this NFT contract. -func OnNEP17Payment(from interop.Hash160, amount int, data interface{}) { +func OnNEP17Payment(from interop.Hash160, amount int, data any) { defer func() { if r := recover(); r != nil { runtime.Log(r.(string)) @@ -364,7 +364,7 @@ func OnNEP17Payment(from interop.Hash160, amount int, data interface{}) { if amount < 10_00000000 { panic("minting NFSO costs at least 10 GAS") } - tokenInfo := data.([]interface{}) + tokenInfo := data.([]any) if len(tokenInfo) != 2 { panic("invalid 'data'") } diff --git a/examples/nft-nd-nns/nns.go b/examples/nft-nd-nns/nns.go index 5a6800d47..b1dacb7a5 100644 --- a/examples/nft-nd-nns/nns.go +++ b/examples/nft-nd-nns/nns.go @@ -79,7 +79,7 @@ func Update(nef []byte, manifest string) { } // _deploy initializes defaults (total supply and registration price) on contract deploy. -func _deploy(data interface{}, isUpdate bool) { +func _deploy(data any, isUpdate bool) { if isUpdate { return } @@ -112,10 +112,10 @@ func OwnerOf(tokenID []byte) interop.Hash160 { } // Properties returns domain name and expiration date of the specified domain. -func Properties(tokenID []byte) map[string]interface{} { +func Properties(tokenID []byte) map[string]any { ctx := storage.GetReadOnlyContext() ns := getNameState(ctx, tokenID) - return map[string]interface{}{ + return map[string]any{ "name": ns.Name, "expiration": ns.Expiration, "admin": ns.Admin, @@ -151,7 +151,7 @@ func TokensOf(owner interop.Hash160) iterator.Iterator { } // Transfer transfers domain with the specified name to new owner. -func Transfer(to interop.Hash160, tokenID []byte, data interface{}) bool { +func Transfer(to interop.Hash160, tokenID []byte, data any) bool { if !isValid(to) { panic(`invalid receiver`) } @@ -398,7 +398,7 @@ func updateBalance(ctx storage.Context, tokenId []byte, acc interop.Hash160, dif // postTransfer sends Transfer notification to the network and calls onNEP11Payment // method. -func postTransfer(from, to interop.Hash160, tokenID []byte, data interface{}) { +func postTransfer(from, to interop.Hash160, tokenID []byte, data any) { runtime.Notify("Transfer", from, to, 1, tokenID) if management.GetContract(to) != nil { contract.Call(to, "onNEP11Payment", contract.All, from, 1, tokenID, data) diff --git a/examples/nft-nd-nns/nns_test.go b/examples/nft-nd-nns/nns_test.go index 9032bb9d2..5d4362105 100644 --- a/examples/nft-nd-nns/nns_test.go +++ b/examples/nft-nd-nns/nns_test.go @@ -190,8 +190,8 @@ func TestRegisterAndRenew(t *testing.T) { t.Run("invalid token ID", func(t *testing.T) { c.InvokeFail(t, "token not found", "properties", "not.exists") c.InvokeFail(t, "token not found", "ownerOf", "not.exists") - c.InvokeFail(t, "invalid conversion", "properties", []interface{}{}) - c.InvokeFail(t, "invalid conversion", "ownerOf", []interface{}{}) + c.InvokeFail(t, "invalid conversion", "properties", []any{}) + c.InvokeFail(t, "invalid conversion", "ownerOf", []any{}) }) // Renew @@ -294,7 +294,7 @@ func TestSetGetRecord(t *testing.T) { {Type: nns.AAAA, Name: "2001::13.1.68.3", ShouldFail: true}, } for _, testCase := range testCases { - args := []interface{}{"neo.com", int64(testCase.Type), testCase.Name} + args := []any{"neo.com", int64(testCase.Type), testCase.Name} t.Run(testCase.Name, func(t *testing.T) { if testCase.ShouldFail { c.InvokeFail(t, "", "setRecord", args...) @@ -377,7 +377,7 @@ func TestTransfer(t *testing.T) { ctr = neotest.CompileSource(t, e.CommitteeHash, strings.NewReader(`package foo import "github.com/nspcc-dev/neo-go/pkg/interop" - func OnNEP11Payment(from interop.Hash160, amount int, token []byte, data interface{}) {}`), + func OnNEP11Payment(from interop.Hash160, amount int, token []byte, data any) {}`), &compiler.Options{Name: "foo"}) e.DeployContract(t, ctr, nil) cTo.Invoke(t, true, "transfer", ctr.Hash, []byte("neo.com"), nil) @@ -404,7 +404,7 @@ func TestTokensOf(t *testing.T) { testTokensOf(t, c, [][]byte{}, util.Uint160{}.BytesBE()) // empty hash is a valid hash still } -func testTokensOf(t *testing.T, c *neotest.ContractInvoker, result [][]byte, args ...interface{}) { +func testTokensOf(t *testing.T, c *neotest.ContractInvoker, result [][]byte, args ...any) { method := "tokensOf" if len(args) == 0 { method = "tokens" diff --git a/examples/nft-nd/nft.go b/examples/nft-nd/nft.go index f4f87b743..d98646d10 100644 --- a/examples/nft-nd/nft.go +++ b/examples/nft-nd/nft.go @@ -173,7 +173,7 @@ func OwnerOf(token []byte) interop.Hash160 { // Transfer token from its owner to another user, notice that it only has three // parameters because token owner can be deduced from token ID itself. -func Transfer(to interop.Hash160, token []byte, data interface{}) bool { +func Transfer(to interop.Hash160, token []byte, data any) bool { if len(to) != 20 { panic("invalid 'to' address") } @@ -199,7 +199,7 @@ func Transfer(to interop.Hash160, token []byte, data interface{}) bool { } // postTransfer emits Transfer event and calls onNEP11Payment if needed. -func postTransfer(from interop.Hash160, to interop.Hash160, token []byte, data interface{}) { +func postTransfer(from interop.Hash160, to interop.Hash160, token []byte, data any) { runtime.Notify("Transfer", from, to, 1, token) if management.GetContract(to) != nil { contract.Call(to, "onNEP11Payment", contract.All, from, 1, token, data) @@ -209,7 +209,7 @@ func postTransfer(from interop.Hash160, to interop.Hash160, token []byte, data i // OnNEP17Payment mints tokens if at least 10 GAS is provided. You don't call // this method directly, instead it's called by GAS contract when you transfer // GAS from your address to the address of this NFT contract. -func OnNEP17Payment(from interop.Hash160, amount int, data interface{}) { +func OnNEP17Payment(from interop.Hash160, amount int, data any) { defer func() { if r := recover(); r != nil { runtime.Log(r.(string)) diff --git a/examples/oracle/oracle.go b/examples/oracle/oracle.go index 62e711454..5c5807351 100644 --- a/examples/oracle/oracle.go +++ b/examples/oracle/oracle.go @@ -23,7 +23,7 @@ func FilteredRequest(url string, filter []byte) { // OracleCallback is called by Oracle native contract when request is finished. // It either throws an error (if the result is not successful) or logs the data // got as a result. -func OracleCallback(url string, data interface{}, code int, res []byte) { +func OracleCallback(url string, data any, code int, res []byte) { // This function shouldn't be called directly, we only expect oracle native // contract to be calling it. callingHash := runtime.GetCallingScriptHash() diff --git a/examples/runtime/runtime.go b/examples/runtime/runtime.go index 9ecdd559d..0fc7df18d 100644 --- a/examples/runtime/runtime.go +++ b/examples/runtime/runtime.go @@ -22,7 +22,7 @@ func init() { // _deploy is called after contract deployment or update, it'll be called // in deployment transaction and if call update method of this contract. -func _deploy(_ interface{}, isUpdate bool) { +func _deploy(_ any, isUpdate bool) { if isUpdate { Log("_deploy method called after contract update") return @@ -46,7 +46,7 @@ func Log(message string) { } // Notify emits an event with the specified data. -func Notify(event interface{}) { +func Notify(event any) { runtime.Notify("Event", event) } diff --git a/examples/storage/storage.go b/examples/storage/storage.go index 7f7c1c267..42416dd82 100644 --- a/examples/storage/storage.go +++ b/examples/storage/storage.go @@ -29,12 +29,12 @@ func PutDefault(value []byte) []byte { } // Get returns the value at the passed key. -func Get(key []byte) interface{} { +func Get(key []byte) any { return storage.Get(ctx, key) } // GetDefault returns the value at the default key. -func GetDefault() interface{} { +func GetDefault() any { return storage.Get(ctx, defaultKey) } diff --git a/examples/timer/timer.go b/examples/timer/timer.go index 3e09d39ba..7898b90e0 100644 --- a/examples/timer/timer.go +++ b/examples/timer/timer.go @@ -25,7 +25,7 @@ func init() { ctx = storage.GetContext() } -func _deploy(_ interface{}, isUpdate bool) { +func _deploy(_ any, isUpdate bool) { if isUpdate { ticksLeft := storage.Get(ctx, ticksKey).(int) + 1 storage.Put(ctx, ticksKey, ticksLeft) diff --git a/examples/token/nep17/nep17.go b/examples/token/nep17/nep17.go index 7d4154766..dc4702d5a 100644 --- a/examples/token/nep17/nep17.go +++ b/examples/token/nep17/nep17.go @@ -46,7 +46,7 @@ func (t Token) BalanceOf(ctx storage.Context, holder []byte) int { } // Transfer token from one user to another -func (t Token) Transfer(ctx storage.Context, from, to interop.Hash160, amount int, data interface{}) bool { +func (t Token) Transfer(ctx storage.Context, from, to interop.Hash160, amount int, data any) bool { amountFrom := t.CanTransfer(ctx, from, to, amount) if amountFrom == -1 { return false diff --git a/examples/token/token.go b/examples/token/token.go index 7cede5d3f..e49970bda 100644 --- a/examples/token/token.go +++ b/examples/token/token.go @@ -53,7 +53,7 @@ func BalanceOf(holder interop.Hash160) int { } // Transfer token from one user to another -func Transfer(from interop.Hash160, to interop.Hash160, amount int, data interface{}) bool { +func Transfer(from interop.Hash160, to interop.Hash160, amount int, data any) bool { return token.Transfer(ctx, from, to, amount, data) } diff --git a/internal/basicchain/basic.go b/internal/basicchain/basic.go index ef9a3d9a4..370986563 100644 --- a/internal/basicchain/basic.go +++ b/internal/basicchain/basic.go @@ -187,7 +187,7 @@ func Init(t *testing.T, rootpath string, e *neotest.Executor) { _, _, _ = deployContractFromPriv0(t, verifyPath, "Verify", verifyCfg, VerifyContractID) // Block #8: deposit some GAS to notary contract for priv0. - transferTxH = gasPriv0Invoker.Invoke(t, true, "transfer", priv0ScriptHash, notaryHash, 10_0000_0000, []interface{}{priv0ScriptHash, int64(e.Chain.BlockHeight() + 1000)}) + transferTxH = gasPriv0Invoker.Invoke(t, true, "transfer", priv0ScriptHash, notaryHash, 10_0000_0000, []any{priv0ScriptHash, int64(e.Chain.BlockHeight() + 1000)}) t.Logf("notaryDepositTxPriv0: %v", transferTxH.StringLE()) // Block #9: designate new Notary node. @@ -195,7 +195,7 @@ func Init(t *testing.T, rootpath string, e *neotest.Executor) { require.NoError(t, err) require.NoError(t, ntr.Accounts[0].Decrypt("one", ntr.Scrypt)) designateSuperInvoker.Invoke(t, stackitem.Null{}, "designateAsRole", - int64(noderoles.P2PNotary), []interface{}{ntr.Accounts[0].PublicKey().Bytes()}) + int64(noderoles.P2PNotary), []any{ntr.Accounts[0].PublicKey().Bytes()}) t.Logf("Designated Notary node: %s", hex.EncodeToString(ntr.Accounts[0].PublicKey().Bytes())) // Block #10: push verification contract with arguments into the chain. @@ -252,7 +252,7 @@ func Init(t *testing.T, rootpath string, e *neotest.Executor) { containerID := util.Uint256{1, 2, 3} objectID := util.Uint256{4, 5, 6} txGas0toNFSH := gasPriv0Invoker.Invoke(t, true, "transfer", - priv0ScriptHash, nfsHash, 10_0000_0000, []interface{}{containerID.BytesBE(), objectID.BytesBE()}) // block #18 + priv0ScriptHash, nfsHash, 10_0000_0000, []any{containerID.BytesBE(), objectID.BytesBE()}) // block #18 res = e.GetTxExecResult(t, txGas0toNFSH) require.Equal(t, 2, len(res.Events)) // GAS transfer + NFSO transfer tokenID, err = res.Events[1].Item.Value().([]stackitem.Item)[3].TryBytes() diff --git a/internal/basicchain/testdata/storage/storage_contract.go b/internal/basicchain/testdata/storage/storage_contract.go index 9cb875c64..f98772b8e 100644 --- a/internal/basicchain/testdata/storage/storage_contract.go +++ b/internal/basicchain/testdata/storage/storage_contract.go @@ -16,7 +16,7 @@ const valuesCount = 255 // valuesPrefix is the prefix values are stored by. var valuesPrefix = []byte{0x01} -func _deploy(data interface{}, isUpdate bool) { +func _deploy(data any, isUpdate bool) { if !isUpdate { ctx := storage.GetContext() for i := 0; i < valuesCount; i++ { diff --git a/internal/basicchain/testdata/test_contract.go b/internal/basicchain/testdata/test_contract.go index e6b98ab57..8807779a0 100644 --- a/internal/basicchain/testdata/test_contract.go +++ b/internal/basicchain/testdata/test_contract.go @@ -27,7 +27,7 @@ func Init() bool { return true } -func OnNEP17Payment(from interop.Hash160, amount int, data interface{}) { +func OnNEP17Payment(from interop.Hash160, amount int, data any) { curr := runtime.GetExecutingScriptHash() balance := neo.BalanceOf(curr) if ledger.CurrentIndex() >= 100 { @@ -47,7 +47,7 @@ func Verify() bool { return true } -func Transfer(from, to interop.Hash160, amount int, data interface{}) bool { +func Transfer(from, to interop.Hash160, amount int, data any) bool { ctx := storage.GetContext() if len(from) != 20 { runtime.Log("invalid 'from' address") diff --git a/internal/contracts/oracle_contract/oracle.go b/internal/contracts/oracle_contract/oracle.go index da7ebe990..94e2b22ac 100644 --- a/internal/contracts/oracle_contract/oracle.go +++ b/internal/contracts/oracle_contract/oracle.go @@ -12,22 +12,22 @@ import ( // RequestURL accepts a complete set of parameters to make an oracle request and // performs it. -func RequestURL(url string, filter []byte, callback string, userData interface{}, gasForResponse int) { +func RequestURL(url string, filter []byte, callback string, userData any, gasForResponse int) { oracle.Request(url, filter, callback, userData, gasForResponse) } // Handle is a response handler that writes response data to the storage. -func Handle(url string, data interface{}, code int, res []byte) { +func Handle(url string, data any, code int, res []byte) { // ABORT if len(data) == 2, some tests use this feature. if data != nil && len(data.(string)) == 2 { util.Abort() } - params := []interface{}{url, data, code, res} + params := []any{url, data, code, res} storage.Put(storage.GetContext(), "lastOracleResponse", std.Serialize(params)) } // HandleRecursive invokes oracle.finish again to test Oracle reentrance. -func HandleRecursive(url string, data interface{}, code int, res []byte) { +func HandleRecursive(url string, data any, code int, res []byte) { // Regular safety check. callingHash := runtime.GetCallingScriptHash() if !callingHash.Equals(oracle.Hash) { diff --git a/internal/fakechain/fakechain.go b/internal/fakechain/fakechain.go index 96296ac45..83f889f10 100644 --- a/internal/fakechain/fakechain.go +++ b/internal/fakechain/fakechain.go @@ -28,7 +28,7 @@ type FakeChain struct { blocksCh []chan *block.Block Blockheight uint32 PoolTxF func(*transaction.Transaction) error - poolTxWithData func(*transaction.Transaction, interface{}, *mempool.Pool) error + poolTxWithData func(*transaction.Transaction, any, *mempool.Pool) error blocks map[util.Uint256]*block.Block hdrHashes map[uint32]util.Uint256 txs map[util.Uint256]*transaction.Transaction @@ -64,7 +64,7 @@ func NewFakeChainWithCustomCfg(protocolCfg func(c *config.Blockchain)) *FakeChai return &FakeChain{ Pool: mempool.New(10, 0, false), PoolTxF: func(*transaction.Transaction) error { return nil }, - poolTxWithData: func(*transaction.Transaction, interface{}, *mempool.Pool) error { return nil }, + poolTxWithData: func(*transaction.Transaction, any, *mempool.Pool) error { return nil }, blocks: make(map[util.Uint256]*block.Block), hdrHashes: make(map[uint32]util.Uint256), txs: make(map[util.Uint256]*transaction.Transaction), @@ -149,7 +149,7 @@ func (chain *FakeChain) GetMaxVerificationGAS() int64 { } // PoolTxWithData implements the Blockchainer interface. -func (chain *FakeChain) PoolTxWithData(t *transaction.Transaction, data interface{}, mp *mempool.Pool, feer mempool.Feer, verificationFunction func(t *transaction.Transaction, data interface{}) error) error { +func (chain *FakeChain) PoolTxWithData(t *transaction.Transaction, data any, mp *mempool.Pool, feer mempool.Feer, verificationFunction func(t *transaction.Transaction, data any) error) error { return chain.poolTxWithData(t, data, mp) } diff --git a/internal/testserdes/testing.go b/internal/testserdes/testing.go index 3cec4801e..87645c176 100644 --- a/internal/testserdes/testing.go +++ b/internal/testserdes/testing.go @@ -12,7 +12,7 @@ import ( // MarshalUnmarshalJSON checks if the expected stays the same after // marshal/unmarshal via JSON. -func MarshalUnmarshalJSON(t *testing.T, expected, actual interface{}) { +func MarshalUnmarshalJSON(t *testing.T, expected, actual any) { data, err := json.Marshal(expected) require.NoError(t, err) require.NoError(t, json.Unmarshal(data, actual)) @@ -21,7 +21,7 @@ func MarshalUnmarshalJSON(t *testing.T, expected, actual interface{}) { // MarshalUnmarshalYAML checks if the expected stays the same after // marshal/unmarshal via YAML. -func MarshalUnmarshalYAML(t *testing.T, expected, actual interface{}) { +func MarshalUnmarshalYAML(t *testing.T, expected, actual any) { data, err := yaml.Marshal(expected) require.NoError(t, err) require.NoError(t, yaml.Unmarshal(data, actual)) diff --git a/pkg/compiler/compiler.go b/pkg/compiler/compiler.go index c8f67e2b3..60a45525c 100644 --- a/pkg/compiler/compiler.go +++ b/pkg/compiler/compiler.go @@ -122,7 +122,7 @@ func (c *codegen) fillImportMap(f *ast.File, pkg *packages.Package) { } } -func getBuildInfo(name string, src interface{}) (*buildInfo, error) { +func getBuildInfo(name string, src any) (*buildInfo, error) { dir, err := filepath.Abs(name) if err != nil { return nil, err diff --git a/pkg/compiler/compiler_test.go b/pkg/compiler/compiler_test.go index 142c33110..8a9ab207a 100644 --- a/pkg/compiler/compiler_test.go +++ b/pkg/compiler/compiler_test.go @@ -102,25 +102,25 @@ func TestOnPayableChecks(t *testing.T) { t.Run("NEP-11, good", func(t *testing.T) { src := `package payable import "github.com/nspcc-dev/neo-go/pkg/interop" - func OnNEP11Payment(from interop.Hash160, amount int, tokenID []byte, data interface{}) {}` + func OnNEP11Payment(from interop.Hash160, amount int, tokenID []byte, data any) {}` require.NoError(t, compileAndCheck(t, src)) }) t.Run("NEP-11, bad", func(t *testing.T) { src := `package payable import "github.com/nspcc-dev/neo-go/pkg/interop" - func OnNEP11Payment(from interop.Hash160, amount int, oldParam string, tokenID []byte, data interface{}) {}` + func OnNEP11Payment(from interop.Hash160, amount int, oldParam string, tokenID []byte, data any) {}` require.Error(t, compileAndCheck(t, src)) }) t.Run("NEP-17, good", func(t *testing.T) { src := `package payable import "github.com/nspcc-dev/neo-go/pkg/interop" - func OnNEP17Payment(from interop.Hash160, amount int, data interface{}) {}` + func OnNEP17Payment(from interop.Hash160, amount int, data any) {}` require.NoError(t, compileAndCheck(t, src)) }) t.Run("NEP-17, bad", func(t *testing.T) { src := `package payable import "github.com/nspcc-dev/neo-go/pkg/interop" - func OnNEP17Payment(from interop.Hash160, amount int, data interface{}, extra int) {}` + func OnNEP17Payment(from interop.Hash160, amount int, data any, extra int) {}` require.Error(t, compileAndCheck(t, src)) }) } @@ -234,7 +234,7 @@ func TestEventWarnings(t *testing.T) { src := `package payable import "github.com/nspcc-dev/neo-go/pkg/interop/runtime" func Main() { - runtime.Notify("Event", []interface{}{1}...) + runtime.Notify("Event", []any{1}...) }` _, di, err := compiler.CompileWithOptions("eventTest.go", strings.NewReader(src), nil) @@ -407,7 +407,7 @@ func TestUnnamedParameterCheck(t *testing.T) { t.Run("interface", func(t *testing.T) { src := ` package testcase - func OnNEP17Payment(h string, i int, _ interface{}){} + func OnNEP17Payment(h string, i int, _ any){} ` _, _, err := compiler.CompileWithOptions("test.go", strings.NewReader(src), nil) require.Error(t, err) @@ -416,7 +416,7 @@ func TestUnnamedParameterCheck(t *testing.T) { t.Run("a set of unnamed params", func(t *testing.T) { src := ` package testcase - func OnNEP17Payment(_ string, _ int, _ interface{}){} + func OnNEP17Payment(_ string, _ int, _ any){} ` _, _, err := compiler.CompileWithOptions("test.go", strings.NewReader(src), nil) require.Error(t, err) @@ -447,11 +447,19 @@ func TestUnnamedParameterCheck(t *testing.T) { _, _, err := compiler.CompileWithOptions("test.go", strings.NewReader(src), nil) require.NoError(t, err) }) + t.Run("good, use any keyword", func(t *testing.T) { + src := ` + package testcase + func OnNEP17Payment(s string, i int, iface any){} + ` + _, _, err := compiler.CompileWithOptions("test.go", strings.NewReader(src), nil) + require.NoError(t, err) + }) t.Run("method with unnamed params", func(t *testing.T) { src := ` package testcase type A int - func (rsv A) OnNEP17Payment(_ string, _ int, iface interface{}){} + func (rsv A) OnNEP17Payment(_ string, _ int, iface any){} ` _, _, err := compiler.CompileWithOptions("test.go", strings.NewReader(src), nil) require.NoError(t, err) // it's OK for exported method to have unnamed params as it won't be included into manifest diff --git a/pkg/compiler/convert_test.go b/pkg/compiler/convert_test.go index eba50b332..0995dc685 100644 --- a/pkg/compiler/convert_test.go +++ b/pkg/compiler/convert_test.go @@ -16,7 +16,7 @@ import ( type convertTestCase struct { returnType string argValue string - result interface{} + result any } func getFunctionName(typ string) string { @@ -85,7 +85,7 @@ func TestTypeAssertion(t *testing.T) { src := `package foo func Main() int { a := []byte{1} - var u interface{} + var u any u = a return u.(int) }` @@ -95,7 +95,7 @@ func TestTypeAssertion(t *testing.T) { src := `package foo func Main() int { a := []byte{1} - var u interface{} + var u any u = a var ret = u.(int) return ret @@ -106,7 +106,7 @@ func TestTypeAssertion(t *testing.T) { src := `package foo func Main() int { a := []byte{1} - var u interface{} + var u any u = a var ret int ret = u.(int) @@ -118,7 +118,7 @@ func TestTypeAssertion(t *testing.T) { src := `package foo func Main() int { a := []byte{1} - var u interface{} + var u any u = a ret := u.(int) return ret @@ -132,7 +132,7 @@ func TestTypeAssertionWithOK(t *testing.T) { src := `package foo func Main() bool { a := 1 - var u interface{} + var u any u = a var _, ok = u.(int) // *ast.GenDecl return ok @@ -145,7 +145,7 @@ func TestTypeAssertionWithOK(t *testing.T) { src := `package foo func Main() bool { a := 1 - var u interface{} + var u any u = a var ok bool _, ok = u.(int) // *ast.AssignStmt @@ -159,7 +159,7 @@ func TestTypeAssertionWithOK(t *testing.T) { src := `package foo func Main() bool { a := 1 - var u interface{} + var u any u = a _, ok := u.(int) // *ast.AssignStmt return ok @@ -231,7 +231,7 @@ func TestInterfaceTypeConversion(t *testing.T) { src := `package foo func Main() int { a := 1 - b := interface{}(a).(int) + b := any(a).(int) return b }` eval(t, src, big.NewInt(1)) diff --git a/pkg/compiler/debug.go b/pkg/compiler/debug.go index 9785de401..82e2e49f7 100644 --- a/pkg/compiler/debug.go +++ b/pkg/compiler/debug.go @@ -308,7 +308,7 @@ func scAndVMInteropTypeFromExpr(named *types.Named, isPointer bool) (smartcontra } return smartcontract.InteropInterfaceType, stackitem.InteropT, - binding.Override{TypeName: "interface{}"}, + binding.Override{TypeName: "any"}, &binding.ExtendedType{Base: smartcontract.InteropInterfaceType, Interface: "iterator"} // Temporarily all interops are iterators. } @@ -318,7 +318,7 @@ func (c *codegen) scAndVMTypeFromExpr(typ ast.Expr, exts map[string]binding.Exte func (c *codegen) scAndVMTypeFromType(t types.Type, exts map[string]binding.ExtendedType) (smartcontract.ParamType, stackitem.Type, binding.Override, *binding.ExtendedType) { if t == nil { - return smartcontract.AnyType, stackitem.AnyT, binding.Override{TypeName: "interface{}"}, nil + return smartcontract.AnyType, stackitem.AnyT, binding.Override{TypeName: "any"}, nil } var isPtr bool @@ -357,7 +357,7 @@ func (c *codegen) scAndVMTypeFromType(t types.Type, exts map[string]binding.Exte over.TypeName = "string" return smartcontract.StringType, stackitem.ByteArrayT, over, nil default: - over.TypeName = "interface{}" + over.TypeName = "any" return smartcontract.AnyType, stackitem.AnyT, over, nil } case *types.Map: @@ -412,7 +412,7 @@ func (c *codegen) scAndVMTypeFromType(t types.Type, exts map[string]binding.Exte } return smartcontract.ArrayType, stackitem.ArrayT, over, et default: - over.TypeName = "interface{}" + over.TypeName = "any" return smartcontract.AnyType, stackitem.AnyT, over, nil } } diff --git a/pkg/compiler/debug_test.go b/pkg/compiler/debug_test.go index dbe382561..4861e29b2 100644 --- a/pkg/compiler/debug_test.go +++ b/pkg/compiler/debug_test.go @@ -65,7 +65,7 @@ func MethodParams(addr interop.Hash160, h interop.Hash256, type MyStruct struct {} func (ms MyStruct) MethodOnStruct() { } func (ms *MyStruct) MethodOnPointerToStruct() { } -func _deploy(data interface{}, isUpdate bool) { x := 1; _ = x } +func _deploy(data any, isUpdate bool) { x := 1; _ = x } ` ne, d, err := CompileWithOptions("foo.go", strings.NewReader(src), nil) diff --git a/pkg/compiler/for_test.go b/pkg/compiler/for_test.go index c7bd36cc1..456678f92 100644 --- a/pkg/compiler/for_test.go +++ b/pkg/compiler/for_test.go @@ -32,7 +32,7 @@ func TestEntryPointWithArgs(t *testing.T) { src := ` package foo - func Main(args []interface{}) int { + func Main(args []any) int { return 2 + args[1].(int) } ` @@ -44,7 +44,7 @@ func TestEntryPointWithMethodAndArgs(t *testing.T) { src := ` package foo - func Main(method string, args []interface{}) int { + func Main(method string, args []any) int { if method == "foobar" { return 2 + args[1].(int) } diff --git a/pkg/compiler/function_call_test.go b/pkg/compiler/function_call_test.go index c409108be..0278c8801 100644 --- a/pkg/compiler/function_call_test.go +++ b/pkg/compiler/function_call_test.go @@ -173,6 +173,21 @@ func TestFunctionCallWithInterfaceType(t *testing.T) { eval(t, src, big.NewInt(10)) } +func TestFunctionCallWithAnyKeywordType(t *testing.T) { + src := ` + package testcase + func Main() any { + x := getSomeInteger(10) + return x + } + + func getSomeInteger(x any) any { + return x + } + ` + eval(t, src, big.NewInt(10)) +} + func TestFunctionCallMultiArg(t *testing.T) { src := ` package testcase @@ -312,7 +327,7 @@ func TestJumpOptimize(t *testing.T) { var a int _ = a } - func _deploy(_ interface{}, upd bool) { + func _deploy(_ any, upd bool) { if true {} else {} t := upd _ = t diff --git a/pkg/compiler/global_test.go b/pkg/compiler/global_test.go index 7b972dd5d..bc0a617c3 100644 --- a/pkg/compiler/global_test.go +++ b/pkg/compiler/global_test.go @@ -137,9 +137,9 @@ func TestUnusedOptimizedGlobalVar(t *testing.T) { func f() int { return 4 }` - eval(t, src, big.NewInt(4), []interface{}{opcode.INITSSLOT, []byte{2}}, // sslot for A and C + eval(t, src, big.NewInt(4), []any{opcode.INITSSLOT, []byte{2}}, // sslot for A and C opcode.PUSH1, opcode.STSFLD0, // store A - []interface{}{opcode.CALL, []byte{10}}, opcode.DROP, // evaluate B and drop + []any{opcode.CALL, []byte{10}}, opcode.DROP, // evaluate B and drop opcode.PUSH3, opcode.STSFLD1, opcode.RET, // store C opcode.LDSFLD0, opcode.LDSFLD1, opcode.ADD, opcode.RET, // Main opcode.PUSH4, opcode.RET) // f @@ -166,7 +166,7 @@ func TestUnusedOptimizedGlobalVar(t *testing.T) { func Main() int { return A }` - eval(t, src, big.NewInt(1), []interface{}{opcode.INITSSLOT, []byte{1}}, // sslot for A + eval(t, src, big.NewInt(1), []any{opcode.INITSSLOT, []byte{1}}, // sslot for A opcode.PUSH1, opcode.STSFLD0, opcode.RET, // store A opcode.LDSFLD0, opcode.RET) // Main }) @@ -176,7 +176,7 @@ func TestUnusedOptimizedGlobalVar(t *testing.T) { func Main() int { return A + B }` - eval(t, src, big.NewInt(4), []interface{}{opcode.INITSSLOT, []byte{2}}, // sslot for A and B + eval(t, src, big.NewInt(4), []any{opcode.INITSSLOT, []byte{2}}, // sslot for A and B opcode.PUSH1, opcode.STSFLD0, // store A opcode.PUSH3, opcode.STSFLD1, opcode.RET, // store B opcode.LDSFLD0, opcode.LDSFLD1, opcode.ADD, opcode.RET) // Main @@ -190,7 +190,7 @@ func TestUnusedOptimizedGlobalVar(t *testing.T) { func Main() int { return A + B + C }` - eval(t, src, big.NewInt(4), []interface{}{opcode.INITSSLOT, []byte{3}}, // sslot for A, B, C + eval(t, src, big.NewInt(4), []any{opcode.INITSSLOT, []byte{3}}, // sslot for A, B, C opcode.PUSH1, opcode.STSFLD0, // store A opcode.PUSH3, opcode.STSFLD1, // store B opcode.PUSH0, opcode.STSFLD2, opcode.RET, // store C @@ -205,9 +205,9 @@ func TestUnusedOptimizedGlobalVar(t *testing.T) { func f() int { return 2 }` - eval(t, src, big.NewInt(1), []interface{}{opcode.INITSSLOT, []byte{1}}, // sslot for A + eval(t, src, big.NewInt(1), []any{opcode.INITSSLOT, []byte{1}}, // sslot for A opcode.PUSH1, opcode.STSFLD0, // store A - []interface{}{opcode.CALL, []byte{6}}, opcode.DROP, opcode.RET, // evaluate Unused1 (call to f) and drop its value + []any{opcode.CALL, []byte{6}}, opcode.DROP, opcode.RET, // evaluate Unused1 (call to f) and drop its value opcode.LDSFLD0, opcode.RET, // Main opcode.PUSH2, opcode.RET) // f }) @@ -221,7 +221,7 @@ func TestUnusedOptimizedGlobalVar(t *testing.T) { func f() int { return 2 }` - eval(t, src, big.NewInt(1), []interface{}{opcode.CALL, []byte{8}}, opcode.PUSH1, opcode.PACKSTRUCT, opcode.DROP, opcode.RET, // evaluate struct val + eval(t, src, big.NewInt(1), []any{opcode.CALL, []byte{8}}, opcode.PUSH1, opcode.PACKSTRUCT, opcode.DROP, opcode.RET, // evaluate struct val opcode.PUSH1, opcode.RET, // Main opcode.PUSH2, opcode.RET) // f }) @@ -319,11 +319,11 @@ func TestUnusedOptimizedGlobalVar(t *testing.T) { func f() int { return 2 }` - eval(t, src, big.NewInt(1), []interface{}{opcode.INITSSLOT, []byte{3}}, // sslot for A + eval(t, src, big.NewInt(1), []any{opcode.INITSSLOT, []byte{3}}, // sslot for A opcode.PUSH1, opcode.STSFLD0, // store A opcode.LDSFLD0, opcode.PUSH1, opcode.ADD, opcode.STSFLD1, // store B opcode.PUSH3, opcode.STSFLD2, // store C - opcode.LDSFLD1, []interface{}{opcode.CALL, []byte{9}}, opcode.ADD, opcode.LDSFLD2, opcode.ADD, opcode.DROP, opcode.RET, // evaluate D and drop + opcode.LDSFLD1, []any{opcode.CALL, []byte{9}}, opcode.ADD, opcode.LDSFLD2, opcode.ADD, opcode.DROP, opcode.RET, // evaluate D and drop opcode.PUSH1, opcode.RET, // Main opcode.PUSH2, opcode.RET) // f }) @@ -337,11 +337,11 @@ func TestUnusedOptimizedGlobalVar(t *testing.T) { func f(a int) int { return a }` - eval(t, src, big.NewInt(1), []interface{}{opcode.INITSSLOT, []byte{1}}, // sslot for A + eval(t, src, big.NewInt(1), []any{opcode.INITSSLOT, []byte{1}}, // sslot for A opcode.PUSH1, opcode.STSFLD0, // store A - opcode.LDSFLD0, []interface{}{opcode.CALL, []byte{6}}, opcode.DROP, opcode.RET, // evaluate B and drop + opcode.LDSFLD0, []any{opcode.CALL, []byte{6}}, opcode.DROP, opcode.RET, // evaluate B and drop opcode.PUSH1, opcode.RET, // Main - []interface{}{opcode.INITSLOT, []byte{0, 1}}, opcode.LDARG0, opcode.RET) // f + []any{opcode.INITSLOT, []byte{0, 1}}, opcode.LDARG0, opcode.RET) // f }) t.Run("named, inside multi-specs and multi-vals var declaration", func(t *testing.T) { src := `package foo @@ -355,7 +355,7 @@ func TestUnusedOptimizedGlobalVar(t *testing.T) { func f() int { return 5 }` - eval(t, src, big.NewInt(1), opcode.PUSH3, []interface{}{opcode.CALL, []byte{7}}, opcode.ADD, opcode.DROP, opcode.RET, // evaluate and drop A + eval(t, src, big.NewInt(1), opcode.PUSH3, []any{opcode.CALL, []byte{7}}, opcode.ADD, opcode.DROP, opcode.RET, // evaluate and drop A opcode.PUSH1, opcode.RET, // Main opcode.PUSH5, opcode.RET) // f }) @@ -367,7 +367,7 @@ func TestUnusedOptimizedGlobalVar(t *testing.T) { func Main() int { return A }` - eval(t, src, big.NewInt(1), []interface{}{opcode.INITSSLOT, []byte{1}}, // sslot for A + eval(t, src, big.NewInt(1), []any{opcode.INITSSLOT, []byte{1}}, // sslot for A opcode.PUSH1, opcode.STSFLD0, opcode.RET, // store A opcode.LDSFLD0, opcode.RET) // Main }) @@ -395,8 +395,8 @@ func TestUnusedOptimizedGlobalVar(t *testing.T) { func f() (int, int) { return 3, 4 }` - eval(t, src, big.NewInt(3), []interface{}{opcode.INITSSLOT, []byte{1}}, // sslot for A - []interface{}{opcode.CALL, []byte{7}}, opcode.STSFLD0, opcode.DROP, opcode.RET, // evaluate and store A, drop B + eval(t, src, big.NewInt(3), []any{opcode.INITSSLOT, []byte{1}}, // sslot for A + []any{opcode.CALL, []byte{7}}, opcode.STSFLD0, opcode.DROP, opcode.RET, // evaluate and store A, drop B opcode.LDSFLD0, opcode.RET, // Main opcode.PUSH4, opcode.PUSH3, opcode.RET) // f }) @@ -460,12 +460,12 @@ func TestUnusedOptimizedGlobalVar(t *testing.T) { func f(a int) int { return a }` - eval(t, src, big.NewInt(1), []interface{}{opcode.INITSSLOT, []byte{2}}, // sslot for A, B + eval(t, src, big.NewInt(1), []any{opcode.INITSSLOT, []byte{2}}, // sslot for A, B opcode.PUSH2, opcode.STSFLD0, // store A opcode.PUSH3, opcode.LDSFLD0, opcode.PUSH1, opcode.PUSH3, opcode.PACK, opcode.PUSH1, opcode.PICKITEM, opcode.STSFLD1, // evaluate B - opcode.PUSH1, []interface{}{opcode.CALL, []byte{8}}, opcode.LDSFLD1, opcode.ADD, opcode.DROP, opcode.RET, // evalute C and drop + opcode.PUSH1, []any{opcode.CALL, []byte{8}}, opcode.LDSFLD1, opcode.ADD, opcode.DROP, opcode.RET, // evalute C and drop opcode.PUSH1, opcode.RET, // Main - []interface{}{opcode.INITSLOT, []byte{0, 1}}, opcode.LDARG0, opcode.RET) // f + []any{opcode.INITSLOT, []byte{0, 1}}, opcode.LDARG0, opcode.RET) // f }) t.Run("index expression", func(t *testing.T) { src := `package foo @@ -477,13 +477,13 @@ func TestUnusedOptimizedGlobalVar(t *testing.T) { func f(a int) int { return a }` - eval(t, src, big.NewInt(1), []interface{}{opcode.INITSSLOT, []byte{1}}, // sslot for Unused + eval(t, src, big.NewInt(1), []any{opcode.INITSSLOT, []byte{1}}, // sslot for Unused opcode.PUSH2, opcode.STSFLD0, // store Unused - opcode.PUSH1, []interface{}{opcode.CALL, []byte{14}}, // call f(1) + opcode.PUSH1, []any{opcode.CALL, []byte{14}}, // call f(1) opcode.PUSH3, opcode.PUSH2, opcode.PUSH1, opcode.PUSH3, opcode.PACK, opcode.LDSFLD0, opcode.PICKITEM, // eval index expression opcode.ADD, opcode.DROP, opcode.RET, // eval and drop A opcode.PUSH1, opcode.RET, // Main - []interface{}{opcode.INITSLOT, []byte{0, 1}}, opcode.LDARG0, opcode.RET) // f(a) + []any{opcode.INITSLOT, []byte{0, 1}}, opcode.LDARG0, opcode.RET) // f(a) }) t.Run("used via nested function calls", func(t *testing.T) { src := `package foo @@ -497,10 +497,10 @@ func TestUnusedOptimizedGlobalVar(t *testing.T) { func g() int { return A }` - eval(t, src, big.NewInt(1), []interface{}{opcode.INITSSLOT, []byte{1}}, // sslot for A + eval(t, src, big.NewInt(1), []any{opcode.INITSSLOT, []byte{1}}, // sslot for A opcode.PUSH1, opcode.STSFLD0, opcode.RET, // store A - []interface{}{opcode.CALL, []byte{3}}, opcode.RET, // Main - []interface{}{opcode.CALL, []byte{3}}, opcode.RET, // f + []any{opcode.CALL, []byte{3}}, opcode.RET, // Main + []any{opcode.CALL, []byte{3}}, opcode.RET, // f opcode.LDSFLD0, opcode.RET) // g }) t.Run("struct field name matches global var name", func(t *testing.T) { @@ -511,7 +511,7 @@ func TestUnusedOptimizedGlobalVar(t *testing.T) { func Main() int { return str.Int }` - eval(t, src, big.NewInt(2), []interface{}{opcode.INITSSLOT, []byte{1}}, // sslot for str + eval(t, src, big.NewInt(2), []any{opcode.INITSSLOT, []byte{1}}, // sslot for str opcode.PUSH2, opcode.PUSH1, opcode.PACKSTRUCT, opcode.STSFLD0, opcode.RET, // store str opcode.LDSFLD0, opcode.PUSH0, opcode.PICKITEM, opcode.RET) // Main }) @@ -929,11 +929,11 @@ func TestUnderscoreGlobalVarDontEmitCode(t *testing.T) { func f(a, b int) (int, int, int) { return 8, 9, 10 }` - eval(t, src, big.NewInt(1), []interface{}{opcode.INITSSLOT, []byte{2}}, // sslot for A, B + eval(t, src, big.NewInt(1), []any{opcode.INITSSLOT, []byte{2}}, // sslot for A, B opcode.PUSH2, opcode.STSFLD0, // store A opcode.PUSH5, opcode.STSFLD1, // store B - opcode.LDSFLD0, opcode.LDSFLD1, opcode.SWAP, []interface{}{opcode.CALL, []byte{8}}, // evaluate f(A,B) + opcode.LDSFLD0, opcode.LDSFLD1, opcode.SWAP, []any{opcode.CALL, []byte{8}}, // evaluate f(A,B) opcode.DROP, opcode.DROP, opcode.DROP, opcode.RET, // drop result of f(A,B) opcode.PUSH1, opcode.RET, // Main - []interface{}{opcode.INITSLOT, []byte{0, 2}}, opcode.PUSH10, opcode.PUSH9, opcode.PUSH8, opcode.RET) // f + []any{opcode.INITSLOT, []byte{0, 2}}, opcode.PUSH10, opcode.PUSH9, opcode.PUSH8, opcode.RET) // f } diff --git a/pkg/compiler/interop_test.go b/pkg/compiler/interop_test.go index 2ba7a5f2f..7e6fc9bd3 100644 --- a/pkg/compiler/interop_test.go +++ b/pkg/compiler/interop_test.go @@ -39,7 +39,7 @@ func TestTypeConstantSize(t *testing.T) { src := `package foo import "github.com/nspcc-dev/neo-go/pkg/interop" var a %T // type declaration is always ok - func Main() interface{} { + func Main() any { return %#v }` @@ -532,7 +532,7 @@ func TestCallWithVersion(t *testing.T) { "github.com/nspcc-dev/neo-go/pkg/interop/contract" util "github.com/nspcc-dev/neo-go/pkg/interop/lib/contract" ) - func CallWithVersion(hash interop.Hash160, version int, method string) interface{} { + func CallWithVersion(hash interop.Hash160, version int, method string) any { return util.CallWithVersion(hash, version, method, contract.All) }` ctr := neotest.CompileSource(t, e.CommitteeHash, strings.NewReader(src), &compiler.Options{Name: "Helper"}) @@ -569,7 +569,7 @@ func TestForcedNotifyArgumentsConversion(t *testing.T) { runtime.Notify("withoutEllipsis", arg0, arg1, arg2, arg3, arg4, 5, f(6)) // The fifth argument is basic literal. } func WithEllipsis() { - arg := []interface{}{0, 1, f(2), 3, 4, 5, 6} + arg := []any{0, 1, f(2), 3, 4, 5, 6} runtime.Notify("withEllipsis", arg...) } func f(i int) int { diff --git a/pkg/compiler/native_test.go b/pkg/compiler/native_test.go index 06db9f919..088d714b8 100644 --- a/pkg/compiler/native_test.go +++ b/pkg/compiler/native_test.go @@ -295,7 +295,7 @@ func addNativeTestCase(t *testing.T, srcBuilder *bytes.Buffer, ctr interop.Contr isVoid := md.MD.ReturnType == smartcontract.VoidType srcBuilder.WriteString("func F" + strconv.Itoa(i) + "() ") if !isVoid { - srcBuilder.WriteString("interface{} { return ") + srcBuilder.WriteString("any { return ") } else { srcBuilder.WriteString("{ ") } diff --git a/pkg/compiler/nilcheck_test.go b/pkg/compiler/nilcheck_test.go index 54f36e037..415a8f294 100644 --- a/pkg/compiler/nilcheck_test.go +++ b/pkg/compiler/nilcheck_test.go @@ -11,7 +11,7 @@ var nilTestCases = []testCase{ ` package foo func Main() int { - var t interface{} + var t any if t == nil { return 1 } @@ -39,7 +39,7 @@ var nilTestCases = []testCase{ ` package foo func Main() int { - var t interface{} + var t any if nil == t { return 1 } diff --git a/pkg/compiler/return_test.go b/pkg/compiler/return_test.go index ead69d2fb..437f7cd9b 100644 --- a/pkg/compiler/return_test.go +++ b/pkg/compiler/return_test.go @@ -124,7 +124,7 @@ func TestTypeAssertReturn(t *testing.T) { src := ` package main - func foo() interface{} { + func foo() any { return 5 } diff --git a/pkg/compiler/syscall_test.go b/pkg/compiler/syscall_test.go index ed0e655d6..fc56d6d0a 100644 --- a/pkg/compiler/syscall_test.go +++ b/pkg/compiler/syscall_test.go @@ -121,7 +121,7 @@ func TestSyscallExecution(t *testing.T) { if tc.isVoid { tmpl = "func %s() { %s(%s) }\n" } else { - tmpl = "func %s() interface{} { return %s(%s) }\n" + tmpl = "func %s() any { return %s(%s) }\n" } srcBuilder.WriteString(fmt.Sprintf(tmpl, realName, goName, strings.Join(tc.params, ", "))) } diff --git a/pkg/compiler/testdata/util/equals.go b/pkg/compiler/testdata/util/equals.go index 391fb74db..33f4b2e7a 100644 --- a/pkg/compiler/testdata/util/equals.go +++ b/pkg/compiler/testdata/util/equals.go @@ -1,6 +1,6 @@ package util // Equals is a mirror of `Equals` builtin. -func Equals(a, b interface{}) bool { +func Equals(a, b any) bool { return true } diff --git a/pkg/compiler/vardecl_test.go b/pkg/compiler/vardecl_test.go index 3759582b3..954b7a5ed 100644 --- a/pkg/compiler/vardecl_test.go +++ b/pkg/compiler/vardecl_test.go @@ -59,18 +59,18 @@ func TestUnderscoreLocalVarDontEmitCode(t *testing.T) { func (fo Foo) GetInt() int { return fo.Int }` - eval(t, src, big.NewInt(9), []interface{}{opcode.INITSLOT, []byte{5, 0}}, // local slot for A, B, C, D, fo + eval(t, src, big.NewInt(9), []any{opcode.INITSLOT, []byte{5, 0}}, // local slot for A, B, C, D, fo opcode.PUSH2, opcode.STLOC0, // store A opcode.PUSH5, opcode.STLOC1, // store B - opcode.LDLOC0, opcode.LDLOC1, opcode.SWAP, []interface{}{opcode.CALL, []byte{27}}, // evaluate f() first time + opcode.LDLOC0, opcode.LDLOC1, opcode.SWAP, []any{opcode.CALL, []byte{27}}, // evaluate f() first time opcode.DROP, opcode.DROP, opcode.DROP, // drop all values from f - opcode.LDLOC0, opcode.LDLOC1, opcode.SWAP, []interface{}{opcode.CALL, []byte{19}}, // evaluate f() second time + opcode.LDLOC0, opcode.LDLOC1, opcode.SWAP, []any{opcode.CALL, []byte{19}}, // evaluate f() second time opcode.DROP, opcode.STLOC2, opcode.DROP, // store C opcode.PUSH7, opcode.STLOC3, // store D opcode.LDLOC3, opcode.DROP, // empty assignment opcode.PUSH3, opcode.PUSH1, opcode.PACKSTRUCT, opcode.STLOC4, // fo decl - opcode.LDLOC4, []interface{}{opcode.CALL, []byte{12}}, opcode.DROP, // fo.GetInt() + opcode.LDLOC4, []any{opcode.CALL, []byte{12}}, opcode.DROP, // fo.GetInt() opcode.LDLOC2, opcode.RET, // return C - []interface{}{opcode.INITSLOT, []byte{0, 2}}, opcode.PUSH10, opcode.PUSH9, opcode.PUSH8, opcode.RET, // f - []interface{}{opcode.INITSLOT, []byte{0, 1}}, opcode.LDARG0, opcode.PUSH0, opcode.PICKITEM, opcode.RET) // (fo Foo) GetInt() int + []any{opcode.INITSLOT, []byte{0, 2}}, opcode.PUSH10, opcode.PUSH9, opcode.PUSH8, opcode.RET, // f + []any{opcode.INITSLOT, []byte{0, 1}}, opcode.LDARG0, opcode.PUSH0, opcode.PICKITEM, opcode.RET) // (fo Foo) GetInt() int } diff --git a/pkg/compiler/vm_test.go b/pkg/compiler/vm_test.go index 58a4cda57..4ec7196a5 100644 --- a/pkg/compiler/vm_test.go +++ b/pkg/compiler/vm_test.go @@ -23,7 +23,7 @@ import ( type testCase struct { name string src string - result interface{} + result any } // testMainIdent is a method invoked in tests by default. @@ -35,7 +35,7 @@ func runTestCases(t *testing.T, tcases []testCase) { } } -func eval(t *testing.T, src string, result interface{}, expectedOps ...interface{}) []byte { +func eval(t *testing.T, src string, result any, expectedOps ...any) []byte { vm, _, script := vmAndCompileInterop(t, src) if len(expectedOps) != 0 { expected := io.NewBufBinWriter() @@ -43,7 +43,7 @@ func eval(t *testing.T, src string, result interface{}, expectedOps ...interface switch typ := op.(type) { case opcode.Opcode: emit.Opcodes(expected.BinWriter, typ) - case []interface{}: + case []any: emit.Instruction(expected.BinWriter, typ[0].(opcode.Opcode), typ[1].([]byte)) default: t.Fatalf("unexpected evaluation operation: %v", typ) @@ -64,14 +64,14 @@ func evalWithError(t *testing.T, src string, e string) []byte { return prog } -func runAndCheck(t *testing.T, v *vm.VM, result interface{}) { +func runAndCheck(t *testing.T, v *vm.VM, result any) { err := v.Run() require.NoError(t, err) assert.Equal(t, 1, v.Estack().Len(), "stack contains unexpected items") assertResult(t, v, result) } -func evalWithArgs(t *testing.T, src string, op []byte, args []stackitem.Item, result interface{}) { +func evalWithArgs(t *testing.T, src string, op []byte, args []stackitem.Item, result any) { vm := vmAndCompile(t, src) if len(args) > 0 { vm.Estack().PushVal(args) @@ -82,7 +82,7 @@ func evalWithArgs(t *testing.T, src string, op []byte, args []stackitem.Item, re runAndCheck(t, vm, result) } -func assertResult(t *testing.T, vm *vm.VM, result interface{}) { +func assertResult(t *testing.T, vm *vm.VM, result any) { assert.Equal(t, result, vm.PopResult()) assert.Nil(t, vm.Context()) } diff --git a/pkg/consensus/consensus.go b/pkg/consensus/consensus.go index 915b51629..777f5d341 100644 --- a/pkg/consensus/consensus.go +++ b/pkg/consensus/consensus.go @@ -238,7 +238,7 @@ func NewPayload(m netmode.Magic, stateRootEnabled bool) *Payload { } } -func (s *service) newPayload(c *dbft.Context, t payload.MessageType, msg interface{}) payload.ConsensusPayload { +func (s *service) newPayload(c *dbft.Context, t payload.MessageType, msg any) payload.ConsensusPayload { cp := NewPayload(s.ProtocolConfiguration.Magic, s.ProtocolConfiguration.StateRootInHeader) cp.SetHeight(c.BlockIndex) cp.SetValidatorIndex(uint16(c.MyIndex)) diff --git a/pkg/consensus/payload.go b/pkg/consensus/payload.go index d9290c49f..aa100cf8c 100644 --- a/pkg/consensus/payload.go +++ b/pkg/consensus/payload.go @@ -65,12 +65,12 @@ func (p *Payload) SetType(t payload.MessageType) { } // Payload implements the payload.ConsensusPayload interface. -func (p Payload) Payload() interface{} { +func (p Payload) Payload() any { return p.payload } // SetPayload implements the payload.ConsensusPayload interface. -func (p *Payload) SetPayload(pl interface{}) { +func (p *Payload) SetPayload(pl any) { p.payload = pl.(io.Serializable) } diff --git a/pkg/core/block/block_test.go b/pkg/core/block/block_test.go index 0123e4819..90d434627 100644 --- a/pkg/core/block/block_test.go +++ b/pkg/core/block/block_test.go @@ -19,7 +19,7 @@ import ( "github.com/stretchr/testify/require" ) -func trim0x(value interface{}) string { +func trim0x(value any) string { s := value.(string) return strings.TrimPrefix(s, "0x") } @@ -42,15 +42,15 @@ func TestDecodeBlock1(t *testing.T) { assert.Equal(t, trim0x(data["merkleroot"]), block.MerkleRoot.StringLE()) assert.Equal(t, trim0x(data["nextconsensus"]), address.Uint160ToString(block.NextConsensus)) - scripts := data["witnesses"].([]interface{}) - script := scripts[0].(map[string]interface{}) + scripts := data["witnesses"].([]any) + script := scripts[0].(map[string]any) assert.Equal(t, script["invocation"].(string), base64.StdEncoding.EncodeToString(block.Script.InvocationScript)) assert.Equal(t, script["verification"].(string), base64.StdEncoding.EncodeToString(block.Script.VerificationScript)) - tx := data["tx"].([]interface{}) - tx0 := tx[0].(map[string]interface{}) + tx := data["tx"].([]any) + tx0 := tx[0].(map[string]any) assert.Equal(t, len(tx), len(block.Transactions)) - assert.Equal(t, len(tx0["attributes"].([]interface{})), len(block.Transactions[0].Attributes)) + assert.Equal(t, len(tx0["attributes"].([]any)), len(block.Transactions[0].Attributes)) } func TestTrimmedBlock(t *testing.T) { diff --git a/pkg/core/block/helper_test.go b/pkg/core/block/helper_test.go index 85be4903b..db61d299f 100644 --- a/pkg/core/block/helper_test.go +++ b/pkg/core/block/helper_test.go @@ -24,12 +24,12 @@ func getDecodedBlock(t *testing.T, i int) *Block { return block } -func getBlockData(i int) (map[string]interface{}, error) { +func getBlockData(i int) (map[string]any, error) { b, err := os.ReadFile(fmt.Sprintf("../test_data/block_%d.json", i)) if err != nil { return nil, err } - var data map[string]interface{} + var data map[string]any if err := json.Unmarshal(b, &data); err != nil { return nil, err } diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index 2c28c06a3..bde36a856 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -183,8 +183,8 @@ type Blockchain struct { // Notification subsystem. events chan bcEvent - subCh chan interface{} - unsubCh chan interface{} + subCh chan any + unsubCh chan any } // StateRoot represents local state root module. @@ -312,8 +312,8 @@ func NewBlockchain(s storage.Store, cfg config.Blockchain, log *zap.Logger) (*Bl memPool: mempool.New(cfg.MemPoolSize, 0, false), log: log, events: make(chan bcEvent), - subCh: make(chan interface{}), - unsubCh: make(chan interface{}), + subCh: make(chan any), + unsubCh: make(chan any), contracts: *native.NewContracts(cfg.ProtocolConfiguration), } @@ -2334,7 +2334,7 @@ var ( // verifyAndPoolTx verifies whether a transaction is bonafide or not and tries // to add it to the mempool given. -func (bc *Blockchain) verifyAndPoolTx(t *transaction.Transaction, pool *mempool.Pool, feer mempool.Feer, data ...interface{}) error { +func (bc *Blockchain) verifyAndPoolTx(t *transaction.Transaction, pool *mempool.Pool, feer mempool.Feer, data ...any) error { // This code can technically be moved out of here, because it doesn't // really require a chain lock. err := vm.IsScriptCorrect(t.Script, nil) @@ -2552,7 +2552,7 @@ func (bc *Blockchain) PoolTx(t *transaction.Transaction, pools ...*mempool.Pool) } // PoolTxWithData verifies and tries to add given transaction with additional data into the mempool. -func (bc *Blockchain) PoolTxWithData(t *transaction.Transaction, data interface{}, mp *mempool.Pool, feer mempool.Feer, verificationFunction func(tx *transaction.Transaction, data interface{}) error) error { +func (bc *Blockchain) PoolTxWithData(t *transaction.Transaction, data any, mp *mempool.Pool, feer mempool.Feer, verificationFunction func(tx *transaction.Transaction, data any) error) error { bc.lock.RLock() defer bc.lock.RUnlock() diff --git a/pkg/core/blockchain_neotest_test.go b/pkg/core/blockchain_neotest_test.go index f71b8890b..488b3411a 100644 --- a/pkg/core/blockchain_neotest_test.go +++ b/pkg/core/blockchain_neotest_test.go @@ -1024,7 +1024,7 @@ func TestBlockchain_MPTDeleteNoKey(t *testing.T) { // native contract. func TestConfigNativeUpdateHistory(t *testing.T) { var prefixPath = filepath.Join("..", "..", "config") - check := func(t *testing.T, cfgFileSuffix interface{}) { + check := func(t *testing.T, cfgFileSuffix any) { cfgPath := filepath.Join(prefixPath, fmt.Sprintf("protocol.%s.yml", cfgFileSuffix)) cfg, err := config.LoadFile(cfgPath) require.NoError(t, err, fmt.Errorf("failed to load %s", cfgPath)) @@ -1038,7 +1038,7 @@ func TestConfigNativeUpdateHistory(t *testing.T) { "edit the test if the contract should be disabled", cfgPath, c.Metadata().Name)) } } - testCases := []interface{}{ + testCases := []any{ netmode.MainNet, netmode.PrivNet, netmode.TestNet, @@ -1390,7 +1390,7 @@ func TestBlockchain_VerifyTx(t *testing.T) { checkErr(t, core.ErrInvalidAttribute, tx) }) - keys := make([]interface{}, 0, len(oraclePubs)) + keys := make([]any, 0, len(oraclePubs)) for _, p := range oraclePubs { keys = append(keys, p.Bytes()) } @@ -1612,7 +1612,7 @@ func TestBlockchain_VerifyTx(t *testing.T) { notary, err := wallet.NewAccount() require.NoError(t, err) designateSuperInvoker.Invoke(t, stackitem.Null{}, "designateAsRole", - int64(noderoles.P2PNotary), []interface{}{notary.PublicKey().Bytes()}) + int64(noderoles.P2PNotary), []any{notary.PublicKey().Bytes()}) txSetNotary := transaction.New([]byte{byte(opcode.RET)}, 0) txSetNotary.Signers = []transaction.Signer{ { @@ -1861,7 +1861,7 @@ func TestBlockchain_VerifyTx(t *testing.T) { } mp := mempool.New(10, 1, false) - verificationF := func(tx *transaction.Transaction, data interface{}) error { + verificationF := func(tx *transaction.Transaction, data any) error { if data.(int) > 5 { return errors.New("bad data") } @@ -1909,7 +1909,7 @@ func TestBlockchain_Bug1728(t *testing.T) { src := `package example import "github.com/nspcc-dev/neo-go/pkg/interop/runtime" func init() { if true { } else { } } - func _deploy(_ interface{}, isUpdate bool) { + func _deploy(_ any, isUpdate bool) { runtime.Log("Deploy") }` c := neotest.CompileSource(t, acc.ScriptHash(), strings.NewReader(src), &compiler.Options{Name: "TestContract"}) diff --git a/pkg/core/interop/contract/account_test.go b/pkg/core/interop/contract/account_test.go index 2359c185e..bedb97730 100644 --- a/pkg/core/interop/contract/account_test.go +++ b/pkg/core/interop/contract/account_test.go @@ -63,7 +63,7 @@ func TestCreateMultisigAccount(t *testing.T) { e := neotest.NewExecutor(t, bc, acc, acc) w := io.NewBufBinWriter() - createScript := func(t *testing.T, pubs []interface{}, m int) []byte { + createScript := func(t *testing.T, pubs []any, m int) []byte { w.Reset() emit.Array(w.BinWriter, pubs...) emit.Int(w.BinWriter, int64(m)) @@ -74,7 +74,7 @@ func TestCreateMultisigAccount(t *testing.T) { t.Run("Good", func(t *testing.T) { m, n := 3, 5 pubs := make(keys.PublicKeys, n) - arr := make([]interface{}, n) + arr := make([]any, n) for i := range pubs { pk, err := keys.NewPrivateKey() require.NoError(t, err) @@ -94,13 +94,13 @@ func TestCreateMultisigAccount(t *testing.T) { require.Equal(t, hash.Hash160(expected), u) }) t.Run("InvalidKey", func(t *testing.T) { - script := createScript(t, []interface{}{[]byte{1, 2, 3}}, 1) + script := createScript(t, []any{[]byte{1, 2, 3}}, 1) e.InvokeScriptCheckFAULT(t, script, []neotest.Signer{acc}, "invalid prefix 1") }) t.Run("Invalid m", func(t *testing.T) { pk, err := keys.NewPrivateKey() require.NoError(t, err) - script := createScript(t, []interface{}{pk.PublicKey().Bytes()}, 2) + script := createScript(t, []any{pk.PublicKey().Bytes()}, 2) e.InvokeScriptCheckFAULT(t, script, []neotest.Signer{acc}, "length of the signatures (2) is higher then the number of public keys") }) t.Run("m overflows int32", func(t *testing.T) { @@ -131,7 +131,7 @@ func TestCreateAccount_Hardfork(t *testing.T) { pub := priv.PublicKey() w := io.NewBufBinWriter() - emit.Array(w.BinWriter, []interface{}{pub.Bytes(), pub.Bytes(), pub.Bytes()}...) + emit.Array(w.BinWriter, []any{pub.Bytes(), pub.Bytes(), pub.Bytes()}...) emit.Int(w.BinWriter, int64(2)) emit.Syscall(w.BinWriter, interopnames.SystemContractCreateMultisigAccount) require.NoError(t, w.Err) diff --git a/pkg/core/interop/contract/call_test.go b/pkg/core/interop/contract/call_test.go index 50648a4b6..6bcf575a7 100644 --- a/pkg/core/interop/contract/call_test.go +++ b/pkg/core/interop/contract/call_test.go @@ -90,7 +90,7 @@ func TestCall(t *testing.T) { require.Error(t, contract.Call(ic)) }) - runInvalid := func(args ...interface{}) func(t *testing.T) { + runInvalid := func(args ...any) func(t *testing.T) { return func(t *testing.T) { loadScriptWithHashAndFlags(ic, currScript, h, callflag.All, 42) for i := range args { @@ -591,7 +591,7 @@ func TestCALLL_from_VoidContext(t *testing.T) { ctrInvoker.Invoke(t, stackitem.Null{}, "callHasRet") } -func loadScript(ic *interop.Context, script []byte, args ...interface{}) { +func loadScript(ic *interop.Context, script []byte, args ...any) { ic.SpawnVM() ic.VM.LoadScriptWithFlags(script, callflag.AllowCall) for i := range args { @@ -600,7 +600,7 @@ func loadScript(ic *interop.Context, script []byte, args ...interface{}) { ic.VM.GasLimit = -1 } -func loadScriptWithHashAndFlags(ic *interop.Context, script []byte, hash util.Uint160, f callflag.CallFlag, args ...interface{}) { +func loadScriptWithHashAndFlags(ic *interop.Context, script []byte, hash util.Uint160, f callflag.CallFlag, args ...any) { ic.SpawnVM() ic.VM.LoadScriptWithHash(script, hash, f) for i := range args { diff --git a/pkg/core/interop/crypto/ecdsa_test.go b/pkg/core/interop/crypto/ecdsa_test.go index fc6f70bfd..a44c959ce 100644 --- a/pkg/core/interop/crypto/ecdsa_test.go +++ b/pkg/core/interop/crypto/ecdsa_test.go @@ -180,7 +180,7 @@ func TestCheckSig(t *testing.T) { verifyFunc := ECDSASecp256r1CheckSig d := dao.NewSimple(storage.NewMemoryStore(), false, false) ic := &interop.Context{Network: uint32(netmode.UnitTestNet), DAO: d} - runCase := func(t *testing.T, isErr bool, result interface{}, args ...interface{}) { + runCase := func(t *testing.T, isErr bool, result any, args ...any) { ic.SpawnVM() for i := range args { ic.VM.Estack().PushVal(args[i]) diff --git a/pkg/core/interop/runtime/engine_test.go b/pkg/core/interop/runtime/engine_test.go index 656a78dcb..646926d8a 100644 --- a/pkg/core/interop/runtime/engine_test.go +++ b/pkg/core/interop/runtime/engine_test.go @@ -21,7 +21,7 @@ import ( "go.uber.org/zap/zaptest" ) -func checkStack(t *testing.T, v *vm.VM, args ...interface{}) { +func checkStack(t *testing.T, v *vm.VM, args ...any) { require.Equal(t, len(args), v.Estack().Len()) for i := range args { require.Equal(t, stackitem.Make(args[i]), v.Estack().Pop().Item(), "%d", i) @@ -122,7 +122,7 @@ func TestLog(t *testing.T) { ls := buf.Lines() require.Equal(t, 1, len(ls)) - var logMsg map[string]interface{} + var logMsg map[string]any require.NoError(t, json.Unmarshal([]byte(ls[0]), &logMsg)) require.Equal(t, "info", logMsg["level"]) require.Equal(t, "hello", logMsg["msg"]) diff --git a/pkg/core/interop/runtime/ext_test.go b/pkg/core/interop/runtime/ext_test.go index d423ee701..64feb3ecb 100644 --- a/pkg/core/interop/runtime/ext_test.go +++ b/pkg/core/interop/runtime/ext_test.go @@ -71,7 +71,7 @@ func createVM(t testing.TB) (*vm.VM, *interop.Context, *core.Blockchain) { return v, ic, chain } -func loadScriptWithHashAndFlags(ic *interop.Context, script []byte, hash util.Uint160, f callflag.CallFlag, args ...interface{}) { +func loadScriptWithHashAndFlags(ic *interop.Context, script []byte, hash util.Uint160, f callflag.CallFlag, args ...any) { ic.SpawnVM() ic.VM.LoadScriptWithHash(script, hash, f) for i := range args { @@ -80,7 +80,7 @@ func loadScriptWithHashAndFlags(ic *interop.Context, script []byte, hash util.Ui ic.VM.GasLimit = -1 } -func wrapDynamicScript(t *testing.T, script []byte, flags callflag.CallFlag, args ...interface{}) []byte { +func wrapDynamicScript(t *testing.T, script []byte, flags callflag.CallFlag, args ...any) []byte { b := io.NewBufBinWriter() // Params. @@ -150,7 +150,7 @@ func TestCheckWitness(t *testing.T) { script := []byte{byte(opcode.RET)} scriptHash := hash.Hash160(script) - check := func(t *testing.T, ic *interop.Context, arg interface{}, shouldFail bool, expected ...bool) { + check := func(t *testing.T, ic *interop.Context, arg any, shouldFail bool, expected ...bool) { ic.VM.Estack().PushVal(arg) err := runtime.CheckWitness(ic) if shouldFail { @@ -632,7 +632,7 @@ func TestGetRandomCompatibility(t *testing.T) { func TestNotify(t *testing.T) { caller := random.Uint160() - newIC := func(name string, args interface{}) *interop.Context { + newIC := func(name string, args any) *interop.Context { _, _, bc, cs := getDeployedInternal(t) ic, err := bc.GetTestVM(trigger.Application, nil, nil) require.NoError(t, err) diff --git a/pkg/core/interop/storage/interops_test.go b/pkg/core/interop/storage/interops_test.go index 74795fc21..0ae492c9d 100644 --- a/pkg/core/interop/storage/interops_test.go +++ b/pkg/core/interop/storage/interops_test.go @@ -11,7 +11,7 @@ import ( ) func TestUnexpectedNonInterops(t *testing.T) { - vals := map[string]interface{}{ + vals := map[string]any{ "int": 1, "bool": false, "string": "smth", diff --git a/pkg/core/mempool/mem_pool.go b/pkg/core/mempool/mem_pool.go index d393f6e34..0faf79c96 100644 --- a/pkg/core/mempool/mem_pool.go +++ b/pkg/core/mempool/mem_pool.go @@ -41,7 +41,7 @@ var ( type item struct { txn *transaction.Transaction blockStamp uint32 - data interface{} + data any } // items is a slice of an item. @@ -70,7 +70,7 @@ type Pool struct { payerIndex int resendThreshold uint32 - resendFunc func(*transaction.Transaction, interface{}) + resendFunc func(*transaction.Transaction, any) // subscriptions for mempool events subscriptionsEnabled bool @@ -197,7 +197,7 @@ func checkBalance(tx *transaction.Transaction, balance utilityBalanceAndFees) (u } // Add tries to add the given transaction to the Pool. -func (mp *Pool) Add(t *transaction.Transaction, fee Feer, data ...interface{}) error { +func (mp *Pool) Add(t *transaction.Transaction, fee Feer, data ...any) error { var pItem = item{ txn: t, blockStamp: fee.BlockHeight(), @@ -441,7 +441,7 @@ func New(capacity int, payerIndex int, enableSubscriptions bool) *Pool { // SetResendThreshold sets a threshold after which the transaction will be considered stale // and returned for retransmission by `GetStaleTransactions`. -func (mp *Pool) SetResendThreshold(h uint32, f func(*transaction.Transaction, interface{})) { +func (mp *Pool) SetResendThreshold(h uint32, f func(*transaction.Transaction, any)) { mp.lock.Lock() defer mp.lock.Unlock() mp.resendThreshold = h @@ -466,7 +466,7 @@ func (mp *Pool) TryGetValue(hash util.Uint256) (*transaction.Transaction, bool) } // TryGetData returns data associated with the specified transaction if it exists in the memory pool. -func (mp *Pool) TryGetData(hash util.Uint256) (interface{}, bool) { +func (mp *Pool) TryGetData(hash util.Uint256) (any, bool) { mp.lock.RLock() defer mp.lock.RUnlock() if tx, ok := mp.verifiedMap[hash]; ok { diff --git a/pkg/core/mempool/mem_pool_test.go b/pkg/core/mempool/mem_pool_test.go index 20d571953..43a1f0cef 100644 --- a/pkg/core/mempool/mem_pool_test.go +++ b/pkg/core/mempool/mem_pool_test.go @@ -76,7 +76,7 @@ func TestMemPoolRemoveStale(t *testing.T) { } staleTxs := make(chan *transaction.Transaction, 5) - f := func(tx *transaction.Transaction, _ interface{}) { + f := func(tx *transaction.Transaction, _ any) { staleTxs <- tx } mp.SetResendThreshold(5, f) diff --git a/pkg/core/mempoolevent/event.go b/pkg/core/mempoolevent/event.go index d59c07c8e..85fc8436b 100644 --- a/pkg/core/mempoolevent/event.go +++ b/pkg/core/mempoolevent/event.go @@ -21,7 +21,7 @@ const ( type Event struct { Type Type Tx *transaction.Transaction - Data interface{} + Data any } // String is a Stringer implementation. diff --git a/pkg/core/mpt/empty.go b/pkg/core/mpt/empty.go index b3ceec873..7a25b0f7d 100644 --- a/pkg/core/mpt/empty.go +++ b/pkg/core/mpt/empty.go @@ -29,7 +29,7 @@ func (e EmptyNode) MarshalJSON() ([]byte, error) { // UnmarshalJSON implements Node interface. func (e EmptyNode) UnmarshalJSON(bytes []byte) error { - var m map[string]interface{} + var m map[string]any err := json.Unmarshal(bytes, &m) if err != nil { return err diff --git a/pkg/core/mpt/extension.go b/pkg/core/mpt/extension.go index 49af8558b..c752e8aff 100644 --- a/pkg/core/mpt/extension.go +++ b/pkg/core/mpt/extension.go @@ -80,7 +80,7 @@ func (e *ExtensionNode) Size() int { // MarshalJSON implements the json.Marshaler. func (e *ExtensionNode) MarshalJSON() ([]byte, error) { - m := map[string]interface{}{ + m := map[string]any{ "key": hex.EncodeToString(e.key), "next": e.next, } diff --git a/pkg/core/native/crypto_test.go b/pkg/core/native/crypto_test.go index 727c160a9..11cc87db7 100644 --- a/pkg/core/native/crypto_test.go +++ b/pkg/core/native/crypto_test.go @@ -91,7 +91,7 @@ func testECDSAVerify(t *testing.T, curve NamedCurve) { } require.NoError(t, err) - runCase := func(t *testing.T, isErr bool, result interface{}, args ...interface{}) { + runCase := func(t *testing.T, isErr bool, result any, args ...any) { argsArr := make([]stackitem.Item, len(args)) for i := range args { argsArr[i] = stackitem.Make(args[i]) diff --git a/pkg/core/native/native_test/common_test.go b/pkg/core/native/native_test/common_test.go index 53a927a52..4957291f6 100644 --- a/pkg/core/native/native_test/common_test.go +++ b/pkg/core/native/native_test/common_test.go @@ -113,7 +113,7 @@ func testGetSetCache(t *testing.T, c *neotest.ContractInvoker, name string, defa } func setNodesByRole(t *testing.T, designateInvoker *neotest.ContractInvoker, ok bool, r noderoles.Role, nodes keys.PublicKeys) { - pubs := make([]interface{}, len(nodes)) + pubs := make([]any, len(nodes)) for i := range nodes { pubs[i] = nodes[i].Bytes() } diff --git a/pkg/core/native/native_test/designate_test.go b/pkg/core/native/native_test/designate_test.go index 98d3c362b..5bb7e47d0 100644 --- a/pkg/core/native/native_test/designate_test.go +++ b/pkg/core/native/native_test/designate_test.go @@ -106,11 +106,11 @@ func TestDesignate_Cache(t *testing.T) { } privGood, err := keys.NewPrivateKey() require.NoError(t, err) - pubsGood := []interface{}{privGood.PublicKey().Bytes()} + pubsGood := []any{privGood.PublicKey().Bytes()} privBad, err := keys.NewPrivateKey() require.NoError(t, err) - pubsBad := []interface{}{privBad.PublicKey().Bytes()} + pubsBad := []any{privBad.PublicKey().Bytes()} // Firstly, designate good Oracle node and check that OracleService callback was called during PostPersist. e.Chain.SetOracle(oracleServ) diff --git a/pkg/core/native/native_test/gas_test.go b/pkg/core/native/native_test/gas_test.go index 3c08fbf30..e92f9097b 100644 --- a/pkg/core/native/native_test/gas_test.go +++ b/pkg/core/native/native_test/gas_test.go @@ -78,7 +78,7 @@ func TestGAS_RewardWithP2PSigExtensionsEnabled(t *testing.T) { // set Notary nodes and check their balance notaryNodes := make([]*keys.PrivateKey, nNotaries) - notaryNodesPublicKeys := make([]interface{}, nNotaries) + notaryNodesPublicKeys := make([]any, nNotaries) var err error for i := range notaryNodes { notaryNodes[i], err = keys.NewPrivateKey() @@ -92,7 +92,7 @@ func TestGAS_RewardWithP2PSigExtensionsEnabled(t *testing.T) { // deposit GAS for `signer` with lock until the next block depositAmount := 100_0000 + (2+int64(nKeys))*notaryServiceFeePerKey // sysfee + netfee of the next transaction - gasCommitteeInvoker.Invoke(t, true, "transfer", e.CommitteeHash, notaryHash, depositAmount, []interface{}{e.CommitteeHash, e.Chain.BlockHeight() + 1}) + gasCommitteeInvoker.Invoke(t, true, "transfer", e.CommitteeHash, notaryHash, depositAmount, []any{e.CommitteeHash, e.Chain.BlockHeight() + 1}) // save initial GAS total supply getGASTS := func(t *testing.T) int64 { diff --git a/pkg/core/native/native_test/management_test.go b/pkg/core/native/native_test/management_test.go index dd5535cdb..a5525fb0b 100644 --- a/pkg/core/native/native_test/management_test.go +++ b/pkg/core/native/native_test/management_test.go @@ -98,7 +98,7 @@ func TestManagement_ContractDeploy(t *testing.T) { managementInvoker.InvokeFail(t, "invalid NEF file", "deploy", []byte{}, manifestBytes) }) t.Run("array for NEF", func(t *testing.T) { - managementInvoker.InvokeFail(t, "invalid NEF file", "deploy", []interface{}{int64(1)}, manifestBytes) + managementInvoker.InvokeFail(t, "invalid NEF file", "deploy", []any{int64(1)}, manifestBytes) }) t.Run("bad script in NEF", func(t *testing.T) { nf, err := nef.FileFromBytes(nefBytes) // make a full copy @@ -116,7 +116,7 @@ func TestManagement_ContractDeploy(t *testing.T) { managementInvoker.InvokeFail(t, "invalid manifest", "deploy", nefBytes, []byte{}) }) t.Run("array for manifest", func(t *testing.T) { - managementInvoker.InvokeFail(t, "invalid manifest", "deploy", nefBytes, []interface{}{int64(1)}) + managementInvoker.InvokeFail(t, "invalid manifest", "deploy", nefBytes, []any{int64(1)}) }) t.Run("non-utf8 manifest", func(t *testing.T) { manifestBad := bytes.Replace(manifestBytes, []byte("TestMain"), []byte("\xff\xfe\xfd"), 1) // Replace name. @@ -549,7 +549,7 @@ func TestManagement_GetContract(t *testing.T) { managementInvoker.Invoke(t, si, "deploy", nefBytes, manifestBytes) t.Run("bad parameter type", func(t *testing.T) { - managementInvoker.InvokeFail(t, "invalid conversion: Array/ByteString", "getContract", []interface{}{int64(1)}) + managementInvoker.InvokeFail(t, "invalid conversion: Array/ByteString", "getContract", []any{int64(1)}) }) t.Run("not a hash", func(t *testing.T) { managementInvoker.InvokeFail(t, "expected byte size of 20 got 3", "getContract", []byte{1, 2, 3}) @@ -558,7 +558,7 @@ func TestManagement_GetContract(t *testing.T) { managementInvoker.Invoke(t, si, "getContract", cs1.Hash.BytesBE()) }) t.Run("by ID, bad parameter type", func(t *testing.T) { - managementInvoker.InvokeFail(t, "invalid conversion: Array/Integer", "getContractById", []interface{}{int64(1)}) + managementInvoker.InvokeFail(t, "invalid conversion: Array/Integer", "getContractById", []any{int64(1)}) }) t.Run("by ID, bad num", func(t *testing.T) { managementInvoker.InvokeFail(t, "id is not a correct int32", "getContractById", []byte{1, 2, 3, 4, 5}) diff --git a/pkg/core/native/native_test/notary_test.go b/pkg/core/native/native_test/notary_test.go index 85e3914fb..c4a58ac71 100644 --- a/pkg/core/native/native_test/notary_test.go +++ b/pkg/core/native/native_test/notary_test.go @@ -75,19 +75,19 @@ func TestNotary_Pipeline(t *testing.T) { notaryCommitteeInvoker.Invoke(t, false, "lockDepositUntil", multisigHash, int64(depositLock+1)) // `onPayment`: bad token - neoCommitteeInvoker.InvokeFail(t, "only GAS can be accepted for deposit", "transfer", multisigHash, notaryHash, int64(1), []interface{}{nil, int64(depositLock)}) + neoCommitteeInvoker.InvokeFail(t, "only GAS can be accepted for deposit", "transfer", multisigHash, notaryHash, int64(1), []any{nil, int64(depositLock)}) // `onPayment`: insufficient first deposit - gasCommitteeInvoker.InvokeFail(t, "first deposit can not be less then", "transfer", multisigHash, notaryHash, int64(2*feePerKey-1), []interface{}{nil, int64(depositLock)}) + gasCommitteeInvoker.InvokeFail(t, "first deposit can not be less then", "transfer", multisigHash, notaryHash, int64(2*feePerKey-1), []any{nil, int64(depositLock)}) // `onPayment`: invalid `data` (missing `till` parameter) - gasCommitteeInvoker.InvokeFail(t, "`data` parameter should be an array of 2 elements", "transfer", multisigHash, notaryHash, 2*feePerKey, []interface{}{nil}) + gasCommitteeInvoker.InvokeFail(t, "`data` parameter should be an array of 2 elements", "transfer", multisigHash, notaryHash, 2*feePerKey, []any{nil}) // `onPayment`: invalid `data` (outdated `till` parameter) - gasCommitteeInvoker.InvokeFail(t, "`till` shouldn't be less then the chain's height", "transfer", multisigHash, notaryHash, 2*feePerKey, []interface{}{nil, int64(0)}) + gasCommitteeInvoker.InvokeFail(t, "`till` shouldn't be less then the chain's height", "transfer", multisigHash, notaryHash, 2*feePerKey, []any{nil, int64(0)}) // `onPayment`: good - gasCommitteeInvoker.Invoke(t, true, "transfer", multisigHash, notaryHash, 2*feePerKey, []interface{}{nil, int64(depositLock)}) + gasCommitteeInvoker.Invoke(t, true, "transfer", multisigHash, notaryHash, 2*feePerKey, []any{nil, int64(depositLock)}) checkBalanceOf(t, notaryHash, 2*feePerKey) // `expirationOf`: check `till` was set @@ -97,7 +97,7 @@ func TestNotary_Pipeline(t *testing.T) { notaryCommitteeInvoker.Invoke(t, 2*feePerKey, "balanceOf", multisigHash) // `onPayment`: good second deposit and explicit `to` paramenter - gasCommitteeInvoker.Invoke(t, true, "transfer", multisigHash, notaryHash, feePerKey, []interface{}{multisigHash, int64(depositLock + 1)}) + gasCommitteeInvoker.Invoke(t, true, "transfer", multisigHash, notaryHash, feePerKey, []any{multisigHash, int64(depositLock + 1)}) checkBalanceOf(t, notaryHash, 3*feePerKey) // `balanceOf`: check deposited amount for the multisig account @@ -107,17 +107,17 @@ func TestNotary_Pipeline(t *testing.T) { notaryCommitteeInvoker.Invoke(t, depositLock+1, "expirationOf", multisigHash) // `onPayment`: empty payment, should fail because `till` less then the previous one - gasCommitteeInvoker.InvokeFail(t, "`till` shouldn't be less then the previous value", "transfer", multisigHash, notaryHash, int64(0), []interface{}{multisigHash, int64(depositLock)}) + gasCommitteeInvoker.InvokeFail(t, "`till` shouldn't be less then the previous value", "transfer", multisigHash, notaryHash, int64(0), []any{multisigHash, int64(depositLock)}) checkBalanceOf(t, notaryHash, 3*feePerKey) notaryCommitteeInvoker.Invoke(t, depositLock+1, "expirationOf", multisigHash) // `onPayment`: empty payment, should fail because `till` less then the chain height - gasCommitteeInvoker.InvokeFail(t, "`till` shouldn't be less then the chain's height", "transfer", multisigHash, notaryHash, int64(0), []interface{}{multisigHash, int64(1)}) + gasCommitteeInvoker.InvokeFail(t, "`till` shouldn't be less then the chain's height", "transfer", multisigHash, notaryHash, int64(0), []any{multisigHash, int64(1)}) checkBalanceOf(t, notaryHash, 3*feePerKey) notaryCommitteeInvoker.Invoke(t, depositLock+1, "expirationOf", multisigHash) // `onPayment`: empty payment, should successfully update `till` - gasCommitteeInvoker.Invoke(t, true, "transfer", multisigHash, notaryHash, int64(0), []interface{}{multisigHash, int64(depositLock + 2)}) + gasCommitteeInvoker.Invoke(t, true, "transfer", multisigHash, notaryHash, int64(0), []any{multisigHash, int64(depositLock + 2)}) checkBalanceOf(t, notaryHash, 3*feePerKey) notaryCommitteeInvoker.Invoke(t, depositLock+2, "expirationOf", multisigHash) @@ -159,12 +159,12 @@ func TestNotary_Pipeline(t *testing.T) { notaryCommitteeInvoker.Invoke(t, false, "withdraw", multisigHash, accHash) // `onPayment`: good first deposit to other account, should set default `till` even if other `till` value is provided - gasCommitteeInvoker.Invoke(t, true, "transfer", multisigHash, notaryHash, 2*feePerKey, []interface{}{accHash, int64(math.MaxUint32 - 1)}) + gasCommitteeInvoker.Invoke(t, true, "transfer", multisigHash, notaryHash, 2*feePerKey, []any{accHash, int64(math.MaxUint32 - 1)}) checkBalanceOf(t, notaryHash, 2*feePerKey) notaryCommitteeInvoker.Invoke(t, 5760+e.Chain.BlockHeight()-1, "expirationOf", accHash) // `onPayment`: good second deposit to other account, shouldn't update `till` even if other `till` value is provided - gasCommitteeInvoker.Invoke(t, true, "transfer", multisigHash, notaryHash, feePerKey, []interface{}{accHash, int64(math.MaxUint32 - 1)}) + gasCommitteeInvoker.Invoke(t, true, "transfer", multisigHash, notaryHash, feePerKey, []any{accHash, int64(math.MaxUint32 - 1)}) checkBalanceOf(t, notaryHash, 3*feePerKey) notaryCommitteeInvoker.Invoke(t, 5760+e.Chain.BlockHeight()-3, "expirationOf", accHash) } @@ -184,7 +184,7 @@ func TestNotary_NotaryNodesReward(t *testing.T) { // set Notary nodes and check their balance notaryNodes := make([]*keys.PrivateKey, nNotaryNodes) - notaryNodesPublicKeys := make([]interface{}, nNotaryNodes) + notaryNodesPublicKeys := make([]any, nNotaryNodes) for i := range notaryNodes { notaryNodes[i], err = keys.NewPrivateKey() require.NoError(t, err) @@ -201,7 +201,7 @@ func TestNotary_NotaryNodesReward(t *testing.T) { if !spendFullDeposit { depositAmount += 1_0000 } - gasCommitteeInvoker.Invoke(t, true, "transfer", multisigHash, notaryHash, depositAmount, []interface{}{multisigHash, e.Chain.BlockHeight() + 1}) + gasCommitteeInvoker.Invoke(t, true, "transfer", multisigHash, notaryHash, depositAmount, []any{multisigHash, e.Chain.BlockHeight() + 1}) // send transaction with Notary contract as a sender tx := transaction.New([]byte{byte(opcode.PUSH1)}, 1_000_000) diff --git a/pkg/core/native/native_test/oracle_test.go b/pkg/core/native/native_test/oracle_test.go index f7ce224f3..54ad6569c 100644 --- a/pkg/core/native/native_test/oracle_test.go +++ b/pkg/core/native/native_test/oracle_test.go @@ -36,7 +36,7 @@ func TestOracle_GetSetPriceCache(t *testing.T) { func putOracleRequest(t *testing.T, oracleInvoker *neotest.ContractInvoker, url string, filter *string, cb string, userData []byte, gas int64, errStr ...string) { - var filtItem interface{} + var filtItem any if filter != nil { filtItem = *filter } @@ -71,7 +71,7 @@ func TestOracle_Request(t *testing.T) { // Designate single Oracle node. oracleNode := e.NewAccount(t) - designationCommitteeInvoker.Invoke(t, stackitem.Null{}, "designateAsRole", int(noderoles.Oracle), []interface{}{oracleNode.(neotest.SingleSigner).Account().PublicKey().Bytes()}) + designationCommitteeInvoker.Invoke(t, stackitem.Null{}, "designateAsRole", int(noderoles.Oracle), []any{oracleNode.(neotest.SingleSigner).Account().PublicKey().Bytes()}) err = oracleNode.(neotest.SingleSigner).Account().ConvertMultisig(1, []*keys.PublicKey{oracleNode.(neotest.SingleSigner).Account().PublicKey()}) require.NoError(t, err) oracleNodeMulti := neotest.NewMultiSigner(oracleNode.(neotest.SingleSigner).Account()) diff --git a/pkg/core/native/oracle_types_test.go b/pkg/core/native/oracle_types_test.go index cba0e20b1..ac640151d 100644 --- a/pkg/core/native/oracle_types_test.go +++ b/pkg/core/native/oracle_types_test.go @@ -9,7 +9,7 @@ import ( "github.com/stretchr/testify/require" ) -func getInvalidTestFunc(actual stackitem.Convertible, value interface{}) func(t *testing.T) { +func getInvalidTestFunc(actual stackitem.Convertible, value any) func(t *testing.T) { return func(t *testing.T) { it := stackitem.Make(value) require.Error(t, actual.FromStackItem(it)) diff --git a/pkg/core/native/std_test.go b/pkg/core/native/std_test.go index 48b81b526..dc1461328 100644 --- a/pkg/core/native/std_test.go +++ b/pkg/core/native/std_test.go @@ -306,7 +306,7 @@ func TestStdLibSerializeDeserialize(t *testing.T) { ic := &interop.Context{VM: vm.New(), DAO: &dao.Simple{}} var actual stackitem.Item - checkSerializeDeserialize := func(t *testing.T, value interface{}, expected stackitem.Item) { + checkSerializeDeserialize := func(t *testing.T, value any, expected stackitem.Item) { require.NotPanics(t, func() { actual = s.serialize(ic, []stackitem.Item{stackitem.Make(value)}) }) @@ -427,7 +427,7 @@ func TestMemorySearch(t *testing.T) { s := newStd() ic := &interop.Context{VM: vm.New()} - check := func(t *testing.T, result int64, args ...interface{}) { + check := func(t *testing.T, result int64, args ...any) { items := make([]stackitem.Item, len(args)) for i := range args { items[i] = stackitem.Make(args[i]) @@ -519,7 +519,7 @@ func TestStringSplit(t *testing.T) { s := newStd() ic := &interop.Context{VM: vm.New()} - check := func(t *testing.T, result []string, str, sep string, remove interface{}) { + check := func(t *testing.T, result []string, str, sep string, remove any) { args := []stackitem.Item{stackitem.Make(str), stackitem.Make(sep)} var actual stackitem.Item if remove == nil { diff --git a/pkg/core/transaction/attribute.go b/pkg/core/transaction/attribute.go index 91f8b66e5..0044f4b5f 100644 --- a/pkg/core/transaction/attribute.go +++ b/pkg/core/transaction/attribute.go @@ -17,7 +17,7 @@ type Attribute struct { // Anonymous interface fields are not considered anonymous by // json lib and marshaling Value together with type makes code // harder to follow. - toJSONMap(map[string]interface{}) + toJSONMap(map[string]any) } } @@ -70,7 +70,7 @@ func (attr *Attribute) EncodeBinary(bw *io.BinWriter) { // MarshalJSON implements the json Marshaller interface. func (attr *Attribute) MarshalJSON() ([]byte, error) { - m := map[string]interface{}{"type": attr.Type.String()} + m := map[string]any{"type": attr.Type.String()} if attr.Value != nil { attr.Value.toJSONMap(m) } diff --git a/pkg/core/transaction/conflicts.go b/pkg/core/transaction/conflicts.go index 01b62e441..50005fb21 100644 --- a/pkg/core/transaction/conflicts.go +++ b/pkg/core/transaction/conflicts.go @@ -20,6 +20,6 @@ func (c *Conflicts) EncodeBinary(w *io.BinWriter) { c.Hash.EncodeBinary(w) } -func (c *Conflicts) toJSONMap(m map[string]interface{}) { +func (c *Conflicts) toJSONMap(m map[string]any) { m["hash"] = c.Hash } diff --git a/pkg/core/transaction/not_valid_before.go b/pkg/core/transaction/not_valid_before.go index 232009f3d..6fe9b7b56 100644 --- a/pkg/core/transaction/not_valid_before.go +++ b/pkg/core/transaction/not_valid_before.go @@ -19,6 +19,6 @@ func (n *NotValidBefore) EncodeBinary(w *io.BinWriter) { w.WriteU32LE(n.Height) } -func (n *NotValidBefore) toJSONMap(m map[string]interface{}) { +func (n *NotValidBefore) toJSONMap(m map[string]any) { m["height"] = n.Height } diff --git a/pkg/core/transaction/notary_assisted.go b/pkg/core/transaction/notary_assisted.go index 5a7de29a4..747711165 100644 --- a/pkg/core/transaction/notary_assisted.go +++ b/pkg/core/transaction/notary_assisted.go @@ -19,6 +19,6 @@ func (n *NotaryAssisted) EncodeBinary(w *io.BinWriter) { w.WriteB(n.NKeys) } -func (n *NotaryAssisted) toJSONMap(m map[string]interface{}) { +func (n *NotaryAssisted) toJSONMap(m map[string]any) { m["nkeys"] = n.NKeys } diff --git a/pkg/core/transaction/oracle.go b/pkg/core/transaction/oracle.go index 2d396d2f7..68459ef56 100644 --- a/pkg/core/transaction/oracle.go +++ b/pkg/core/transaction/oracle.go @@ -111,7 +111,7 @@ func (r *OracleResponse) EncodeBinary(w *io.BinWriter) { w.WriteVarBytes(r.Result) } -func (r *OracleResponse) toJSONMap(m map[string]interface{}) { +func (r *OracleResponse) toJSONMap(m map[string]any) { m["id"] = r.ID m["code"] = r.Code m["result"] = r.Result diff --git a/pkg/core/transaction/oracle_test.go b/pkg/core/transaction/oracle_test.go index f0ec24a09..afc61f441 100644 --- a/pkg/core/transaction/oracle_test.go +++ b/pkg/core/transaction/oracle_test.go @@ -68,7 +68,7 @@ func TestOracleResponse_toJSONMap(t *testing.T) { b1, err := json.Marshal(r) require.NoError(t, err) - m := map[string]interface{}{} + m := map[string]any{} r.toJSONMap(m) b2, err := json.Marshal(m) require.NoError(t, err) diff --git a/pkg/core/transaction/reserved.go b/pkg/core/transaction/reserved.go index cc622c708..677458aa3 100644 --- a/pkg/core/transaction/reserved.go +++ b/pkg/core/transaction/reserved.go @@ -19,6 +19,6 @@ func (e *Reserved) EncodeBinary(w *io.BinWriter) { w.WriteVarBytes(e.Value) } -func (e *Reserved) toJSONMap(m map[string]interface{}) { +func (e *Reserved) toJSONMap(m map[string]any) { m["value"] = e.Value } diff --git a/pkg/core/transaction/witness_condition.go b/pkg/core/transaction/witness_condition.go index 65a73b09e..b34a8d389 100644 --- a/pkg/core/transaction/witness_condition.go +++ b/pkg/core/transaction/witness_condition.go @@ -631,7 +631,7 @@ func unmarshalConditionJSON(data []byte, maxDepth int) (WitnessCondition, error) return res, nil } -func condToStackItem(typ WitnessConditionType, c interface{}) stackitem.Item { +func condToStackItem(typ WitnessConditionType, c any) stackitem.Item { res := make([]stackitem.Item, 0, 2) res = append(res, stackitem.NewBigInteger(big.NewInt(int64(typ)))) switch typ { diff --git a/pkg/crypto/keys/publickey.go b/pkg/crypto/keys/publickey.go index 674ca8e76..c1bf5c3b0 100644 --- a/pkg/crypto/keys/publickey.go +++ b/pkg/crypto/keys/publickey.go @@ -181,7 +181,7 @@ func (p *PublicKey) UncompressedBytes() []byte { func NewPublicKeyFromASN1(data []byte) (*PublicKey, error) { var ( err error - pubkey interface{} + pubkey any ) if pubkey, err = x509.ParsePKIXPublicKey(data); err != nil { return nil, err diff --git a/pkg/encoding/fixedn/fixed8.go b/pkg/encoding/fixedn/fixed8.go index 3bea85b3a..ad28d5133 100644 --- a/pkg/encoding/fixedn/fixed8.go +++ b/pkg/encoding/fixedn/fixed8.go @@ -85,7 +85,7 @@ func (f *Fixed8) UnmarshalJSON(data []byte) error { } // UnmarshalYAML implements the yaml unmarshaler interface. -func (f *Fixed8) UnmarshalYAML(unmarshal func(interface{}) error) error { +func (f *Fixed8) UnmarshalYAML(unmarshal func(any) error) error { var s string err := unmarshal(&s) if err != nil { @@ -109,7 +109,7 @@ func (f Fixed8) MarshalJSON() ([]byte, error) { } // MarshalYAML implements the yaml marshaller interface. -func (f Fixed8) MarshalYAML() (interface{}, error) { +func (f Fixed8) MarshalYAML() (any, error) { return f.String(), nil } diff --git a/pkg/interop/contract/contract.go b/pkg/interop/contract/contract.go index 2f3843ee3..0b4ad6b58 100644 --- a/pkg/interop/contract/contract.go +++ b/pkg/interop/contract/contract.go @@ -47,6 +47,6 @@ func GetCallFlags() CallFlag { // (20 bytes in BE form) using the provided arguments and call flags. // It returns whatever this contract returns. This function uses // `System.Contract.Call` syscall. -func Call(scriptHash interop.Hash160, method string, f CallFlag, args ...interface{}) interface{} { +func Call(scriptHash interop.Hash160, method string, f CallFlag, args ...any) any { return neogointernal.Syscall4("System.Contract.Call", scriptHash, method, f, args) } diff --git a/pkg/interop/convert/convert.go b/pkg/interop/convert/convert.go index 653f55ca1..0f4eb8dc0 100644 --- a/pkg/interop/convert/convert.go +++ b/pkg/interop/convert/convert.go @@ -2,21 +2,21 @@ package convert // ToInteger converts it's argument to an Integer. -func ToInteger(v interface{}) int { +func ToInteger(v any) int { return v.(int) } // ToBytes converts it's argument to a Buffer VM type. -func ToBytes(v interface{}) []byte { +func ToBytes(v any) []byte { return v.([]byte) } // ToString converts it's argument to a ByteString VM type. -func ToString(v interface{}) string { +func ToString(v any) string { return v.(string) } // ToBool converts it's argument to a Boolean. -func ToBool(v interface{}) bool { +func ToBool(v any) bool { return v.(bool) } diff --git a/pkg/interop/doc.go b/pkg/interop/doc.go index a78d25b72..b9d083500 100644 --- a/pkg/interop/doc.go +++ b/pkg/interop/doc.go @@ -14,6 +14,7 @@ correspond to smartcontract and VM types: []byte - ByteArray (Buffer in VM) string - String (ByteString in VM) (interface{})(nil) - Any + (any)(nil) - Any non-byte slice - Array map[K]V - map diff --git a/pkg/interop/iterator/iterator.go b/pkg/interop/iterator/iterator.go index 391e64cf3..243d02851 100644 --- a/pkg/interop/iterator/iterator.go +++ b/pkg/interop/iterator/iterator.go @@ -24,6 +24,6 @@ func Next(it Iterator) bool { // For slices, the result is just value. // For maps, the result can be cast to a slice of 2 elements: a key and a value. // For storage iterators, refer to `storage.FindFlags` documentation. -func Value(it Iterator) interface{} { +func Value(it Iterator) any { return neogointernal.Syscall1("System.Iterator.Value", it) } diff --git a/pkg/interop/lib/contract/contract.go b/pkg/interop/lib/contract/contract.go index 735db00ba..8011ae6f9 100644 --- a/pkg/interop/lib/contract/contract.go +++ b/pkg/interop/lib/contract/contract.go @@ -11,7 +11,7 @@ import ( // (20 bytes in BE form) using the provided arguments and call flags. It fails // if the contract has version mismatch. It returns whatever this contract // returns. This function uses `System.Contract.Call` syscall. -func CallWithVersion(scriptHash interop.Hash160, version int, method string, f contract.CallFlag, args ...interface{}) interface{} { +func CallWithVersion(scriptHash interop.Hash160, version int, method string, f contract.CallFlag, args ...any) any { cs := management.GetContract(scriptHash) if cs == nil { panic("unknown contract") diff --git a/pkg/interop/native/gas/gas.go b/pkg/interop/native/gas/gas.go index 538ac0a36..338a6f99d 100644 --- a/pkg/interop/native/gas/gas.go +++ b/pkg/interop/native/gas/gas.go @@ -34,7 +34,7 @@ func BalanceOf(addr interop.Hash160) int { } // Transfer represents `transfer` method of GAS native contract. -func Transfer(from, to interop.Hash160, amount int, data interface{}) bool { +func Transfer(from, to interop.Hash160, amount int, data any) bool { return neogointernal.CallWithToken(Hash, "transfer", int(contract.All), from, to, amount, data).(bool) } diff --git a/pkg/interop/native/ledger/block.go b/pkg/interop/native/ledger/block.go index 84e1a6407..0164803cb 100644 --- a/pkg/interop/native/ledger/block.go +++ b/pkg/interop/native/ledger/block.go @@ -51,5 +51,5 @@ type BlockSR struct { // ToBlockSR converts Block into BlockSR for chains with StateRootInHeader option. func (b *Block) ToBlockSR() *BlockSR { - return interface{}(b).(*BlockSR) + return any(b).(*BlockSR) } diff --git a/pkg/interop/native/ledger/ledger.go b/pkg/interop/native/ledger/ledger.go index f26a15fa4..591dccaea 100644 --- a/pkg/interop/native/ledger/ledger.go +++ b/pkg/interop/native/ledger/ledger.go @@ -39,7 +39,7 @@ func CurrentIndex() int { } // GetBlock represents `getBlock` method of Ledger native contract. -func GetBlock(indexOrHash interface{}) *Block { +func GetBlock(indexOrHash any) *Block { return neogointernal.CallWithToken(Hash, "getBlock", int(contract.ReadStates), indexOrHash).(*Block) } @@ -54,7 +54,7 @@ func GetTransactionHeight(hash interop.Hash256) int { } // GetTransactionFromBlock represents `getTransactionFromBlock` method of Ledger native contract. -func GetTransactionFromBlock(indexOrHash interface{}, txIndex int) *Transaction { +func GetTransactionFromBlock(indexOrHash any, txIndex int) *Transaction { return neogointernal.CallWithToken(Hash, "getTransactionFromBlock", int(contract.ReadStates), indexOrHash, txIndex).(*Transaction) } diff --git a/pkg/interop/native/ledger/transaction_signer.go b/pkg/interop/native/ledger/transaction_signer.go index 04f04772b..05270faf6 100644 --- a/pkg/interop/native/ledger/transaction_signer.go +++ b/pkg/interop/native/ledger/transaction_signer.go @@ -82,7 +82,7 @@ type WitnessCondition struct { // WitnessCalledByContract -> interop.Hash160 // WitnessCalledByGroup -> interop.PublicKey // WitnessCalledByEntry -> doesn't have value, thus, an attempt to access the Value leads to runtime exception. - Value interface{} + Value any } // WitnessConditionType represents the type of rule-based witness condition. diff --git a/pkg/interop/native/management/contract.go b/pkg/interop/native/management/contract.go index 31778e2e4..b05fc66bc 100644 --- a/pkg/interop/native/management/contract.go +++ b/pkg/interop/native/management/contract.go @@ -40,7 +40,7 @@ type Manifest struct { ABI ABI Permissions []Permission Trusts []interop.Hash160 - Extra interface{} + Extra any } // ABI represents contract's ABI. diff --git a/pkg/interop/native/management/management.go b/pkg/interop/native/management/management.go index 8f6517242..9e7a632c3 100644 --- a/pkg/interop/native/management/management.go +++ b/pkg/interop/native/management/management.go @@ -29,7 +29,7 @@ func Deploy(script, manifest []byte) *Contract { } // DeployWithData represents `deploy` method of Management native contract. -func DeployWithData(script, manifest []byte, data interface{}) *Contract { +func DeployWithData(script, manifest []byte, data any) *Contract { return neogointernal.CallWithToken(Hash, "deploy", int(contract.All), script, manifest, data).(*Contract) } @@ -80,7 +80,7 @@ func Update(script, manifest []byte) { } // UpdateWithData represents `update` method of Management native contract. -func UpdateWithData(script, manifest []byte, data interface{}) { +func UpdateWithData(script, manifest []byte, data any) { neogointernal.CallWithTokenNoRet(Hash, "update", int(contract.All), script, manifest, data) } diff --git a/pkg/interop/native/neo/neo.go b/pkg/interop/native/neo/neo.go index 4c5e4c9b0..dac6dae9d 100644 --- a/pkg/interop/native/neo/neo.go +++ b/pkg/interop/native/neo/neo.go @@ -44,7 +44,7 @@ func BalanceOf(addr interop.Hash160) int { } // Transfer represents `transfer` method of NEO native contract. -func Transfer(from, to interop.Hash160, amount int, data interface{}) bool { +func Transfer(from, to interop.Hash160, amount int, data any) bool { return neogointernal.CallWithToken(Hash, "transfer", int(contract.All), from, to, amount, data).(bool) } diff --git a/pkg/interop/native/oracle/oracle.go b/pkg/interop/native/oracle/oracle.go index 46a627a17..14155b5df 100644 --- a/pkg/interop/native/oracle/oracle.go +++ b/pkg/interop/native/oracle/oracle.go @@ -50,7 +50,7 @@ const MinimumResponseGas = 10_000_000 // of the same contract that invokes Request and it must have the following // signature for correct invocation: // -// - Method(url string, userData interface{}, code int, result []byte) +// - Method(url string, userData any, code int, result []byte) // where url is the same url specified for Request, userData is anything // passed in the next parameter, code is the status of the reply and // result is the data returned from the request if any. @@ -64,7 +64,7 @@ const MinimumResponseGas = 10_000_000 // GAS is used for oracle transaction's network and system fees, // so it should be enough to pay for reply data as well as // its processing. -func Request(url string, filter []byte, cb string, userData interface{}, gasForResponse int) { +func Request(url string, filter []byte, cb string, userData any, gasForResponse int) { neogointernal.CallWithTokenNoRet(Hash, "request", int(contract.States|contract.AllowNotify), url, filter, cb, userData, gasForResponse) diff --git a/pkg/interop/native/std/std.go b/pkg/interop/native/std/std.go index 10d7ddd47..e79e32d3d 100644 --- a/pkg/interop/native/std/std.go +++ b/pkg/interop/native/std/std.go @@ -16,14 +16,14 @@ const Hash = "\xc0\xef\x39\xce\xe0\xe4\xe9\x25\xc6\xc2\xa0\x6a\x79\xe1\x44\x0d\x // any given item into a byte slice. It works for all regular VM types (not ones // from interop package) and allows to save them in the storage or pass them into Notify // and then Deserialize them on the next run or in the external event receiver. -func Serialize(item interface{}) []byte { +func Serialize(item any) []byte { return neogointernal.CallWithToken(Hash, "serialize", int(contract.NoneFlag), item).([]byte) } // Deserialize calls `deserialize` method of StdLib native contract and unpacks // a previously serialized value from a byte slice, it's the opposite of Serialize. -func Deserialize(b []byte) interface{} { +func Deserialize(b []byte) any { return neogointernal.CallWithToken(Hash, "deserialize", int(contract.NoneFlag), b) } @@ -37,8 +37,9 @@ func Deserialize(b []byte) interface{} { // string -> base64 encoded sequence of underlying bytes // (u)int* -> integer, only value in -2^53..2^53 are allowed // []interface{} -> json array +// []any -> json array // map[type1]type2 -> json object with string keys marshaled as strings (not base64). -func JSONSerialize(item interface{}) []byte { +func JSONSerialize(item any) []byte { return neogointernal.CallWithToken(Hash, "jsonSerialize", int(contract.NoneFlag), item).([]byte) } @@ -52,7 +53,7 @@ func JSONSerialize(item interface{}) []byte { // null -> interface{}(nil) // arrays -> []interface{} // maps -> map[string]interface{} -func JSONDeserialize(data []byte) interface{} { +func JSONDeserialize(data []byte) any { return neogointernal.CallWithToken(Hash, "jsonDeserialize", int(contract.NoneFlag), data) } diff --git a/pkg/interop/neogointernal/call.go b/pkg/interop/neogointernal/call.go index 0309bfe94..f32e65fad 100644 --- a/pkg/interop/neogointernal/call.go +++ b/pkg/interop/neogointernal/call.go @@ -3,10 +3,10 @@ package neogointernal // CallWithToken performs contract call using CALLT instruction. It only works // for static script hashes and methods, requiring additional metadata compared to // ordinary contract.Call. It's more efficient though. -func CallWithToken(scriptHash string, method string, flags int, args ...interface{}) interface{} { +func CallWithToken(scriptHash string, method string, flags int, args ...any) any { return nil } // CallWithTokenNoRet is a version of CallWithToken that does not return anything. -func CallWithTokenNoRet(scriptHash string, method string, flags int, args ...interface{}) { +func CallWithTokenNoRet(scriptHash string, method string, flags int, args ...any) { } diff --git a/pkg/interop/neogointernal/opcode.go b/pkg/interop/neogointernal/opcode.go index 1667c5e05..a64e85733 100644 --- a/pkg/interop/neogointernal/opcode.go +++ b/pkg/interop/neogointernal/opcode.go @@ -5,20 +5,20 @@ func Opcode0NoReturn(op string) { } // Opcode1 emits opcode with 1 argument. -func Opcode1(op string, arg interface{}) interface{} { +func Opcode1(op string, arg any) any { return nil } // Opcode2 emits opcode with 2 arguments. -func Opcode2(op string, arg1, arg2 interface{}) interface{} { +func Opcode2(op string, arg1, arg2 any) any { return nil } // Opcode2NoReturn emits opcode with 2 arguments. -func Opcode2NoReturn(op string, arg1, arg2 interface{}) { +func Opcode2NoReturn(op string, arg1, arg2 any) { } // Opcode3 emits opcode with 3 arguments. -func Opcode3(op string, arg1, arg2, arg3 interface{}) interface{} { +func Opcode3(op string, arg1, arg2, arg3 any) any { return nil } diff --git a/pkg/interop/neogointernal/syscall.go b/pkg/interop/neogointernal/syscall.go index f42ed2735..d106d2c1a 100644 --- a/pkg/interop/neogointernal/syscall.go +++ b/pkg/interop/neogointernal/syscall.go @@ -1,7 +1,7 @@ package neogointernal // Syscall0 performs syscall with 0 arguments. -func Syscall0(name string) interface{} { +func Syscall0(name string) any { return nil } @@ -10,37 +10,37 @@ func Syscall0NoReturn(name string) { } // Syscall1 performs syscall with 1 arguments. -func Syscall1(name string, arg interface{}) interface{} { +func Syscall1(name string, arg any) any { return nil } // Syscall1NoReturn performs syscall with 1 arguments. -func Syscall1NoReturn(name string, arg interface{}) { +func Syscall1NoReturn(name string, arg any) { } // Syscall2 performs syscall with 2 arguments. -func Syscall2(name string, arg1, arg2 interface{}) interface{} { +func Syscall2(name string, arg1, arg2 any) any { return nil } // Syscall2NoReturn performs syscall with 2 arguments. -func Syscall2NoReturn(name string, arg1, arg2 interface{}) { +func Syscall2NoReturn(name string, arg1, arg2 any) { } // Syscall3 performs syscall with 3 arguments. -func Syscall3(name string, arg1, arg2, arg3 interface{}) interface{} { +func Syscall3(name string, arg1, arg2, arg3 any) any { return nil } // Syscall3NoReturn performs syscall with 3 arguments. -func Syscall3NoReturn(name string, arg1, arg2, arg3 interface{}) { +func Syscall3NoReturn(name string, arg1, arg2, arg3 any) { } // Syscall4 performs syscall with 4 arguments. -func Syscall4(name string, arg1, arg2, arg3, arg4 interface{}) interface{} { +func Syscall4(name string, arg1, arg2, arg3, arg4 any) any { return nil } // Syscall4NoReturn performs syscall with 4 arguments. -func Syscall4NoReturn(name string, arg1, arg2, arg3, arg4 interface{}) { +func Syscall4NoReturn(name string, arg1, arg2, arg3, arg4 any) { } diff --git a/pkg/interop/runtime/runtime.go b/pkg/interop/runtime/runtime.go index ab8415fb2..a23039473 100644 --- a/pkg/interop/runtime/runtime.go +++ b/pkg/interop/runtime/runtime.go @@ -41,7 +41,7 @@ func CheckWitness(hashOrKey []byte) bool { // script can ABORT the transaction or THROW an exception, make sure you // appropriately handle exceptions if bytecode comes from untrusted source. // This function uses `System.Runtime.LoadScript` syscall. -func LoadScript(script []byte, f contract.CallFlag, args ...interface{}) interface{} { +func LoadScript(script []byte, f contract.CallFlag, args ...any) any { return neogointernal.Syscall3("System.Runtime.LoadScript", script, f, args) } @@ -58,7 +58,7 @@ func Log(message string) { // part of contract's API to external systems, these events can be monitored // from outside and act upon accordingly. This function uses // `System.Runtime.Notify` syscall. -func Notify(name string, args ...interface{}) { +func Notify(name string, args ...any) { neogointernal.Syscall2NoReturn("System.Runtime.Notify", name, args) } @@ -105,8 +105,8 @@ func GasLeft() int { // 'nil' literal means no filtering. It returns slice consisting of following elements: // [ scripthash of notification's contract , emitted item ]. // This function uses `System.Runtime.GetNotifications` syscall. -func GetNotifications(h interop.Hash160) [][]interface{} { - return neogointernal.Syscall1("System.Runtime.GetNotifications", h).([][]interface{}) +func GetNotifications(h interop.Hash160) [][]any { + return neogointernal.Syscall1("System.Runtime.GetNotifications", h).([][]any) } // GetInvocationCounter returns how many times current contract was invoked during current tx execution. diff --git a/pkg/interop/storage/storage.go b/pkg/interop/storage/storage.go index 15f5de118..146e32104 100644 --- a/pkg/interop/storage/storage.go +++ b/pkg/interop/storage/storage.go @@ -61,25 +61,25 @@ func GetReadOnlyContext() Context { } // Put saves given value with given key in the storage using given Context. -// Even though it accepts interface{} for both, you can only pass simple types -// there like string, []byte, int or bool (not structures or slices of more -// complex types). To put more complex types there serialize them first using -// runtime.Serialize. This function uses `System.Storage.Put` syscall. -func Put(ctx Context, key interface{}, value interface{}) { +// Even though it accepts interface{} hidden under `any` for both, you can only +// pass simple types there like string, []byte, int or bool (not structures or +// slices of more complex types). To put more complex types there serialize them +// first using runtime.Serialize. This function uses `System.Storage.Put` syscall. +func Put(ctx Context, key any, value any) { neogointernal.Syscall3NoReturn("System.Storage.Put", ctx, key, value) } // Get retrieves value stored for the given key using given Context. See Put // documentation on possible key and value types. If the value is not present in // the database it returns nil. This function uses `System.Storage.Get` syscall. -func Get(ctx Context, key interface{}) interface{} { +func Get(ctx Context, key any) any { return neogointernal.Syscall2("System.Storage.Get", ctx, key) } // Delete removes key-value pair from storage by the given key using given // Context. See Put documentation on possible key types. This function uses // `System.Storage.Delete` syscall. -func Delete(ctx Context, key interface{}) { +func Delete(ctx Context, key any) { neogointernal.Syscall2NoReturn("System.Storage.Delete", ctx, key) } @@ -87,6 +87,6 @@ func Delete(ctx Context, key interface{}) { // that match the given key (contain it as a prefix). See Put documentation on // possible key types and iterator package documentation on how to use the // returned value. This function uses `System.Storage.Find` syscall. -func Find(ctx Context, key interface{}, options FindFlags) iterator.Iterator { +func Find(ctx Context, key any, options FindFlags) iterator.Iterator { return neogointernal.Syscall3("System.Storage.Find", ctx, key, options).(iterator.Iterator) } diff --git a/pkg/interop/types.go b/pkg/interop/types.go index c0ffd4ece..a99dcd413 100644 --- a/pkg/interop/types.go +++ b/pkg/interop/types.go @@ -36,14 +36,14 @@ type PublicKey []byte // Interface represents interop interface type which is needed for // transparent handling of VM-internal types (e.g. storage.Context). -type Interface interface{} +type Interface any // Equals compares Hash160 with the provided stackitem using EQUAL opcode. // The provided stackitem `b` must be either one of the primitive type (int, // bool, string, []byte) or derived from the primitive type, otherwise Equals // will fail on .(string) conversion. -func (a Hash160) Equals(b interface{}) bool { - ha := interface{}(a) +func (a Hash160) Equals(b any) bool { + ha := any(a) return bytesEquals(ha, b) } @@ -51,8 +51,8 @@ func (a Hash160) Equals(b interface{}) bool { // The provided stackitem `b` must be either one of the primitive type (int, // bool, string, []byte) or derived from the primitive type, otherwise Equals // will fail on .(string) conversion. -func (a Hash256) Equals(b interface{}) bool { - ha := interface{}(a) +func (a Hash256) Equals(b any) bool { + ha := any(a) return bytesEquals(ha, b) } @@ -60,8 +60,8 @@ func (a Hash256) Equals(b interface{}) bool { // The provided stackitem `b` must be either one of the primitive type (int, // bool, string, []byte) or derived from the primitive type, otherwise Equals // will fail on .(string) conversion. -func (a PublicKey) Equals(b interface{}) bool { - ha := interface{}(a) +func (a PublicKey) Equals(b any) bool { + ha := any(a) return bytesEquals(ha, b) } @@ -69,14 +69,14 @@ func (a PublicKey) Equals(b interface{}) bool { // The provided stackitem `b` must be either one of the primitive types (int, // bool, string, []byte) or derived from the primitive type, otherwise Equals // will fail on .(string) conversion. -func (a Signature) Equals(b interface{}) bool { - ha := interface{}(a) +func (a Signature) Equals(b any) bool { + ha := any(a) return bytesEquals(ha, b) } // bytesEquals is an internal helper function allowed to compare types that can be // converted to ByteString. -func bytesEquals(a interface{}, b interface{}) bool { +func bytesEquals(a any, b any) bool { return (a == nil && b == nil) || (a != nil && b != nil && neogointernal.Opcode2("EQUAL", a.(string), b.(string)).(bool)) } diff --git a/pkg/interop/util/util.go b/pkg/interop/util/util.go index 038b17aa9..dcd85f14c 100644 --- a/pkg/interop/util/util.go +++ b/pkg/interop/util/util.go @@ -27,12 +27,12 @@ func FromAddress(address string) interop.Hash160 { // Equals compares a with b and will return true when a and b are equal. It's // implemented as an EQUAL VM opcode, so the rules of comparison are those // of EQUAL. -func Equals(a, b interface{}) bool { +func Equals(a, b any) bool { return neogointernal.Opcode2("EQUAL", a, b).(bool) } // Remove removes element with index i from slice. // This is done in place and slice must have type other than `[]byte`. -func Remove(slice interface{}, i int) { +func Remove(slice any, i int) { neogointernal.Opcode2NoReturn("REMOVE", slice, i) } diff --git a/pkg/io/binaryReader.go b/pkg/io/binaryReader.go index 34abd7976..642eae245 100644 --- a/pkg/io/binaryReader.go +++ b/pkg/io/binaryReader.go @@ -100,7 +100,7 @@ func (r *BinReader) ReadBool() bool { // ReadArray reads an array into a value which must be // a pointer to a slice. -func (r *BinReader) ReadArray(t interface{}, maxSize ...int) { +func (r *BinReader) ReadArray(t any, maxSize ...int) { value := reflect.ValueOf(t) if value.Kind() != reflect.Ptr || value.Elem().Kind() != reflect.Slice { panic(value.Type().String() + " is not a pointer to a slice") diff --git a/pkg/io/binaryWriter.go b/pkg/io/binaryWriter.go index 6188a70d8..9abadb7cf 100644 --- a/pkg/io/binaryWriter.go +++ b/pkg/io/binaryWriter.go @@ -68,7 +68,7 @@ func (w *BinWriter) WriteBool(b bool) { // WriteArray writes a slice or an array arr into w. Note that nil slices and // empty slices are gonna be treated the same resulting in an equal zero-length // array encoded. -func (w *BinWriter) WriteArray(arr interface{}) { +func (w *BinWriter) WriteArray(arr any) { switch val := reflect.ValueOf(arr); val.Kind() { case reflect.Slice, reflect.Array: if w.Err != nil { diff --git a/pkg/io/size.go b/pkg/io/size.go index ba83a403e..25dd51686 100644 --- a/pkg/io/size.go +++ b/pkg/io/size.go @@ -38,7 +38,7 @@ func getVarIntSize(value int) int { // them with variable-length encoding that is used in Neo), strings, pointers to Serializable structures, // slices and arrays of ints/uints or Serializable structures. It's similar to GetVarSize(this T[] value) // used in C#, but differs in that it also supports things like Uint160 or Uint256. -func GetVarSize(value interface{}) int { +func GetVarSize(value any) int { v := reflect.ValueOf(value) switch v.Kind() { case reflect.String: diff --git a/pkg/io/size_test.go b/pkg/io/size_test.go index 26af4c026..66223838b 100644 --- a/pkg/io/size_test.go +++ b/pkg/io/size_test.go @@ -31,7 +31,7 @@ func (*smthNotReallySerializable) EncodeBinary(bw *io.BinWriter) { func TestVarSize(t *testing.T) { testCases := []struct { - variable interface{} + variable any name string expected int }{ @@ -189,7 +189,7 @@ func TestVarSize(t *testing.T) { } } -func panicVarSize(t *testing.T, v interface{}) { +func panicVarSize(t *testing.T, v any) { defer func() { r := recover() assert.NotNil(t, r) diff --git a/pkg/neorpc/result/validate_address.go b/pkg/neorpc/result/validate_address.go index 12c092afc..468a94cab 100644 --- a/pkg/neorpc/result/validate_address.go +++ b/pkg/neorpc/result/validate_address.go @@ -4,6 +4,6 @@ package result // Address is an interface{} here because the server echoes back whatever address // value a user has sent to it, even if it's not a string. type ValidateAddress struct { - Address interface{} `json:"address"` - IsValid bool `json:"isvalid"` + Address any `json:"address"` + IsValid bool `json:"isvalid"` } diff --git a/pkg/neorpc/rpcevent/filter.go b/pkg/neorpc/rpcevent/filter.go index 049943498..ecba3e199 100644 --- a/pkg/neorpc/rpcevent/filter.go +++ b/pkg/neorpc/rpcevent/filter.go @@ -13,13 +13,13 @@ type ( // filter notifications. Comparator interface { EventID() neorpc.EventID - Filter() interface{} + Filter() any } // Container is an interface required from notification event to be able to // pass filter. Container interface { EventID() neorpc.EventID - EventPayload() interface{} + EventPayload() any } ) diff --git a/pkg/neorpc/rpcevent/filter_test.go b/pkg/neorpc/rpcevent/filter_test.go index 6afd20d13..de56a08fc 100644 --- a/pkg/neorpc/rpcevent/filter_test.go +++ b/pkg/neorpc/rpcevent/filter_test.go @@ -17,24 +17,24 @@ import ( type ( testComparator struct { id neorpc.EventID - filter interface{} + filter any } testContainer struct { id neorpc.EventID - pld interface{} + pld any } ) func (c testComparator) EventID() neorpc.EventID { return c.id } -func (c testComparator) Filter() interface{} { +func (c testComparator) Filter() any { return c.filter } func (c testContainer) EventID() neorpc.EventID { return c.id } -func (c testContainer) EventPayload() interface{} { +func (c testContainer) EventPayload() any { return c.pld } diff --git a/pkg/neorpc/types.go b/pkg/neorpc/types.go index 223cd591c..40db91878 100644 --- a/pkg/neorpc/types.go +++ b/pkg/neorpc/types.go @@ -35,7 +35,7 @@ type ( // used by the method implementation on the server side. While JSON-RPC // technically allows it to be an object, all Neo calls expect params // to be an array. - Params []interface{} `json:"params"` + Params []any `json:"params"` // ID is an identifier associated with this request. JSON-RPC itself allows // any strings to be used for it as well, but NeoGo RPC client uses numeric // identifiers. @@ -66,9 +66,9 @@ type ( // special in that they look like requests but they don't have IDs and their // "method" is actually an event name. Notification struct { - JSONRPC string `json:"jsonrpc"` - Event EventID `json:"method"` - Payload []interface{} `json:"params"` + JSONRPC string `json:"jsonrpc"` + Event EventID `json:"method"` + Payload []any `json:"params"` } // SignerWithWitness represents transaction's signer with the corresponding witness. @@ -139,6 +139,6 @@ func (n *Notification) EventID() EventID { // EventPayload implements EventContainer interface and returns notification // object. -func (n *Notification) EventPayload() interface{} { +func (n *Notification) EventPayload() any { return n.Payload[0] } diff --git a/pkg/neotest/basic.go b/pkg/neotest/basic.go index 8c1c5b307..ce6ed44b1 100644 --- a/pkg/neotest/basic.go +++ b/pkg/neotest/basic.go @@ -80,7 +80,7 @@ func (e *Executor) NativeID(t testing.TB, name string) int32 { } // NewUnsignedTx creates a new unsigned transaction which invokes the method of the contract with the hash. -func (e *Executor) NewUnsignedTx(t testing.TB, hash util.Uint160, method string, args ...interface{}) *transaction.Transaction { +func (e *Executor) NewUnsignedTx(t testing.TB, hash util.Uint160, method string, args ...any) *transaction.Transaction { script, err := smartcontract.CreateCallScript(hash, method, args...) require.NoError(t, err) @@ -93,7 +93,7 @@ func (e *Executor) NewUnsignedTx(t testing.TB, hash util.Uint160, method string, // NewTx creates a new transaction which invokes the contract method. // The transaction is signed by the signers. func (e *Executor) NewTx(t testing.TB, signers []Signer, - hash util.Uint160, method string, args ...interface{}) *transaction.Transaction { + hash util.Uint160, method string, args ...any) *transaction.Transaction { tx := e.NewUnsignedTx(t, hash, method, args...) return e.SignTx(t, tx, -1, signers...) } @@ -137,7 +137,7 @@ func (e *Executor) NewAccount(t testing.TB, expectedGASBalance ...int64) Signer // the precalculated contract hash matches the actual one. // data is an optional argument to `_deploy`. // It returns the hash of the deploy transaction. -func (e *Executor) DeployContract(t testing.TB, c *Contract, data interface{}) util.Uint256 { +func (e *Executor) DeployContract(t testing.TB, c *Contract, data any) util.Uint256 { return e.DeployContractBy(t, e.Validator, c, data) } @@ -145,7 +145,7 @@ func (e *Executor) DeployContract(t testing.TB, c *Contract, data interface{}) u // It also checks that the precalculated contract hash matches the actual one. // data is an optional argument to `_deploy`. // It returns the hash of the deploy transaction. -func (e *Executor) DeployContractBy(t testing.TB, signer Signer, c *Contract, data interface{}) util.Uint256 { +func (e *Executor) DeployContractBy(t testing.TB, signer Signer, c *Contract, data any) util.Uint256 { tx := NewDeployTxBy(t, e.Chain, signer, c, data) e.AddNewBlock(t, tx) e.CheckHalt(t, tx.Hash()) @@ -164,7 +164,7 @@ func (e *Executor) DeployContractBy(t testing.TB, signer Signer, c *Contract, da // DeployContractCheckFAULT compiles and deploys a contract to the bc using the validator // account. It checks that the deploy transaction FAULTed with the specified error. -func (e *Executor) DeployContractCheckFAULT(t testing.TB, c *Contract, data interface{}, errMessage string) { +func (e *Executor) DeployContractCheckFAULT(t testing.TB, c *Contract, data any, errMessage string) { tx := e.NewDeployTx(t, e.Chain, c, data) e.AddNewBlock(t, tx) e.CheckFault(t, tx.Hash(), errMessage) @@ -253,12 +253,12 @@ func (e *Executor) EnsureGASBalance(t testing.TB, acc util.Uint160, isOk func(ba } // NewDeployTx returns a new deployment tx for the contract signed by the committee. -func (e *Executor) NewDeployTx(t testing.TB, bc *core.Blockchain, c *Contract, data interface{}) *transaction.Transaction { +func (e *Executor) NewDeployTx(t testing.TB, bc *core.Blockchain, c *Contract, data any) *transaction.Transaction { return NewDeployTxBy(t, bc, e.Validator, c, data) } // NewDeployTxBy returns a new deployment tx for the contract signed by the specified signer. -func NewDeployTxBy(t testing.TB, bc *core.Blockchain, signer Signer, c *Contract, data interface{}) *transaction.Transaction { +func NewDeployTxBy(t testing.TB, bc *core.Blockchain, signer Signer, c *Contract, data any) *transaction.Transaction { rawManifest, err := json.Marshal(c.Manifest) require.NoError(t, err) diff --git a/pkg/neotest/client.go b/pkg/neotest/client.go index 25ac8c158..9596c12cb 100644 --- a/pkg/neotest/client.go +++ b/pkg/neotest/client.go @@ -48,7 +48,7 @@ func (e *Executor) ValidatorInvoker(h util.Uint160) *ContractInvoker { } // TestInvoke creates test the VM and invokes the method with the args. -func (c *ContractInvoker) TestInvoke(t testing.TB, method string, args ...interface{}) (*vm.Stack, error) { +func (c *ContractInvoker) TestInvoke(t testing.TB, method string, args ...any) (*vm.Stack, error) { tx := c.PrepareInvokeNoSign(t, method, args...) b := c.NewUnsignedBlock(t, tx) ic, err := c.Chain.GetTestVM(trigger.Application, tx, b) @@ -70,18 +70,18 @@ func (c *ContractInvoker) WithSigners(signers ...Signer) *ContractInvoker { } // PrepareInvoke creates a new invocation transaction. -func (c *ContractInvoker) PrepareInvoke(t testing.TB, method string, args ...interface{}) *transaction.Transaction { +func (c *ContractInvoker) PrepareInvoke(t testing.TB, method string, args ...any) *transaction.Transaction { return c.Executor.NewTx(t, c.Signers, c.Hash, method, args...) } // PrepareInvokeNoSign creates a new unsigned invocation transaction. -func (c *ContractInvoker) PrepareInvokeNoSign(t testing.TB, method string, args ...interface{}) *transaction.Transaction { +func (c *ContractInvoker) PrepareInvokeNoSign(t testing.TB, method string, args ...any) *transaction.Transaction { return c.Executor.NewUnsignedTx(t, c.Hash, method, args...) } // Invoke invokes the method with the args, persists the transaction and checks the result. // Returns transaction hash. -func (c *ContractInvoker) Invoke(t testing.TB, result interface{}, method string, args ...interface{}) util.Uint256 { +func (c *ContractInvoker) Invoke(t testing.TB, result any, method string, args ...any) util.Uint256 { tx := c.PrepareInvoke(t, method, args...) c.AddNewBlock(t, tx) c.CheckHalt(t, tx.Hash(), stackitem.Make(result)) @@ -90,7 +90,7 @@ func (c *ContractInvoker) Invoke(t testing.TB, result interface{}, method string // InvokeAndCheck invokes the method with the args, persists the transaction and checks the result // using the provided function. It returns the transaction hash. -func (c *ContractInvoker) InvokeAndCheck(t testing.TB, checkResult func(t testing.TB, stack []stackitem.Item), method string, args ...interface{}) util.Uint256 { +func (c *ContractInvoker) InvokeAndCheck(t testing.TB, checkResult func(t testing.TB, stack []stackitem.Item), method string, args ...any) util.Uint256 { tx := c.PrepareInvoke(t, method, args...) c.AddNewBlock(t, tx) aer, err := c.Chain.GetAppExecResults(tx.Hash(), trigger.Application) @@ -103,7 +103,7 @@ func (c *ContractInvoker) InvokeAndCheck(t testing.TB, checkResult func(t testin } // InvokeWithFeeFail is like InvokeFail but sets the custom system fee for the transaction. -func (c *ContractInvoker) InvokeWithFeeFail(t testing.TB, message string, sysFee int64, method string, args ...interface{}) util.Uint256 { +func (c *ContractInvoker) InvokeWithFeeFail(t testing.TB, message string, sysFee int64, method string, args ...any) util.Uint256 { tx := c.PrepareInvokeNoSign(t, method, args...) c.Executor.SignTx(t, tx, sysFee, c.Signers...) c.AddNewBlock(t, tx) @@ -113,7 +113,7 @@ func (c *ContractInvoker) InvokeWithFeeFail(t testing.TB, message string, sysFee // InvokeFail invokes the method with the args, persists the transaction and checks the error message. // It returns the transaction hash. -func (c *ContractInvoker) InvokeFail(t testing.TB, message string, method string, args ...interface{}) util.Uint256 { +func (c *ContractInvoker) InvokeFail(t testing.TB, message string, method string, args ...any) util.Uint256 { tx := c.PrepareInvoke(t, method, args...) c.AddNewBlock(t, tx) c.CheckFault(t, tx.Hash(), message) diff --git a/pkg/network/server.go b/pkg/network/server.go index ca37d774f..0ce3697d5 100644 --- a/pkg/network/server.go +++ b/pkg/network/server.go @@ -73,7 +73,7 @@ type ( HeaderHeight() uint32 P2PSigExtensionsEnabled() bool PoolTx(t *transaction.Transaction, pools ...*mempool.Pool) error - PoolTxWithData(t *transaction.Transaction, data interface{}, mp *mempool.Pool, feer mempool.Feer, verificationFunction func(t *transaction.Transaction, data interface{}) error) error + PoolTxWithData(t *transaction.Transaction, data any, mp *mempool.Pool, feer mempool.Feer, verificationFunction func(t *transaction.Transaction, data any) error) error RegisterPostBlock(f func(func(*transaction.Transaction, *mempool.Pool, bool) bool, *mempool.Pool, *block.Block)) SubscribeForBlocks(ch chan *block.Block) UnsubscribeFromBlocks(ch chan *block.Block) @@ -1189,7 +1189,7 @@ func (s *Server) verifyAndPoolNotaryRequest(r *payload.P2PNotaryRequest) error { } // verifyNotaryRequest is a function for state-dependant P2PNotaryRequest payload verification which is executed before ordinary blockchain's verification. -func (s *Server) verifyNotaryRequest(_ *transaction.Transaction, data interface{}) error { +func (s *Server) verifyNotaryRequest(_ *transaction.Transaction, data any) error { r := data.(*payload.P2PNotaryRequest) payer := r.FallbackTransaction.Signers[1].Account if _, err := s.chain.VerifyWitness(payer, r, &r.Witness, s.chain.GetMaxVerificationGAS()); err != nil { @@ -1206,7 +1206,7 @@ func (s *Server) verifyNotaryRequest(_ *transaction.Transaction, data interface{ return nil } -func (s *Server) broadcastP2PNotaryRequestPayload(_ *transaction.Transaction, data interface{}) { +func (s *Server) broadcastP2PNotaryRequestPayload(_ *transaction.Transaction, data any) { r := data.(*payload.P2PNotaryRequest) // we can guarantee that cast is successful msg := NewMessage(CMDInv, payload.NewInventory(payload.P2PNotaryRequestType, []util.Uint256{r.FallbackTransaction.Hash()})) s.broadcastMessage(msg) @@ -1592,7 +1592,7 @@ func (s *Server) RelayTxn(t *transaction.Transaction) error { } // broadcastTX broadcasts an inventory message about new transaction. -func (s *Server) broadcastTX(t *transaction.Transaction, _ interface{}) { +func (s *Server) broadcastTX(t *transaction.Transaction, _ any) { select { case s.transactions <- t: case <-s.quit: diff --git a/pkg/rpcclient/actor/actor.go b/pkg/rpcclient/actor/actor.go index f8926a958..35ae9346a 100644 --- a/pkg/rpcclient/actor/actor.go +++ b/pkg/rpcclient/actor/actor.go @@ -245,7 +245,7 @@ func (a *Actor) sendWrapper(tx *transaction.Transaction, err error) (util.Uint25 // SendCall creates a transaction that calls the given method of the given // contract with the given parameters (see also MakeCall) and sends it to the // network. -func (a *Actor) SendCall(contract util.Uint160, method string, params ...interface{}) (util.Uint256, uint32, error) { +func (a *Actor) SendCall(contract util.Uint160, method string, params ...any) (util.Uint256, uint32, error) { return a.sendWrapper(a.MakeCall(contract, method, params...)) } @@ -253,7 +253,7 @@ func (a *Actor) SendCall(contract util.Uint160, method string, params ...interfa // contract with the given parameters (see also MakeTunedCall) and attributes, // allowing to check for execution results of this call and modify transaction // before it's signed; this transaction is then sent to the network. -func (a *Actor) SendTunedCall(contract util.Uint160, method string, attrs []transaction.Attribute, txHook TransactionCheckerModifier, params ...interface{}) (util.Uint256, uint32, error) { +func (a *Actor) SendTunedCall(contract util.Uint160, method string, attrs []transaction.Attribute, txHook TransactionCheckerModifier, params ...any) (util.Uint256, uint32, error) { return a.sendWrapper(a.MakeTunedCall(contract, method, attrs, txHook, params...)) } diff --git a/pkg/rpcclient/actor/maker.go b/pkg/rpcclient/actor/maker.go index d185dd1fd..38b9d92fe 100644 --- a/pkg/rpcclient/actor/maker.go +++ b/pkg/rpcclient/actor/maker.go @@ -52,7 +52,7 @@ func DefaultCheckerModifier(r *result.Invoke, t *transaction.Transaction) error // Actor-configured TransactionCheckerModifier. The resulting transaction has // Actor-configured attributes added as well. If you need to override attributes // and/or TransactionCheckerModifier use MakeTunedCall. -func (a *Actor) MakeCall(contract util.Uint160, method string, params ...interface{}) (*transaction.Transaction, error) { +func (a *Actor) MakeCall(contract util.Uint160, method string, params ...any) (*transaction.Transaction, error) { return a.MakeTunedCall(contract, method, nil, nil, params...) } @@ -61,7 +61,7 @@ func (a *Actor) MakeCall(contract util.Uint160, method string, params ...interfa // parameters. It's filtered through the provided callback (or Actor default // one's if nil, see TransactionCheckerModifier documentation also), so the // process can be aborted and transaction can be modified before signing. -func (a *Actor) MakeTunedCall(contract util.Uint160, method string, attrs []transaction.Attribute, txHook TransactionCheckerModifier, params ...interface{}) (*transaction.Transaction, error) { +func (a *Actor) MakeTunedCall(contract util.Uint160, method string, attrs []transaction.Attribute, txHook TransactionCheckerModifier, params ...any) (*transaction.Transaction, error) { r, err := a.Call(contract, method, params...) return a.makeUncheckedWrapper(r, err, attrs, txHook) } @@ -130,7 +130,7 @@ func (a *Actor) MakeUncheckedRun(script []byte, sysfee int64, attrs []transactio // transaction returned has correct SystemFee and NetworkFee values. // TransactionModifier is not applied to the result of this method, but default // attributes are used if attrs is nil. -func (a *Actor) MakeUnsignedCall(contract util.Uint160, method string, attrs []transaction.Attribute, params ...interface{}) (*transaction.Transaction, error) { +func (a *Actor) MakeUnsignedCall(contract util.Uint160, method string, attrs []transaction.Attribute, params ...any) (*transaction.Transaction, error) { r, err := a.Call(contract, method, params...) return a.makeUnsignedWrapper(r, err, attrs) } diff --git a/pkg/rpcclient/actor/waiter.go b/pkg/rpcclient/actor/waiter.go index 8de06a6a8..d37b4383b 100644 --- a/pkg/rpcclient/actor/waiter.go +++ b/pkg/rpcclient/actor/waiter.go @@ -331,10 +331,10 @@ func (w *EventWaiter) WaitAny(ctx context.Context, vub uint32, hashes ...util.Ui case unsubErr := <-unsubErrs: if unsubErr != nil { errFmt := "unsubscription error: %v" - errArgs := []interface{}{unsubErr} + errArgs := []any{unsubErr} if waitErr != nil { errFmt = "%w; " + errFmt - errArgs = append([]interface{}{waitErr}, errArgs...) + errArgs = append([]any{waitErr}, errArgs...) } waitErr = fmt.Errorf(errFmt, errArgs...) } diff --git a/pkg/rpcclient/client.go b/pkg/rpcclient/client.go index 67cf3f10d..9c67ad43a 100644 --- a/pkg/rpcclient/client.go +++ b/pkg/rpcclient/client.go @@ -181,9 +181,9 @@ func (c *Client) Close() { c.cli.CloseIdleConnections() } -func (c *Client) performRequest(method string, p []interface{}, v interface{}) error { +func (c *Client) performRequest(method string, p []any, v any) error { if p == nil { - p = []interface{}{} // neo-project/neo-modules#742 + p = []any{} // neo-project/neo-modules#742 } var r = neorpc.Request{ JSONRPC: neorpc.JSONRPCVersion, diff --git a/pkg/rpcclient/gas/gas_test.go b/pkg/rpcclient/gas/gas_test.go index eb49affda..3ca49e5c5 100644 --- a/pkg/rpcclient/gas/gas_test.go +++ b/pkg/rpcclient/gas/gas_test.go @@ -17,7 +17,7 @@ type testAct struct { vub uint32 } -func (t *testAct) Call(contract util.Uint160, operation string, params ...interface{}) (*result.Invoke, error) { +func (t *testAct) Call(contract util.Uint160, operation string, params ...any) (*result.Invoke, error) { return t.res, t.err } func (t *testAct) MakeRun(script []byte) (*transaction.Transaction, error) { diff --git a/pkg/rpcclient/helper.go b/pkg/rpcclient/helper.go index 587816c93..af394cde9 100644 --- a/pkg/rpcclient/helper.go +++ b/pkg/rpcclient/helper.go @@ -36,7 +36,7 @@ func (c *Client) InvokeAndPackIteratorResults(contract util.Uint160, operation s if err != nil { return nil, fmt.Errorf("expanding params to emitable: %w", err) } - bytes, err := smartcontract.CreateCallAndUnwrapIteratorScript(contract, operation, max, values.([]interface{})...) + bytes, err := smartcontract.CreateCallAndUnwrapIteratorScript(contract, operation, max, values.([]any)...) if err != nil { return nil, fmt.Errorf("failed to create iterator unwrapper script: %w", err) } diff --git a/pkg/rpcclient/invoker/invoker.go b/pkg/rpcclient/invoker/invoker.go index dfab2c803..a56be5942 100644 --- a/pkg/rpcclient/invoker/invoker.go +++ b/pkg/rpcclient/invoker/invoker.go @@ -139,7 +139,7 @@ func (h *historicConverter) TraverseIterator(sessionID, iteratorID uuid.UUID, ma // Call invokes a method of the contract with the given parameters (and // Invoker-specific list of signers) and returns the result as is. -func (v *Invoker) Call(contract util.Uint160, operation string, params ...interface{}) (*result.Invoke, error) { +func (v *Invoker) Call(contract util.Uint160, operation string, params ...any) (*result.Invoke, error) { ps, err := smartcontract.NewParametersFromValues(params...) if err != nil { return nil, err @@ -155,7 +155,7 @@ func (v *Invoker) Call(contract util.Uint160, operation string, params ...interf // result of the whole script is an array containing up to maxResultItems elements // from the iterator returned from the contract's method call. This script is executed // using regular JSON-API (according to the way Iterator is set up). -func (v *Invoker) CallAndExpandIterator(contract util.Uint160, method string, maxItems int, params ...interface{}) (*result.Invoke, error) { +func (v *Invoker) CallAndExpandIterator(contract util.Uint160, method string, maxItems int, params ...any) (*result.Invoke, error) { bytes, err := smartcontract.CreateCallAndUnwrapIteratorScript(contract, method, maxItems, params...) if err != nil { return nil, fmt.Errorf("iterator unwrapper script: %w", err) @@ -165,7 +165,7 @@ func (v *Invoker) CallAndExpandIterator(contract util.Uint160, method string, ma // Verify invokes contract's verify method in the verification context with // Invoker-specific signers and given witnesses and parameters. -func (v *Invoker) Verify(contract util.Uint160, witnesses []transaction.Witness, params ...interface{}) (*result.Invoke, error) { +func (v *Invoker) Verify(contract util.Uint160, witnesses []transaction.Witness, params ...any) (*result.Invoke, error) { ps, err := smartcontract.NewParametersFromValues(params...) if err != nil { return nil, err diff --git a/pkg/rpcclient/local.go b/pkg/rpcclient/local.go index 19e67ceaa..345566d71 100644 --- a/pkg/rpcclient/local.go +++ b/pkg/rpcclient/local.go @@ -34,7 +34,7 @@ func NewInternal(ctx context.Context, register InternalHook) (*Internal, error) done: make(chan struct{}), closeCalled: *atomic.NewBool(false), subscriptions: make(map[string]notificationReceiver), - receivers: make(map[interface{}][]string), + receivers: make(map[any][]string), }, events: make(chan neorpc.Notification), } diff --git a/pkg/rpcclient/management/management.go b/pkg/rpcclient/management/management.go index 6c8e375f9..c6d2e77ef 100644 --- a/pkg/rpcclient/management/management.go +++ b/pkg/rpcclient/management/management.go @@ -27,8 +27,8 @@ import ( // Invoker is used by ContractReader to call various methods. type Invoker interface { - Call(contract util.Uint160, operation string, params ...interface{}) (*result.Invoke, error) - CallAndExpandIterator(contract util.Uint160, method string, maxItems int, params ...interface{}) (*result.Invoke, error) + Call(contract util.Uint160, operation string, params ...any) (*result.Invoke, error) + CallAndExpandIterator(contract util.Uint160, method string, maxItems int, params ...any) (*result.Invoke, error) TerminateSession(sessionID uuid.UUID) error TraverseIterator(sessionID uuid.UUID, iterator *result.Iterator, num int) ([]stackitem.Item, error) } @@ -37,11 +37,11 @@ type Invoker interface { type Actor interface { Invoker - MakeCall(contract util.Uint160, method string, params ...interface{}) (*transaction.Transaction, error) + MakeCall(contract util.Uint160, method string, params ...any) (*transaction.Transaction, error) MakeRun(script []byte) (*transaction.Transaction, error) - MakeUnsignedCall(contract util.Uint160, method string, attrs []transaction.Attribute, params ...interface{}) (*transaction.Transaction, error) + MakeUnsignedCall(contract util.Uint160, method string, attrs []transaction.Attribute, params ...any) (*transaction.Transaction, error) MakeUnsignedRun(script []byte, attrs []transaction.Attribute) (*transaction.Transaction, error) - SendCall(contract util.Uint160, method string, params ...interface{}) (util.Uint256, uint32, error) + SendCall(contract util.Uint160, method string, params ...any) (util.Uint256, uint32, error) SendRun(script []byte) (util.Uint256, uint32, error) } @@ -222,7 +222,7 @@ func (c *ContractReader) HasMethod(hash util.Uint160, method string, pcount int) // to the invocation and will be used for "_deploy" method invocation done by // the ContractManagement contract. If successful, this method returns deployed // contract state that can be retrieved from the stack after execution. -func (c *Contract) Deploy(exe *nef.File, manif *manifest.Manifest, data interface{}) (util.Uint256, uint32, error) { +func (c *Contract) Deploy(exe *nef.File, manif *manifest.Manifest, data any) (util.Uint256, uint32, error) { script, err := mkDeployScript(exe, manif, data) if err != nil { return util.Uint256{}, 0, err @@ -235,7 +235,7 @@ func (c *Contract) Deploy(exe *nef.File, manif *manifest.Manifest, data interfac // to the invocation and will be used for "_deploy" method invocation done by // the ContractManagement contract. If successful, this method returns deployed // contract state that can be retrieved from the stack after execution. -func (c *Contract) DeployTransaction(exe *nef.File, manif *manifest.Manifest, data interface{}) (*transaction.Transaction, error) { +func (c *Contract) DeployTransaction(exe *nef.File, manif *manifest.Manifest, data any) (*transaction.Transaction, error) { script, err := mkDeployScript(exe, manif, data) if err != nil { return nil, err @@ -248,7 +248,7 @@ func (c *Contract) DeployTransaction(exe *nef.File, manif *manifest.Manifest, da // to the invocation and will be used for "_deploy" method invocation done by // the ContractManagement contract. If successful, this method returns deployed // contract state that can be retrieved from the stack after execution. -func (c *Contract) DeployUnsigned(exe *nef.File, manif *manifest.Manifest, data interface{}) (*transaction.Transaction, error) { +func (c *Contract) DeployUnsigned(exe *nef.File, manif *manifest.Manifest, data any) (*transaction.Transaction, error) { script, err := mkDeployScript(exe, manif, data) if err != nil { return nil, err @@ -256,7 +256,7 @@ func (c *Contract) DeployUnsigned(exe *nef.File, manif *manifest.Manifest, data return c.actor.MakeUnsignedRun(script, nil) } -func mkDeployScript(exe *nef.File, manif *manifest.Manifest, data interface{}) ([]byte, error) { +func mkDeployScript(exe *nef.File, manif *manifest.Manifest, data any) ([]byte, error) { exeB, err := exe.Bytes() if err != nil { return nil, fmt.Errorf("bad NEF: %w", err) diff --git a/pkg/rpcclient/management/management_test.go b/pkg/rpcclient/management/management_test.go index 31a54484d..f30531972 100644 --- a/pkg/rpcclient/management/management_test.go +++ b/pkg/rpcclient/management/management_test.go @@ -23,16 +23,16 @@ type testAct struct { vub uint32 } -func (t *testAct) Call(contract util.Uint160, operation string, params ...interface{}) (*result.Invoke, error) { +func (t *testAct) Call(contract util.Uint160, operation string, params ...any) (*result.Invoke, error) { return t.res, t.err } -func (t *testAct) MakeCall(contract util.Uint160, method string, params ...interface{}) (*transaction.Transaction, error) { +func (t *testAct) MakeCall(contract util.Uint160, method string, params ...any) (*transaction.Transaction, error) { return t.tx, t.err } -func (t *testAct) MakeUnsignedCall(contract util.Uint160, method string, attrs []transaction.Attribute, params ...interface{}) (*transaction.Transaction, error) { +func (t *testAct) MakeUnsignedCall(contract util.Uint160, method string, attrs []transaction.Attribute, params ...any) (*transaction.Transaction, error) { return t.tx, t.err } -func (t *testAct) SendCall(contract util.Uint160, method string, params ...interface{}) (util.Uint256, uint32, error) { +func (t *testAct) SendCall(contract util.Uint160, method string, params ...any) (util.Uint256, uint32, error) { return t.txh, t.vub, t.err } func (t *testAct) MakeRun(script []byte) (*transaction.Transaction, error) { @@ -44,7 +44,7 @@ func (t *testAct) MakeUnsignedRun(script []byte, attrs []transaction.Attribute) func (t *testAct) SendRun(script []byte) (util.Uint256, uint32, error) { return t.txh, t.vub, t.err } -func (t *testAct) CallAndExpandIterator(contract util.Uint160, method string, maxItems int, params ...interface{}) (*result.Invoke, error) { +func (t *testAct) CallAndExpandIterator(contract util.Uint160, method string, maxItems int, params ...any) (*result.Invoke, error) { return t.res, t.err } func (t *testAct) TerminateSession(sessionID uuid.UUID) error { @@ -283,7 +283,7 @@ func TestDeploy(t *testing.T) { _, _, err := man.Deploy(nefFile, manif, nil) require.Error(t, err) - for _, m := range []func(exe *nef.File, manif *manifest.Manifest, data interface{}) (*transaction.Transaction, error){ + for _, m := range []func(exe *nef.File, manif *manifest.Manifest, data any) (*transaction.Transaction, error){ man.DeployTransaction, man.DeployUnsigned, } { @@ -301,7 +301,7 @@ func TestDeploy(t *testing.T) { require.Equal(t, ta.vub, vub) ta.tx = transaction.New([]byte{1, 2, 3}, 100500) - for _, m := range []func(exe *nef.File, manif *manifest.Manifest, data interface{}) (*transaction.Transaction, error){ + for _, m := range []func(exe *nef.File, manif *manifest.Manifest, data any) (*transaction.Transaction, error){ man.DeployTransaction, man.DeployUnsigned, } { diff --git a/pkg/rpcclient/neo/neo.go b/pkg/rpcclient/neo/neo.go index b9b17ed33..3da8b47a0 100644 --- a/pkg/rpcclient/neo/neo.go +++ b/pkg/rpcclient/neo/neo.go @@ -33,7 +33,7 @@ const ( type Invoker interface { nep17.Invoker - CallAndExpandIterator(contract util.Uint160, method string, maxItems int, params ...interface{}) (*result.Invoke, error) + CallAndExpandIterator(contract util.Uint160, method string, maxItems int, params ...any) (*result.Invoke, error) TerminateSession(sessionID uuid.UUID) error TraverseIterator(sessionID uuid.UUID, iterator *result.Iterator, num int) ([]stackitem.Item, error) } @@ -44,10 +44,10 @@ type Actor interface { Invoker Run(script []byte) (*result.Invoke, error) - MakeCall(contract util.Uint160, method string, params ...interface{}) (*transaction.Transaction, error) - MakeUnsignedCall(contract util.Uint160, method string, attrs []transaction.Attribute, params ...interface{}) (*transaction.Transaction, error) + MakeCall(contract util.Uint160, method string, params ...any) (*transaction.Transaction, error) + MakeUnsignedCall(contract util.Uint160, method string, attrs []transaction.Attribute, params ...any) (*transaction.Transaction, error) MakeUnsignedUncheckedRun(script []byte, sysFee int64, attrs []transaction.Attribute) (*transaction.Transaction, error) - SendCall(contract util.Uint160, method string, params ...interface{}) (util.Uint256, uint32, error) + SendCall(contract util.Uint160, method string, params ...any) (util.Uint256, uint32, error) Sign(tx *transaction.Transaction) error SignAndSend(tx *transaction.Transaction) (util.Uint256, uint32, error) } @@ -398,7 +398,7 @@ func (c *Contract) VoteUnsigned(account util.Uint160, voteTo *keys.PublicKey) (* } func voteScript(account util.Uint160, voteTo *keys.PublicKey) []byte { - var param interface{} + var param any if voteTo != nil { param = voteTo.Bytes() diff --git a/pkg/rpcclient/neo/neo_test.go b/pkg/rpcclient/neo/neo_test.go index 5cf7e8235..d99dc86f9 100644 --- a/pkg/rpcclient/neo/neo_test.go +++ b/pkg/rpcclient/neo/neo_test.go @@ -27,7 +27,7 @@ type testAct struct { inv *result.Invoke } -func (t *testAct) Call(contract util.Uint160, operation string, params ...interface{}) (*result.Invoke, error) { +func (t *testAct) Call(contract util.Uint160, operation string, params ...any) (*result.Invoke, error) { return t.res, t.err } func (t *testAct) MakeRun(script []byte) (*transaction.Transaction, error) { @@ -39,13 +39,13 @@ func (t *testAct) MakeUnsignedRun(script []byte, attrs []transaction.Attribute) func (t *testAct) SendRun(script []byte) (util.Uint256, uint32, error) { return t.txh, t.vub, t.err } -func (t *testAct) MakeCall(contract util.Uint160, method string, params ...interface{}) (*transaction.Transaction, error) { +func (t *testAct) MakeCall(contract util.Uint160, method string, params ...any) (*transaction.Transaction, error) { return t.tx, t.err } -func (t *testAct) MakeUnsignedCall(contract util.Uint160, method string, attrs []transaction.Attribute, params ...interface{}) (*transaction.Transaction, error) { +func (t *testAct) MakeUnsignedCall(contract util.Uint160, method string, attrs []transaction.Attribute, params ...any) (*transaction.Transaction, error) { return t.tx, t.err } -func (t *testAct) SendCall(contract util.Uint160, method string, params ...interface{}) (util.Uint256, uint32, error) { +func (t *testAct) SendCall(contract util.Uint160, method string, params ...any) (util.Uint256, uint32, error) { return t.txh, t.vub, t.err } func (t *testAct) Run(script []byte) (*result.Invoke, error) { @@ -60,7 +60,7 @@ func (t *testAct) Sign(tx *transaction.Transaction) error { func (t *testAct) SignAndSend(tx *transaction.Transaction) (util.Uint256, uint32, error) { return t.txh, t.vub, t.err } -func (t *testAct) CallAndExpandIterator(contract util.Uint160, method string, maxItems int, params ...interface{}) (*result.Invoke, error) { +func (t *testAct) CallAndExpandIterator(contract util.Uint160, method string, maxItems int, params ...any) (*result.Invoke, error) { return t.inv, t.err } func (t *testAct) TerminateSession(sessionID uuid.UUID) error { diff --git a/pkg/rpcclient/nep.go b/pkg/rpcclient/nep.go index 4b2497315..3fa41a913 100644 --- a/pkg/rpcclient/nep.go +++ b/pkg/rpcclient/nep.go @@ -25,7 +25,7 @@ func (c *Client) nepTotalSupply(tokenHash util.Uint160) (int64, error) { // nepBalanceOf invokes `balanceOf` NEP* method on the specified contract. func (c *Client) nepBalanceOf(tokenHash, acc util.Uint160, tokenID []byte) (int64, error) { - params := []interface{}{acc} + params := []any{acc} if tokenID != nil { params = append(params, tokenID) } diff --git a/pkg/rpcclient/nep11.go b/pkg/rpcclient/nep11.go index 723922759..e80999c04 100644 --- a/pkg/rpcclient/nep11.go +++ b/pkg/rpcclient/nep11.go @@ -62,7 +62,7 @@ func (c *Client) NEP11TokenInfo(tokenHash util.Uint160) (*wallet.Token, error) { // Deprecated: please use nep11 package, this method will be removed in future // versions. func (c *Client) TransferNEP11(acc *wallet.Account, to util.Uint160, - tokenHash util.Uint160, tokenID string, data interface{}, gas int64, cosigners []SignerAccount) (util.Uint256, error) { + tokenHash util.Uint160, tokenID string, data any, gas int64, cosigners []SignerAccount) (util.Uint256, error) { tx, err := c.CreateNEP11TransferTx(acc, tokenHash, gas, cosigners, to, tokenID, data) if err != nil { return util.Uint256{}, err @@ -82,7 +82,7 @@ func (c *Client) TransferNEP11(acc *wallet.Account, to util.Uint160, // Deprecated: please use nep11 package, this method will be removed in future // versions. func (c *Client) CreateNEP11TransferTx(acc *wallet.Account, tokenHash util.Uint160, - gas int64, cosigners []SignerAccount, args ...interface{}) (*transaction.Transaction, error) { + gas int64, cosigners []SignerAccount, args ...any) (*transaction.Transaction, error) { script, err := smartcontract.CreateCallWithAssertScript(tokenHash, "transfer", args...) if err != nil { return nil, fmt.Errorf("failed to create NEP-11 transfer script: %w", err) @@ -142,7 +142,7 @@ func (c *Client) NEP11NDOwnerOf(tokenHash util.Uint160, tokenID []byte) (util.Ui // Deprecated: please use nep11 package, this method will be removed in future // versions. func (c *Client) TransferNEP11D(acc *wallet.Account, to util.Uint160, - tokenHash util.Uint160, amount int64, tokenID []byte, data interface{}, gas int64, cosigners []SignerAccount) (util.Uint256, error) { + tokenHash util.Uint160, amount int64, tokenID []byte, data any, gas int64, cosigners []SignerAccount) (util.Uint256, error) { tx, err := c.CreateNEP11TransferTx(acc, tokenHash, gas, cosigners, acc.ScriptHash(), to, amount, tokenID, data) if err != nil { return util.Uint256{}, err diff --git a/pkg/rpcclient/nep11/base.go b/pkg/rpcclient/nep11/base.go index 71c75ef7a..ed30df2af 100644 --- a/pkg/rpcclient/nep11/base.go +++ b/pkg/rpcclient/nep11/base.go @@ -28,7 +28,7 @@ import ( type Invoker interface { neptoken.Invoker - CallAndExpandIterator(contract util.Uint160, method string, maxItems int, params ...interface{}) (*result.Invoke, error) + CallAndExpandIterator(contract util.Uint160, method string, maxItems int, params ...any) (*result.Invoke, error) TerminateSession(sessionID uuid.UUID) error TraverseIterator(sessionID uuid.UUID, iterator *result.Iterator, num int) ([]stackitem.Item, error) } @@ -149,7 +149,7 @@ func (t *BaseReader) TokensOfExpanded(account util.Uint160, num int) ([][]byte, // transaction if it's not true. It works for divisible NFTs only when there is // one owner for the particular token. The returned values are transaction hash, // its ValidUntilBlock value and an error if any. -func (t *BaseWriter) Transfer(to util.Uint160, id []byte, data interface{}) (util.Uint256, uint32, error) { +func (t *BaseWriter) Transfer(to util.Uint160, id []byte, data any) (util.Uint256, uint32, error) { script, err := t.transferScript(to, id, data) if err != nil { return util.Uint256{}, 0, err @@ -162,7 +162,7 @@ func (t *BaseWriter) Transfer(to util.Uint160, id []byte, data interface{}) (uti // transaction if it's not true. It works for divisible NFTs only when there is // one owner for the particular token. This transaction is signed, but not sent // to the network, instead it's returned to the caller. -func (t *BaseWriter) TransferTransaction(to util.Uint160, id []byte, data interface{}) (*transaction.Transaction, error) { +func (t *BaseWriter) TransferTransaction(to util.Uint160, id []byte, data any) (*transaction.Transaction, error) { script, err := t.transferScript(to, id, data) if err != nil { return nil, err @@ -175,7 +175,7 @@ func (t *BaseWriter) TransferTransaction(to util.Uint160, id []byte, data interf // transaction if it's not true. It works for divisible NFTs only when there is // one owner for the particular token. This transaction is not signed and just // returned to the caller. -func (t *BaseWriter) TransferUnsigned(to util.Uint160, id []byte, data interface{}) (*transaction.Transaction, error) { +func (t *BaseWriter) TransferUnsigned(to util.Uint160, id []byte, data any) (*transaction.Transaction, error) { script, err := t.transferScript(to, id, data) if err != nil { return nil, err @@ -183,7 +183,7 @@ func (t *BaseWriter) TransferUnsigned(to util.Uint160, id []byte, data interface return t.actor.MakeUnsignedRun(script, nil) } -func (t *BaseWriter) transferScript(params ...interface{}) ([]byte, error) { +func (t *BaseWriter) transferScript(params ...any) ([]byte, error) { return smartcontract.CreateCallWithAssertScript(t.hash, "transfer", params...) } diff --git a/pkg/rpcclient/nep11/base_test.go b/pkg/rpcclient/nep11/base_test.go index 33938c0aa..9ba9b3aa2 100644 --- a/pkg/rpcclient/nep11/base_test.go +++ b/pkg/rpcclient/nep11/base_test.go @@ -21,7 +21,7 @@ type testAct struct { vub uint32 } -func (t *testAct) Call(contract util.Uint160, operation string, params ...interface{}) (*result.Invoke, error) { +func (t *testAct) Call(contract util.Uint160, operation string, params ...any) (*result.Invoke, error) { return t.res, t.err } func (t *testAct) MakeRun(script []byte) (*transaction.Transaction, error) { @@ -33,7 +33,7 @@ func (t *testAct) MakeUnsignedRun(script []byte, attrs []transaction.Attribute) func (t *testAct) SendRun(script []byte) (util.Uint256, uint32, error) { return t.txh, t.vub, t.err } -func (t *testAct) CallAndExpandIterator(contract util.Uint160, method string, maxItems int, params ...interface{}) (*result.Invoke, error) { +func (t *testAct) CallAndExpandIterator(contract util.Uint160, method string, maxItems int, params ...any) (*result.Invoke, error) { return t.res, t.err } func (t *testAct) TerminateSession(sessionID uuid.UUID) error { @@ -241,7 +241,7 @@ func TestTokenTransferTransaction(t *testing.T) { ta := new(testAct) tok := NewBase(ta, util.Uint160{1, 2, 3}) - for _, fun := range []func(to util.Uint160, token []byte, data interface{}) (*transaction.Transaction, error){ + for _, fun := range []func(to util.Uint160, token []byte, data any) (*transaction.Transaction, error){ tok.TransferTransaction, tok.TransferUnsigned, } { diff --git a/pkg/rpcclient/nep11/divisible.go b/pkg/rpcclient/nep11/divisible.go index d558ab05b..59600048a 100644 --- a/pkg/rpcclient/nep11/divisible.go +++ b/pkg/rpcclient/nep11/divisible.go @@ -79,7 +79,7 @@ func (t *DivisibleReader) BalanceOfD(owner util.Uint160, token []byte) (*big.Int // method call using the given parameters and checks for this call result, // failing the transaction if it's not true. The returned values are transaction // hash, its ValidUntilBlock value and an error if any. -func (t *DivisibleWriter) TransferD(from util.Uint160, to util.Uint160, amount *big.Int, id []byte, data interface{}) (util.Uint256, uint32, error) { +func (t *DivisibleWriter) TransferD(from util.Uint160, to util.Uint160, amount *big.Int, id []byte, data any) (util.Uint256, uint32, error) { script, err := t.transferScript(from, to, amount, id, data) if err != nil { return util.Uint256{}, 0, err @@ -92,7 +92,7 @@ func (t *DivisibleWriter) TransferD(from util.Uint160, to util.Uint160, amount * // `transfer` method call using the given parameters and checks for this call // result, failing the transaction if it's not true. This transaction is signed, // but not sent to the network, instead it's returned to the caller. -func (t *DivisibleWriter) TransferDTransaction(from util.Uint160, to util.Uint160, amount *big.Int, id []byte, data interface{}) (*transaction.Transaction, error) { +func (t *DivisibleWriter) TransferDTransaction(from util.Uint160, to util.Uint160, amount *big.Int, id []byte, data any) (*transaction.Transaction, error) { script, err := t.transferScript(from, to, amount, id, data) if err != nil { return nil, err @@ -105,7 +105,7 @@ func (t *DivisibleWriter) TransferDTransaction(from util.Uint160, to util.Uint16 // `transfer` method call using the given parameters and checks for this call // result, failing the transaction if it's not true. This transaction is not // signed and just returned to the caller. -func (t *DivisibleWriter) TransferDUnsigned(from util.Uint160, to util.Uint160, amount *big.Int, id []byte, data interface{}) (*transaction.Transaction, error) { +func (t *DivisibleWriter) TransferDUnsigned(from util.Uint160, to util.Uint160, amount *big.Int, id []byte, data any) (*transaction.Transaction, error) { script, err := t.transferScript(from, to, amount, id, data) if err != nil { return nil, err diff --git a/pkg/rpcclient/nep11/divisible_test.go b/pkg/rpcclient/nep11/divisible_test.go index f44e83c31..dd9a1e26d 100644 --- a/pkg/rpcclient/nep11/divisible_test.go +++ b/pkg/rpcclient/nep11/divisible_test.go @@ -198,7 +198,7 @@ func TestDivisibleTransferTransaction(t *testing.T) { ta := new(testAct) tok := NewDivisible(ta, util.Uint160{1, 2, 3}) - for _, fun := range []func(from util.Uint160, to util.Uint160, amount *big.Int, id []byte, data interface{}) (*transaction.Transaction, error){ + for _, fun := range []func(from util.Uint160, to util.Uint160, amount *big.Int, id []byte, data any) (*transaction.Transaction, error){ tok.TransferDTransaction, tok.TransferDUnsigned, } { diff --git a/pkg/rpcclient/nep17.go b/pkg/rpcclient/nep17.go index aa73a8c28..ea2c5c894 100644 --- a/pkg/rpcclient/nep17.go +++ b/pkg/rpcclient/nep17.go @@ -15,7 +15,7 @@ type TransferTarget struct { Token util.Uint160 Address util.Uint160 Amount int64 - Data interface{} + Data any } // SignerAccount represents combination of the transaction.Signer and the @@ -75,7 +75,7 @@ func (c *Client) NEP17TokenInfo(tokenHash util.Uint160) (*wallet.Token, error) { // Deprecated: please use nep17 package, this method will be removed in future // versions. func (c *Client) CreateNEP17TransferTx(acc *wallet.Account, to util.Uint160, - token util.Uint160, amount int64, gas int64, data interface{}, cosigners []SignerAccount) (*transaction.Transaction, error) { + token util.Uint160, amount int64, gas int64, data any, cosigners []SignerAccount) (*transaction.Transaction, error) { return c.CreateNEP17MultiTransferTx(acc, gas, []TransferTarget{ {Token: token, Address: to, @@ -164,7 +164,7 @@ func (c *Client) CreateTxFromScript(script []byte, acc *wallet.Account, sysFee, // Deprecated: please use nep17 package, this method will be removed in future // versions. func (c *Client) TransferNEP17(acc *wallet.Account, to util.Uint160, token util.Uint160, - amount int64, gas int64, data interface{}, cosigners []SignerAccount) (util.Uint256, error) { + amount int64, gas int64, data any, cosigners []SignerAccount) (util.Uint256, error) { tx, err := c.CreateNEP17TransferTx(acc, to, token, amount, gas, data, cosigners) if err != nil { return util.Uint256{}, err diff --git a/pkg/rpcclient/nep17/nep17.go b/pkg/rpcclient/nep17/nep17.go index e2f1d71e4..f91488e82 100644 --- a/pkg/rpcclient/nep17/nep17.go +++ b/pkg/rpcclient/nep17/nep17.go @@ -63,7 +63,7 @@ type TransferParameters struct { From util.Uint160 To util.Uint160 Amount *big.Int - Data interface{} + Data any } // NewReader creates an instance of TokenReader for contract with the given @@ -82,7 +82,7 @@ func New(actor Actor, hash util.Uint160) *Token { // call using the given parameters and checks for this call result, failing the // transaction if it's not true. The returned values are transaction hash, its // ValidUntilBlock value and an error if any. -func (t *TokenWriter) Transfer(from util.Uint160, to util.Uint160, amount *big.Int, data interface{}) (util.Uint256, uint32, error) { +func (t *TokenWriter) Transfer(from util.Uint160, to util.Uint160, amount *big.Int, data any) (util.Uint256, uint32, error) { return t.MultiTransfer([]TransferParameters{{from, to, amount, data}}) } @@ -90,7 +90,7 @@ func (t *TokenWriter) Transfer(from util.Uint160, to util.Uint160, amount *big.I // call using the given parameters and checks for this call result, failing the // transaction if it's not true. This transaction is signed, but not sent to the // network, instead it's returned to the caller. -func (t *TokenWriter) TransferTransaction(from util.Uint160, to util.Uint160, amount *big.Int, data interface{}) (*transaction.Transaction, error) { +func (t *TokenWriter) TransferTransaction(from util.Uint160, to util.Uint160, amount *big.Int, data any) (*transaction.Transaction, error) { return t.MultiTransferTransaction([]TransferParameters{{from, to, amount, data}}) } @@ -98,7 +98,7 @@ func (t *TokenWriter) TransferTransaction(from util.Uint160, to util.Uint160, am // call using the given parameters and checks for this call result, failing the // transaction if it's not true. This transaction is not signed and just returned // to the caller. -func (t *TokenWriter) TransferUnsigned(from util.Uint160, to util.Uint160, amount *big.Int, data interface{}) (*transaction.Transaction, error) { +func (t *TokenWriter) TransferUnsigned(from util.Uint160, to util.Uint160, amount *big.Int, data any) (*transaction.Transaction, error) { return t.MultiTransferUnsigned([]TransferParameters{{from, to, amount, data}}) } diff --git a/pkg/rpcclient/nep17/nep17_test.go b/pkg/rpcclient/nep17/nep17_test.go index b14e84dda..0fe260cbd 100644 --- a/pkg/rpcclient/nep17/nep17_test.go +++ b/pkg/rpcclient/nep17/nep17_test.go @@ -20,7 +20,7 @@ type testAct struct { vub uint32 } -func (t *testAct) Call(contract util.Uint160, operation string, params ...interface{}) (*result.Invoke, error) { +func (t *testAct) Call(contract util.Uint160, operation string, params ...any) (*result.Invoke, error) { return t.res, t.err } func (t *testAct) MakeRun(script []byte) (*transaction.Transaction, error) { @@ -66,9 +66,9 @@ func TestTokenTransfer(t *testing.T) { ta := new(testAct) tok := New(ta, util.Uint160{1, 2, 3}) - for name, fun := range map[string]func(from util.Uint160, to util.Uint160, amount *big.Int, data interface{}) (util.Uint256, uint32, error){ + for name, fun := range map[string]func(from util.Uint160, to util.Uint160, amount *big.Int, data any) (util.Uint256, uint32, error){ "Tranfer": tok.Transfer, - "MultiTransfer": func(from util.Uint160, to util.Uint160, amount *big.Int, data interface{}) (util.Uint256, uint32, error) { + "MultiTransfer": func(from util.Uint160, to util.Uint160, amount *big.Int, data any) (util.Uint256, uint32, error) { return tok.MultiTransfer([]TransferParameters{{from, to, amount, data}, {from, to, amount, data}}) }, } { @@ -99,13 +99,13 @@ func TestTokenTransferTransaction(t *testing.T) { ta := new(testAct) tok := New(ta, util.Uint160{1, 2, 3}) - for name, fun := range map[string]func(from util.Uint160, to util.Uint160, amount *big.Int, data interface{}) (*transaction.Transaction, error){ + for name, fun := range map[string]func(from util.Uint160, to util.Uint160, amount *big.Int, data any) (*transaction.Transaction, error){ "TransferTransaction": tok.TransferTransaction, "TransferUnsigned": tok.TransferUnsigned, - "MultiTransferTransaction": func(from util.Uint160, to util.Uint160, amount *big.Int, data interface{}) (*transaction.Transaction, error) { + "MultiTransferTransaction": func(from util.Uint160, to util.Uint160, amount *big.Int, data any) (*transaction.Transaction, error) { return tok.MultiTransferTransaction([]TransferParameters{{from, to, amount, data}, {from, to, amount, data}}) }, - "MultiTransferUnsigned": func(from util.Uint160, to util.Uint160, amount *big.Int, data interface{}) (*transaction.Transaction, error) { + "MultiTransferUnsigned": func(from util.Uint160, to util.Uint160, amount *big.Int, data any) (*transaction.Transaction, error) { return tok.MultiTransferUnsigned([]TransferParameters{{from, to, amount, data}, {from, to, amount, data}}) }, } { diff --git a/pkg/rpcclient/neptoken/base.go b/pkg/rpcclient/neptoken/base.go index 610e2be8e..57b504f0a 100644 --- a/pkg/rpcclient/neptoken/base.go +++ b/pkg/rpcclient/neptoken/base.go @@ -24,7 +24,7 @@ const ( // Invoker is used by Base to call various methods. type Invoker interface { - Call(contract util.Uint160, operation string, params ...interface{}) (*result.Invoke, error) + Call(contract util.Uint160, operation string, params ...any) (*result.Invoke, error) } // Base is a reader interface for common NEP-11 and NEP-17 methods built diff --git a/pkg/rpcclient/neptoken/base_test.go b/pkg/rpcclient/neptoken/base_test.go index 7f7320d7c..f1c85332e 100644 --- a/pkg/rpcclient/neptoken/base_test.go +++ b/pkg/rpcclient/neptoken/base_test.go @@ -16,7 +16,7 @@ type testInv struct { res *result.Invoke } -func (t *testInv) Call(contract util.Uint160, operation string, params ...interface{}) (*result.Invoke, error) { +func (t *testInv) Call(contract util.Uint160, operation string, params ...any) (*result.Invoke, error) { return t.res, t.err } diff --git a/pkg/rpcclient/nns/contract_test.go b/pkg/rpcclient/nns/contract_test.go index f69079e68..98a4ef20d 100644 --- a/pkg/rpcclient/nns/contract_test.go +++ b/pkg/rpcclient/nns/contract_test.go @@ -16,10 +16,10 @@ type testAct struct { res *result.Invoke } -func (t *testAct) Call(contract util.Uint160, operation string, params ...interface{}) (*result.Invoke, error) { +func (t *testAct) Call(contract util.Uint160, operation string, params ...any) (*result.Invoke, error) { return t.res, t.err } -func (t *testAct) CallAndExpandIterator(contract util.Uint160, method string, maxItems int, params ...interface{}) (*result.Invoke, error) { +func (t *testAct) CallAndExpandIterator(contract util.Uint160, method string, maxItems int, params ...any) (*result.Invoke, error) { return t.res, t.err } func (t *testAct) TerminateSession(sessionID uuid.UUID) error { diff --git a/pkg/rpcclient/notary/contract.go b/pkg/rpcclient/notary/contract.go index 9bf3b6373..749003f1c 100644 --- a/pkg/rpcclient/notary/contract.go +++ b/pkg/rpcclient/notary/contract.go @@ -27,18 +27,18 @@ const ( // ContractInvoker is used by ContractReader to perform read-only calls. type ContractInvoker interface { - Call(contract util.Uint160, operation string, params ...interface{}) (*result.Invoke, error) + Call(contract util.Uint160, operation string, params ...any) (*result.Invoke, error) } // ContractActor is used by Contract to create and send transactions. type ContractActor interface { ContractInvoker - MakeCall(contract util.Uint160, method string, params ...interface{}) (*transaction.Transaction, error) + MakeCall(contract util.Uint160, method string, params ...any) (*transaction.Transaction, error) MakeRun(script []byte) (*transaction.Transaction, error) - MakeUnsignedCall(contract util.Uint160, method string, attrs []transaction.Attribute, params ...interface{}) (*transaction.Transaction, error) + MakeUnsignedCall(contract util.Uint160, method string, attrs []transaction.Attribute, params ...any) (*transaction.Transaction, error) MakeUnsignedRun(script []byte, attrs []transaction.Attribute) (*transaction.Transaction, error) - SendCall(contract util.Uint160, method string, params ...interface{}) (util.Uint256, uint32, error) + SendCall(contract util.Uint160, method string, params ...any) (util.Uint256, uint32, error) SendRun(script []byte) (util.Uint256, uint32, error) } diff --git a/pkg/rpcclient/notary/contract_test.go b/pkg/rpcclient/notary/contract_test.go index c8498ffbf..1e50f8db5 100644 --- a/pkg/rpcclient/notary/contract_test.go +++ b/pkg/rpcclient/notary/contract_test.go @@ -20,7 +20,7 @@ type testAct struct { vub uint32 } -func (t *testAct) Call(contract util.Uint160, operation string, params ...interface{}) (*result.Invoke, error) { +func (t *testAct) Call(contract util.Uint160, operation string, params ...any) (*result.Invoke, error) { return t.res, t.err } func (t *testAct) MakeRun(script []byte) (*transaction.Transaction, error) { @@ -32,13 +32,13 @@ func (t *testAct) MakeUnsignedRun(script []byte, attrs []transaction.Attribute) func (t *testAct) SendRun(script []byte) (util.Uint256, uint32, error) { return t.txh, t.vub, t.err } -func (t *testAct) MakeCall(contract util.Uint160, method string, params ...interface{}) (*transaction.Transaction, error) { +func (t *testAct) MakeCall(contract util.Uint160, method string, params ...any) (*transaction.Transaction, error) { return t.tx, t.err } -func (t *testAct) MakeUnsignedCall(contract util.Uint160, method string, attrs []transaction.Attribute, params ...interface{}) (*transaction.Transaction, error) { +func (t *testAct) MakeUnsignedCall(contract util.Uint160, method string, attrs []transaction.Attribute, params ...any) (*transaction.Transaction, error) { return t.tx, t.err } -func (t *testAct) SendCall(contract util.Uint160, method string, params ...interface{}) (util.Uint256, uint32, error) { +func (t *testAct) SendCall(contract util.Uint160, method string, params ...any) (util.Uint256, uint32, error) { return t.txh, t.vub, t.err } diff --git a/pkg/rpcclient/oracle/oracle.go b/pkg/rpcclient/oracle/oracle.go index fe3a79964..39a12e023 100644 --- a/pkg/rpcclient/oracle/oracle.go +++ b/pkg/rpcclient/oracle/oracle.go @@ -19,16 +19,16 @@ import ( // Invoker is used by ContractReader to call various methods. type Invoker interface { - Call(contract util.Uint160, operation string, params ...interface{}) (*result.Invoke, error) + Call(contract util.Uint160, operation string, params ...any) (*result.Invoke, error) } // Actor is used by Contract to create and send transactions. type Actor interface { Invoker - MakeCall(contract util.Uint160, method string, params ...interface{}) (*transaction.Transaction, error) - MakeUnsignedCall(contract util.Uint160, method string, attrs []transaction.Attribute, params ...interface{}) (*transaction.Transaction, error) - SendCall(contract util.Uint160, method string, params ...interface{}) (util.Uint256, uint32, error) + MakeCall(contract util.Uint160, method string, params ...any) (*transaction.Transaction, error) + MakeUnsignedCall(contract util.Uint160, method string, attrs []transaction.Attribute, params ...any) (*transaction.Transaction, error) + SendCall(contract util.Uint160, method string, params ...any) (util.Uint256, uint32, error) } // Hash stores the hash of the native OracleContract contract. diff --git a/pkg/rpcclient/oracle/oracle_test.go b/pkg/rpcclient/oracle/oracle_test.go index 25e960d67..aad3386f3 100644 --- a/pkg/rpcclient/oracle/oracle_test.go +++ b/pkg/rpcclient/oracle/oracle_test.go @@ -20,16 +20,16 @@ type testAct struct { vub uint32 } -func (t *testAct) Call(contract util.Uint160, operation string, params ...interface{}) (*result.Invoke, error) { +func (t *testAct) Call(contract util.Uint160, operation string, params ...any) (*result.Invoke, error) { return t.res, t.err } -func (t *testAct) MakeCall(contract util.Uint160, method string, params ...interface{}) (*transaction.Transaction, error) { +func (t *testAct) MakeCall(contract util.Uint160, method string, params ...any) (*transaction.Transaction, error) { return t.tx, t.err } -func (t *testAct) MakeUnsignedCall(contract util.Uint160, method string, attrs []transaction.Attribute, params ...interface{}) (*transaction.Transaction, error) { +func (t *testAct) MakeUnsignedCall(contract util.Uint160, method string, attrs []transaction.Attribute, params ...any) (*transaction.Transaction, error) { return t.tx, t.err } -func (t *testAct) SendCall(contract util.Uint160, method string, params ...interface{}) (util.Uint256, uint32, error) { +func (t *testAct) SendCall(contract util.Uint160, method string, params ...any) (util.Uint256, uint32, error) { return t.txh, t.vub, t.err } diff --git a/pkg/rpcclient/policy/policy.go b/pkg/rpcclient/policy/policy.go index 2f583db0a..52dd6ba5b 100644 --- a/pkg/rpcclient/policy/policy.go +++ b/pkg/rpcclient/policy/policy.go @@ -18,18 +18,18 @@ import ( // Invoker is used by ContractReader to call various methods. type Invoker interface { - Call(contract util.Uint160, operation string, params ...interface{}) (*result.Invoke, error) + Call(contract util.Uint160, operation string, params ...any) (*result.Invoke, error) } // Actor is used by Contract to create and send transactions. type Actor interface { Invoker - MakeCall(contract util.Uint160, method string, params ...interface{}) (*transaction.Transaction, error) + MakeCall(contract util.Uint160, method string, params ...any) (*transaction.Transaction, error) MakeRun(script []byte) (*transaction.Transaction, error) - MakeUnsignedCall(contract util.Uint160, method string, attrs []transaction.Attribute, params ...interface{}) (*transaction.Transaction, error) + MakeUnsignedCall(contract util.Uint160, method string, attrs []transaction.Attribute, params ...any) (*transaction.Transaction, error) MakeUnsignedRun(script []byte, attrs []transaction.Attribute) (*transaction.Transaction, error) - SendCall(contract util.Uint160, method string, params ...interface{}) (util.Uint256, uint32, error) + SendCall(contract util.Uint160, method string, params ...any) (util.Uint256, uint32, error) SendRun(script []byte) (util.Uint256, uint32, error) } diff --git a/pkg/rpcclient/policy/policy_test.go b/pkg/rpcclient/policy/policy_test.go index aed3dcd16..458c77efd 100644 --- a/pkg/rpcclient/policy/policy_test.go +++ b/pkg/rpcclient/policy/policy_test.go @@ -19,16 +19,16 @@ type testAct struct { vub uint32 } -func (t *testAct) Call(contract util.Uint160, operation string, params ...interface{}) (*result.Invoke, error) { +func (t *testAct) Call(contract util.Uint160, operation string, params ...any) (*result.Invoke, error) { return t.res, t.err } -func (t *testAct) MakeCall(contract util.Uint160, method string, params ...interface{}) (*transaction.Transaction, error) { +func (t *testAct) MakeCall(contract util.Uint160, method string, params ...any) (*transaction.Transaction, error) { return t.tx, t.err } -func (t *testAct) MakeUnsignedCall(contract util.Uint160, method string, attrs []transaction.Attribute, params ...interface{}) (*transaction.Transaction, error) { +func (t *testAct) MakeUnsignedCall(contract util.Uint160, method string, attrs []transaction.Attribute, params ...any) (*transaction.Transaction, error) { return t.tx, t.err } -func (t *testAct) SendCall(contract util.Uint160, method string, params ...interface{}) (util.Uint256, uint32, error) { +func (t *testAct) SendCall(contract util.Uint160, method string, params ...any) (util.Uint256, uint32, error) { return t.txh, t.vub, t.err } func (t *testAct) MakeRun(script []byte) (*transaction.Transaction, error) { diff --git a/pkg/rpcclient/rolemgmt/roles.go b/pkg/rpcclient/rolemgmt/roles.go index c7593e4b5..5bb8dbb91 100644 --- a/pkg/rpcclient/rolemgmt/roles.go +++ b/pkg/rpcclient/rolemgmt/roles.go @@ -19,16 +19,16 @@ import ( // Invoker is used by ContractReader to call various methods. type Invoker interface { - Call(contract util.Uint160, operation string, params ...interface{}) (*result.Invoke, error) + Call(contract util.Uint160, operation string, params ...any) (*result.Invoke, error) } // Actor is used by Contract to create and send transactions. type Actor interface { Invoker - MakeCall(contract util.Uint160, method string, params ...interface{}) (*transaction.Transaction, error) - MakeUnsignedCall(contract util.Uint160, method string, attrs []transaction.Attribute, params ...interface{}) (*transaction.Transaction, error) - SendCall(contract util.Uint160, method string, params ...interface{}) (util.Uint256, uint32, error) + MakeCall(contract util.Uint160, method string, params ...any) (*transaction.Transaction, error) + MakeUnsignedCall(contract util.Uint160, method string, attrs []transaction.Attribute, params ...any) (*transaction.Transaction, error) + SendCall(contract util.Uint160, method string, params ...any) (util.Uint256, uint32, error) } // Hash stores the hash of the native RoleManagement contract. diff --git a/pkg/rpcclient/rolemgmt/roles_test.go b/pkg/rpcclient/rolemgmt/roles_test.go index f1899ed80..ffb764fac 100644 --- a/pkg/rpcclient/rolemgmt/roles_test.go +++ b/pkg/rpcclient/rolemgmt/roles_test.go @@ -21,16 +21,16 @@ type testAct struct { vub uint32 } -func (t *testAct) Call(contract util.Uint160, operation string, params ...interface{}) (*result.Invoke, error) { +func (t *testAct) Call(contract util.Uint160, operation string, params ...any) (*result.Invoke, error) { return t.res, t.err } -func (t *testAct) MakeCall(contract util.Uint160, method string, params ...interface{}) (*transaction.Transaction, error) { +func (t *testAct) MakeCall(contract util.Uint160, method string, params ...any) (*transaction.Transaction, error) { return t.tx, t.err } -func (t *testAct) MakeUnsignedCall(contract util.Uint160, method string, attrs []transaction.Attribute, params ...interface{}) (*transaction.Transaction, error) { +func (t *testAct) MakeUnsignedCall(contract util.Uint160, method string, attrs []transaction.Attribute, params ...any) (*transaction.Transaction, error) { return t.tx, t.err } -func (t *testAct) SendCall(contract util.Uint160, method string, params ...interface{}) (util.Uint256, uint32, error) { +func (t *testAct) SendCall(contract util.Uint160, method string, params ...any) (util.Uint256, uint32, error) { return t.txh, t.vub, t.err } diff --git a/pkg/rpcclient/rpc.go b/pkg/rpcclient/rpc.go index 6b97c8895..07cfbe077 100644 --- a/pkg/rpcclient/rpc.go +++ b/pkg/rpcclient/rpc.go @@ -39,7 +39,7 @@ var errNetworkNotInitialized = errors.New("RPC client network is not initialized // filled for standard sig/multisig signers. func (c *Client) CalculateNetworkFee(tx *transaction.Transaction) (int64, error) { var ( - params = []interface{}{tx.Bytes()} + params = []any{tx.Bytes()} resp = new(result.NetworkFee) ) if err := c.performRequest("calculatenetworkfee", params, resp); err != nil { @@ -51,7 +51,7 @@ func (c *Client) CalculateNetworkFee(tx *transaction.Transaction) (int64, error) // GetApplicationLog returns a contract log based on the specified txid. func (c *Client) GetApplicationLog(hash util.Uint256, trig *trigger.Type) (*result.ApplicationLog, error) { var ( - params = []interface{}{hash.StringLE()} + params = []any{hash.StringLE()} resp = new(result.ApplicationLog) ) if trig != nil { @@ -93,13 +93,13 @@ func (c *Client) GetBlockByHash(hash util.Uint256) (*block.Block, error) { return c.getBlock(hash.StringLE()) } -func (c *Client) getBlock(param interface{}) (*block.Block, error) { +func (c *Client) getBlock(param any) (*block.Block, error) { var ( resp []byte err error b *block.Block ) - if err = c.performRequest("getblock", []interface{}{param}, &resp); err != nil { + if err = c.performRequest("getblock", []any{param}, &resp); err != nil { return nil, err } r := io.NewBinReaderFromBuf(resp) @@ -130,9 +130,9 @@ func (c *Client) GetBlockByHashVerbose(hash util.Uint256) (*result.Block, error) return c.getBlockVerbose(hash.StringLE()) } -func (c *Client) getBlockVerbose(param interface{}) (*result.Block, error) { +func (c *Client) getBlockVerbose(param any) (*result.Block, error) { var ( - params = []interface{}{param, 1} // 1 for verbose. + params = []any{param, 1} // 1 for verbose. resp = &result.Block{} err error ) @@ -150,7 +150,7 @@ func (c *Client) getBlockVerbose(param interface{}) (*result.Block, error) { // GetBlockHash returns the hash value of the corresponding block based on the specified index. func (c *Client) GetBlockHash(index uint32) (util.Uint256, error) { var ( - params = []interface{}{index} + params = []any{index} resp = util.Uint256{} ) if err := c.performRequest("getblockhash", params, &resp); err != nil { @@ -164,7 +164,7 @@ func (c *Client) GetBlockHash(index uint32) (util.Uint256, error) { // initialized with Init before calling this method. func (c *Client) GetBlockHeader(hash util.Uint256) (*block.Header, error) { var ( - params = []interface{}{hash.StringLE()} + params = []any{hash.StringLE()} resp []byte h *block.Header ) @@ -199,7 +199,7 @@ func (c *Client) GetBlockHeaderCount() (uint32, error) { // initialized with Init before calling this method. func (c *Client) GetBlockHeaderVerbose(hash util.Uint256) (*result.Header, error) { var ( - params = []interface{}{hash.StringLE(), 1} + params = []any{hash.StringLE(), 1} resp = &result.Header{} ) if err := c.performRequest("getblockheader", params, resp); err != nil { @@ -212,7 +212,7 @@ func (c *Client) GetBlockHeaderVerbose(hash util.Uint256) (*result.Header, error // This method is only supported by NeoGo servers. func (c *Client) GetBlockSysFee(index uint32) (fixedn.Fixed8, error) { var ( - params = []interface{}{index} + params = []any{index} resp fixedn.Fixed8 ) if err := c.performRequest("getblocksysfee", params, &resp); err != nil { @@ -261,9 +261,9 @@ func (c *Client) GetContractStateByID(id int32) (*state.Contract, error) { } // getContractState is an internal representation of GetContractStateBy* methods. -func (c *Client) getContractState(param interface{}) (*state.Contract, error) { +func (c *Client) getContractState(param any) (*state.Contract, error) { var ( - params = []interface{}{param} + params = []any{param} resp = &state.Contract{} ) if err := c.performRequest("getcontractstate", params, resp); err != nil { @@ -291,7 +291,7 @@ func (c *Client) GetNativeContracts() ([]state.NativeContract, error) { // GetNEP11Balances is a wrapper for getnep11balances RPC. func (c *Client) GetNEP11Balances(address util.Uint160) (*result.NEP11Balances, error) { - params := []interface{}{address.StringLE()} + params := []any{address.StringLE()} resp := new(result.NEP11Balances) if err := c.performRequest("getnep11balances", params, resp); err != nil { return nil, err @@ -301,7 +301,7 @@ func (c *Client) GetNEP11Balances(address util.Uint160) (*result.NEP11Balances, // GetNEP17Balances is a wrapper for getnep17balances RPC. func (c *Client) GetNEP17Balances(address util.Uint160) (*result.NEP17Balances, error) { - params := []interface{}{address.StringLE()} + params := []any{address.StringLE()} resp := new(result.NEP17Balances) if err := c.performRequest("getnep17balances", params, resp); err != nil { return nil, err @@ -314,9 +314,9 @@ func (c *Client) GetNEP17Balances(address util.Uint160) (*result.NEP17Balances, // This method is provided mostly for the sake of completeness. For well-known // attributes like "description", "image", "name" and "tokenURI" it returns strings, // while for all others []byte (which can be nil). -func (c *Client) GetNEP11Properties(asset util.Uint160, token []byte) (map[string]interface{}, error) { - params := []interface{}{asset.StringLE(), hex.EncodeToString(token)} - resp := make(map[string]interface{}) +func (c *Client) GetNEP11Properties(asset util.Uint160, token []byte) (map[string]any, error) { + params := []any{asset.StringLE(), hex.EncodeToString(token)} + resp := make(map[string]any) if err := c.performRequest("getnep11properties", params, &resp); err != nil { return nil, err } @@ -355,8 +355,8 @@ func (c *Client) GetNEP11Transfers(address util.Uint160, start, stop *uint64, li return resp, nil } -func packTransfersParams(address util.Uint160, start, stop *uint64, limit, page *int) ([]interface{}, error) { - params := []interface{}{address.StringLE()} +func packTransfersParams(address util.Uint160, start, stop *uint64, limit, page *int) ([]any, error) { + params := []any{address.StringLE()} if start != nil { params = append(params, *start) if stop != nil { @@ -418,7 +418,7 @@ func (c *Client) GetRawMemPool() ([]util.Uint256, error) { // GetRawTransaction returns a transaction by hash. func (c *Client) GetRawTransaction(hash util.Uint256) (*transaction.Transaction, error) { var ( - params = []interface{}{hash.StringLE()} + params = []any{hash.StringLE()} resp []byte err error ) @@ -437,7 +437,7 @@ func (c *Client) GetRawTransaction(hash util.Uint256) (*transaction.Transaction, // NOTE: to get transaction.ID and transaction.Size, use t.Hash() and io.GetVarSize(t) respectively. func (c *Client) GetRawTransactionVerbose(hash util.Uint256) (*result.TransactionOutputRaw, error) { var ( - params = []interface{}{hash.StringLE(), 1} // 1 for verbose. + params = []any{hash.StringLE(), 1} // 1 for verbose. resp = &result.TransactionOutputRaw{} err error ) @@ -451,7 +451,7 @@ func (c *Client) GetRawTransactionVerbose(hash util.Uint256) (*result.Transactio // historical contract hash and historical item key. func (c *Client) GetProof(stateroot util.Uint256, historicalContractHash util.Uint160, historicalKey []byte) (*result.ProofWithKey, error) { var ( - params = []interface{}{stateroot.StringLE(), historicalContractHash.StringLE(), historicalKey} + params = []any{stateroot.StringLE(), historicalContractHash.StringLE(), historicalKey} resp = &result.ProofWithKey{} ) if err := c.performRequest("getproof", params, resp); err != nil { @@ -463,7 +463,7 @@ func (c *Client) GetProof(stateroot util.Uint256, historicalContractHash util.Ui // VerifyProof returns value by the given stateroot and proof. func (c *Client) VerifyProof(stateroot util.Uint256, proof *result.ProofWithKey) ([]byte, error) { var ( - params = []interface{}{stateroot.StringLE(), proof.String()} + params = []any{stateroot.StringLE(), proof.String()} resp []byte ) if err := c.performRequest("verifyproof", params, &resp); err != nil { @@ -476,7 +476,7 @@ func (c *Client) VerifyProof(stateroot util.Uint256, proof *result.ProofWithKey) // historical contract hash and historical item key. func (c *Client) GetState(stateroot util.Uint256, historicalContractHash util.Uint160, historicalKey []byte) ([]byte, error) { var ( - params = []interface{}{stateroot.StringLE(), historicalContractHash.StringLE(), historicalKey} + params = []any{stateroot.StringLE(), historicalContractHash.StringLE(), historicalKey} resp []byte ) if err := c.performRequest("getstate", params, &resp); err != nil { @@ -495,7 +495,7 @@ func (c *Client) FindStates(stateroot util.Uint256, historicalContractHash util. historicalPrefix = []byte{} } var ( - params = []interface{}{stateroot.StringLE(), historicalContractHash.StringLE(), historicalPrefix} + params = []any{stateroot.StringLE(), historicalContractHash.StringLE(), historicalPrefix} resp result.FindStates ) if start == nil && maxCount != nil { @@ -523,9 +523,9 @@ func (c *Client) GetStateRootByBlockHash(hash util.Uint256) (*state.MPTRoot, err return c.getStateRoot(hash) } -func (c *Client) getStateRoot(param interface{}) (*state.MPTRoot, error) { +func (c *Client) getStateRoot(param any) (*state.MPTRoot, error) { var resp = new(state.MPTRoot) - if err := c.performRequest("getstateroot", []interface{}{param}, resp); err != nil { + if err := c.performRequest("getstateroot", []any{param}, resp); err != nil { return nil, err } return resp, nil @@ -543,15 +543,15 @@ func (c *Client) GetStateHeight() (*result.StateHeight, error) { // GetStorageByID returns the stored value according to the contract ID and the stored key. func (c *Client) GetStorageByID(id int32, key []byte) ([]byte, error) { - return c.getStorage([]interface{}{id, key}) + return c.getStorage([]any{id, key}) } // GetStorageByHash returns the stored value according to the contract script hash and the stored key. func (c *Client) GetStorageByHash(hash util.Uint160, key []byte) ([]byte, error) { - return c.getStorage([]interface{}{hash.StringLE(), key}) + return c.getStorage([]any{hash.StringLE(), key}) } -func (c *Client) getStorage(params []interface{}) ([]byte, error) { +func (c *Client) getStorage(params []any) ([]byte, error) { var resp []byte if err := c.performRequest("getstorage", params, &resp); err != nil { return nil, err @@ -562,7 +562,7 @@ func (c *Client) getStorage(params []interface{}) ([]byte, error) { // GetTransactionHeight returns the block index where the transaction is found. func (c *Client) GetTransactionHeight(hash util.Uint256) (uint32, error) { var ( - params = []interface{}{hash.StringLE()} + params = []any{hash.StringLE()} resp uint32 ) if err := c.performRequest("gettransactionheight", params, &resp); err != nil { @@ -574,7 +574,7 @@ func (c *Client) GetTransactionHeight(hash util.Uint256) (uint32, error) { // GetUnclaimedGas returns the unclaimed GAS amount for the specified address. func (c *Client) GetUnclaimedGas(address string) (result.UnclaimedGas, error) { var ( - params = []interface{}{address} + params = []any{address} resp result.UnclaimedGas ) if err := c.performRequest("getunclaimedgas", params, &resp); err != nil { @@ -617,7 +617,7 @@ func (c *Client) GetVersion() (*result.Version, error) { // InvokeScript returns the result of the given script after running it true the VM. // NOTE: This is a test invoke and will not affect the blockchain. func (c *Client) InvokeScript(script []byte, signers []transaction.Signer) (*result.Invoke, error) { - var p = []interface{}{script} + var p = []any{script} return c.invokeSomething("invokescript", p, signers) } @@ -626,7 +626,7 @@ func (c *Client) InvokeScript(script []byte, signers []transaction.Signer) (*res // height. // NOTE: This is a test invoke and will not affect the blockchain. func (c *Client) InvokeScriptAtHeight(height uint32, script []byte, signers []transaction.Signer) (*result.Invoke, error) { - var p = []interface{}{height, script} + var p = []any{height, script} return c.invokeSomething("invokescripthistoric", p, signers) } @@ -635,7 +635,7 @@ func (c *Client) InvokeScriptAtHeight(height uint32, script []byte, signers []tr // state root or block hash. // NOTE: This is a test invoke and will not affect the blockchain. func (c *Client) InvokeScriptWithState(stateOrBlock util.Uint256, script []byte, signers []transaction.Signer) (*result.Invoke, error) { - var p = []interface{}{stateOrBlock.StringLE(), script} + var p = []any{stateOrBlock.StringLE(), script} return c.invokeSomething("invokescripthistoric", p, signers) } @@ -643,7 +643,7 @@ func (c *Client) InvokeScriptWithState(stateOrBlock util.Uint256, script []byte, // with the given operation and parameters. // NOTE: this is test invoke and will not affect the blockchain. func (c *Client) InvokeFunction(contract util.Uint160, operation string, params []smartcontract.Parameter, signers []transaction.Signer) (*result.Invoke, error) { - var p = []interface{}{contract.StringLE(), operation, params} + var p = []any{contract.StringLE(), operation, params} return c.invokeSomething("invokefunction", p, signers) } @@ -652,7 +652,7 @@ func (c *Client) InvokeFunction(contract util.Uint160, operation string, params // specified by the blockchain height. // NOTE: this is test invoke and will not affect the blockchain. func (c *Client) InvokeFunctionAtHeight(height uint32, contract util.Uint160, operation string, params []smartcontract.Parameter, signers []transaction.Signer) (*result.Invoke, error) { - var p = []interface{}{height, contract.StringLE(), operation, params} + var p = []any{height, contract.StringLE(), operation, params} return c.invokeSomething("invokefunctionhistoric", p, signers) } @@ -661,7 +661,7 @@ func (c *Client) InvokeFunctionAtHeight(height uint32, contract util.Uint160, op // by the specified state root or block hash. // NOTE: this is test invoke and will not affect the blockchain. func (c *Client) InvokeFunctionWithState(stateOrBlock util.Uint256, contract util.Uint160, operation string, params []smartcontract.Parameter, signers []transaction.Signer) (*result.Invoke, error) { - var p = []interface{}{stateOrBlock.StringLE(), contract.StringLE(), operation, params} + var p = []any{stateOrBlock.StringLE(), contract.StringLE(), operation, params} return c.invokeSomething("invokefunctionhistoric", p, signers) } @@ -669,7 +669,7 @@ func (c *Client) InvokeFunctionWithState(stateOrBlock util.Uint256, contract uti // with the given parameters under verification trigger type. // NOTE: this is test invoke and will not affect the blockchain. func (c *Client) InvokeContractVerify(contract util.Uint160, params []smartcontract.Parameter, signers []transaction.Signer, witnesses ...transaction.Witness) (*result.Invoke, error) { - var p = []interface{}{contract.StringLE(), params} + var p = []any{contract.StringLE(), params} return c.invokeSomething("invokecontractverify", p, signers, witnesses...) } @@ -678,7 +678,7 @@ func (c *Client) InvokeContractVerify(contract util.Uint160, params []smartcontr // at the blockchain state specified by the blockchain height. // NOTE: this is test invoke and will not affect the blockchain. func (c *Client) InvokeContractVerifyAtHeight(height uint32, contract util.Uint160, params []smartcontract.Parameter, signers []transaction.Signer, witnesses ...transaction.Witness) (*result.Invoke, error) { - var p = []interface{}{height, contract.StringLE(), params} + var p = []any{height, contract.StringLE(), params} return c.invokeSomething("invokecontractverifyhistoric", p, signers, witnesses...) } @@ -687,12 +687,12 @@ func (c *Client) InvokeContractVerifyAtHeight(height uint32, contract util.Uint1 // at the blockchain state specified by the state root or block hash. // NOTE: this is test invoke and will not affect the blockchain. func (c *Client) InvokeContractVerifyWithState(stateOrBlock util.Uint256, contract util.Uint160, params []smartcontract.Parameter, signers []transaction.Signer, witnesses ...transaction.Witness) (*result.Invoke, error) { - var p = []interface{}{stateOrBlock.StringLE(), contract.StringLE(), params} + var p = []any{stateOrBlock.StringLE(), contract.StringLE(), params} return c.invokeSomething("invokecontractverifyhistoric", p, signers, witnesses...) } // invokeSomething is an inner wrapper for Invoke* functions. -func (c *Client) invokeSomething(method string, p []interface{}, signers []transaction.Signer, witnesses ...transaction.Witness) (*result.Invoke, error) { +func (c *Client) invokeSomething(method string, p []any, signers []transaction.Signer, witnesses ...transaction.Witness) (*result.Invoke, error) { var resp = new(result.Invoke) if signers != nil { if witnesses == nil { @@ -722,7 +722,7 @@ func (c *Client) invokeSomething(method string, p []interface{}, signers []trans // hash returned from server, when not it's a locally calculated rawTX hash. func (c *Client) SendRawTransaction(rawTX *transaction.Transaction) (util.Uint256, error) { var ( - params = []interface{}{rawTX.Bytes()} + params = []any{rawTX.Bytes()} resp = new(result.RelayResult) ) if err := c.performRequest("sendrawtransaction", params, resp); err != nil { @@ -734,7 +734,7 @@ func (c *Client) SendRawTransaction(rawTX *transaction.Transaction) (util.Uint25 // SubmitBlock broadcasts a raw block over the NEO network. func (c *Client) SubmitBlock(b block.Block) (util.Uint256, error) { var ( - params []interface{} + params []any resp = new(result.RelayResult) ) buf := io.NewBufBinWriter() @@ -742,7 +742,7 @@ func (c *Client) SubmitBlock(b block.Block) (util.Uint256, error) { if err := buf.Err; err != nil { return util.Uint256{}, err } - params = []interface{}{buf.Bytes()} + params = []any{buf.Bytes()} if err := c.performRequest("submitblock", params, resp); err != nil { return util.Uint256{}, err @@ -752,7 +752,7 @@ func (c *Client) SubmitBlock(b block.Block) (util.Uint256, error) { // SubmitRawOracleResponse submits a raw oracle response to the oracle node. // Raw params are used to avoid excessive marshalling. -func (c *Client) SubmitRawOracleResponse(ps []interface{}) error { +func (c *Client) SubmitRawOracleResponse(ps []any) error { return c.performRequest("submitoracleresponse", ps, new(result.RelayResult)) } @@ -991,7 +991,7 @@ func (c *Client) SubmitP2PNotaryRequest(req *payload.P2PNotaryRequest) (util.Uin if err != nil { return util.Uint256{}, fmt.Errorf("failed to encode request: %w", err) } - params := []interface{}{bytes} + params := []any{bytes} if err := c.performRequest("submitnotaryrequest", params, resp); err != nil { return util.Uint256{}, err } @@ -1002,7 +1002,7 @@ func (c *Client) SubmitP2PNotaryRequest(req *payload.P2PNotaryRequest) (util.Uin // Consider using [address] package instead to do it locally. func (c *Client) ValidateAddress(address string) error { var ( - params = []interface{}{address} + params = []any{address} resp = &result.ValidateAddress{} ) @@ -1168,7 +1168,7 @@ func (c *Client) TraverseIterator(sessionID, iteratorID uuid.UUID, maxItemsCount maxItemsCount = config.DefaultMaxIteratorResultItems } var ( - params = []interface{}{sessionID.String(), iteratorID.String(), maxItemsCount} + params = []any{sessionID.String(), iteratorID.String(), maxItemsCount} resp []json.RawMessage ) if err := c.performRequest("traverseiterator", params, &resp); err != nil { @@ -1190,7 +1190,7 @@ func (c *Client) TraverseIterator(sessionID, iteratorID uuid.UUID, maxItemsCount // the specified session was found on server. func (c *Client) TerminateSession(sessionID uuid.UUID) (bool, error) { var resp bool - params := []interface{}{sessionID.String()} + params := []any{sessionID.String()} if err := c.performRequest("terminatesession", params, &resp); err != nil { return false, err } diff --git a/pkg/rpcclient/rpc_test.go b/pkg/rpcclient/rpc_test.go index 9458e0830..87092343d 100644 --- a/pkg/rpcclient/rpc_test.go +++ b/pkg/rpcclient/rpc_test.go @@ -44,11 +44,11 @@ import ( type rpcClientTestCase struct { name string - invoke func(c *Client) (interface{}, error) + invoke func(c *Client) (any, error) fails bool serverResponse string - result func(c *Client) interface{} - check func(t *testing.T, c *Client, result interface{}) + result func(c *Client) any + check func(t *testing.T, c *Client, result any) } const base64B1 = "AAAAAMSdeyVO3QCekJTbQ4D7YEEGFv2nXPd6CfO5Kn3htI8P9tVA4+VXLyyMG12BUj6qB3CZ+JIFwWCcDF+KBHH0VSjJICSkegEAAAAAAAAAAAAAAQAAAABouegejA5skHm0udEF6HinbT8iPwHGDEBg0hpK90iZlB4ZSCG7BOr7BsvPXGDax360lvqKeNFuzaGI1RYNH50/dhQLxocy90JdsIOyodd1sOJGEjZIt7ztDEAHc2avJzz6tK+FOQMIZO/FEEikJdLJX0+iZXFcsmDRpB7lo2wWMSQbcoTXNg7leuR0VeDsKJ+YdvCuTG5WbiqWDECa6Yjj+bK4te5KR5jdLF5kLt03csyozZcd/X7NPt89IsX01zpX8ec3e+B2qySJIOhEf3cK0i+5U5wyXiFcRI8xkxMMIQIQOn990BZVhZf3lg0nxRakOU/ZaLnmUVXrSwE+QEBAbgwhAqe8Vf6GhOARl2jRBLoweVvcyGYZ6GSt0mFWcj7Rhc1iDCECs2Ir9AF73+MXxYrtX0x1PyBrfbiWBG+n13S7xL9/jcIMIQPZDAffY+aQzneRLhCrUazJRLZoYCN7YIxPj4MJ5x7mmRRBntDcOgIAAgAAAMDYpwAAAAAADHlDAAAAAACwBAAAAWi56B6MDmyQebS50QXoeKdtPyI/AQBbCwIY3fUFDBTunqIsJ+NL0BSPxBCOCPdOj1BIsgwUaLnoHowObJB5tLnRBeh4p20/Ij8UwB8MCHRyYW5zZmVyDBT1Y+pAvCg9TQ4FxI6jBbPyoHNA70FifVtSOQHGDEC8InWg8rQHWjklRojobu7kn4r0xZY2xWYs15ggVX4PQyEHpNTU6vZHT2TXRdPXAOKHhgWAttO0oTvo+9VZAjIVDEBF0qvBMlvmYJIYLqSoCjhBykcSN78UXrBjO5BKL8BpHtejWCld1VT6Z7nYrEBLgySD6HeMcp/fa6vqHzU220e/DECXtm5AA1jy9GFA7t8U6a+1uPrQFk4Ufp0UyXsun0PvN0NdhrHc37xm8k9Z0dB85V/7WLtkMaLLyjVNVIKImC76kxMMIQIQOn990BZVhZf3lg0nxRakOU/ZaLnmUVXrSwE+QEBAbgwhAqe8Vf6GhOARl2jRBLoweVvcyGYZ6GSt0mFWcj7Rhc1iDCECs2Ir9AF73+MXxYrtX0x1PyBrfbiWBG+n13S7xL9/jcIMIQPZDAffY+aQzneRLhCrUazJRLZoYCN7YIxPj4MJ5x7mmRRBntDcOgADAAAAwNinAAAAAACsiEMAAAAAALAEAAABaLnoHowObJB5tLnRBeh4p20/Ij8BAF8LAwDodkgXAAAADBTunqIsJ+NL0BSPxBCOCPdOj1BIsgwUaLnoHowObJB5tLnRBeh4p20/Ij8UwB8MCHRyYW5zZmVyDBTPduKL0AYsSkeO41VhARMZ88+k0kFifVtSOQHGDEDgj/SQT84EbWRZ4ZKhyjJTuLwVPDgVlQO3CGmgacItvni9nziJvTxziZXBG/0Hqkv68ddS1EH94RtWlqLQWRCjDEAWZUeSQ8KskILSvoWPN3836xpg/TYzOGiFVoePv91CFnap4fRFxdbporBgnZ/sUsjFZ74U8f+r0riqtvkdMMyGDEDx5iho79oDVYOCwIDH3K1UeDjAT6Hq9YsD9SCfJSE1rRsAdJPh2StYxdh9Jah1lwGbW0U+Wu6zpbVFf5CS6fFckxMMIQIQOn990BZVhZf3lg0nxRakOU/ZaLnmUVXrSwE+QEBAbgwhAqe8Vf6GhOARl2jRBLoweVvcyGYZ6GSt0mFWcj7Rhc1iDCECs2Ir9AF73+MXxYrtX0x1PyBrfbiWBG+n13S7xL9/jcIMIQPZDAffY+aQzneRLhCrUazJRLZoYCN7YIxPj4MJ5x7mmRRBntDcOg==" @@ -116,11 +116,11 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ "getapplicationlog": { { name: "positive", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetApplicationLog(util.Uint256{}, nil) }, serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"txid":"0x17145a039fca704fcdbeb46e6b210af98a1a9e5b9768e46ffc38f71c79ac2521","executions":[{"trigger":"Application","vmstate":"HALT","gasconsumed":"1","stack":[{"type":"Integer","value":"1"}],"notifications":[]}]}}`, - result: func(c *Client) interface{} { + result: func(c *Client) any { txHash, err := util.Uint256DecodeStringLE("17145a039fca704fcdbeb46e6b210af98a1a9e5b9768e46ffc38f71c79ac2521") if err != nil { panic(err) @@ -143,11 +143,11 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ "getbestblockhash": { { name: "positive", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetBestBlockHash() }, serverResponse: `{"jsonrpc":"2.0","id":1,"result":"0x773dd2dae4a9c9275290f89b56e67d7363ea4826dfd4fc13cc01cf73a44b0d0e"}`, - result: func(c *Client) interface{} { + result: func(c *Client) any { result, err := util.Uint256DecodeStringLE("773dd2dae4a9c9275290f89b56e67d7363ea4826dfd4fc13cc01cf73a44b0d0e") if err != nil { panic(err) @@ -159,29 +159,29 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ "getblock": { { name: "byIndex_positive", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetBlockByIndex(1) }, serverResponse: `{"id":1,"jsonrpc":"2.0","result":"` + base64B1 + `"}`, - result: func(c *Client) interface{} { + result: func(c *Client) any { b := getResultBlock1() return &b.Block }, }, { name: "byIndex_verbose_positive", - invoke: func(c *Client) (i interface{}, err error) { + invoke: func(c *Client) (i any, err error) { return c.GetBlockByIndexVerbose(1) }, serverResponse: `{"id":1,"jsonrpc":"2.0","result":` + b1Verbose + `}`, - result: func(c *Client) interface{} { + result: func(c *Client) any { res := getResultBlock1() return res }, }, { name: "byHash_positive", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { hash, err := util.Uint256DecodeStringLE("d151651e86680a7ecbc87babf3346a42e7bc9974414ce192c9c22ac4f2e9d043") if err != nil { panic(err) @@ -189,14 +189,14 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ return c.GetBlockByHash(hash) }, serverResponse: `{"id":1,"jsonrpc":"2.0","result":"` + base64B1 + `"}`, - result: func(c *Client) interface{} { + result: func(c *Client) any { b := getResultBlock1() return &b.Block }, }, { name: "byHash_verbose_positive", - invoke: func(c *Client) (i interface{}, err error) { + invoke: func(c *Client) (i any, err error) { hash, err := util.Uint256DecodeStringLE("86fe1061140b2ea791b0739fb9732abc6e5e47de4927228a1ac41de3d93eb7cb") if err != nil { panic(err) @@ -204,7 +204,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ return c.GetBlockByHashVerbose(hash) }, serverResponse: `{"id":1,"jsonrpc":"2.0","result":` + b1Verbose + `}`, - result: func(c *Client) interface{} { + result: func(c *Client) any { res := getResultBlock1() return res }, @@ -213,11 +213,11 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ "getblockcount": { { name: "positive", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetBlockCount() }, serverResponse: `{"jsonrpc":"2.0","id":1,"result":991991}`, - result: func(c *Client) interface{} { + result: func(c *Client) any { return uint32(991991) }, }, @@ -225,11 +225,11 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ "getblockhash": { { name: "positive", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetBlockHash(1) }, serverResponse: `{"jsonrpc":"2.0","id":1,"result":"0x4c1e879872344349067c3b1a30781eeb4f9040d3795db7922f513f6f9660b9b2"}`, - result: func(c *Client) interface{} { + result: func(c *Client) any { hash, err := util.Uint256DecodeStringLE("4c1e879872344349067c3b1a30781eeb4f9040d3795db7922f513f6f9660b9b2") if err != nil { panic(err) @@ -241,7 +241,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ "getblockheader": { { name: "positive", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { hash, err := util.Uint256DecodeStringLE("68e4bd688b852e807eef13a0ff7da7b02223e359a35153667e88f9cb4a3b0801") if err != nil { panic(err) @@ -249,14 +249,14 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ return c.GetBlockHeader(hash) }, serverResponse: `{"id":1,"jsonrpc":"2.0","result":"` + base64Header1 + `"}`, - result: func(c *Client) interface{} { + result: func(c *Client) any { b := getResultBlock1() return &b.Header }, }, { name: "verbose_positive", - invoke: func(c *Client) (i interface{}, err error) { + invoke: func(c *Client) (i any, err error) { hash, err := util.Uint256DecodeStringLE("cbb73ed9e31dc41a8a222749de475e6ebc2a73b99f73b091a72e0b146110fe86") if err != nil { panic(err) @@ -264,7 +264,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ return c.GetBlockHeaderVerbose(hash) }, serverResponse: `{"id":1,"jsonrpc":"2.0","result":` + header1Verbose + `}`, - result: func(c *Client) interface{} { + result: func(c *Client) any { b := getResultBlock1() return &result.Header{ Header: b.Header, @@ -280,11 +280,11 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ "getblockheadercount": { { name: "positive", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetBlockHeaderCount() }, serverResponse: `{"jsonrpc":"2.0","id":1,"result":2021}`, - result: func(c *Client) interface{} { + result: func(c *Client) any { return uint32(2021) }, }, @@ -292,11 +292,11 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ "getblocksysfee": { { name: "positive", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetBlockSysFee(1) }, serverResponse: `{"jsonrpc":"2.0","id":1,"result":"195500"}`, - result: func(c *Client) interface{} { + result: func(c *Client) any { return fixedn.Fixed8FromInt64(195500) }, }, @@ -304,11 +304,11 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ "getcommittee": { { name: "positive", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetCommittee() }, serverResponse: `{"jsonrpc":"2.0","id":1,"result":["02103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e"]}`, - result: func(c *Client) interface{} { + result: func(c *Client) any { member, err := keys.NewPublicKeyFromString("02103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e") if err != nil { panic(fmt.Errorf("failed to decode public key: %w", err)) @@ -320,11 +320,11 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ "getconnectioncount": { { name: "positive", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetConnectionCount() }, serverResponse: `{"jsonrpc":"2.0","id":1,"result":10}`, - result: func(c *Client) interface{} { + result: func(c *Client) any { return 10 }, }, @@ -332,7 +332,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ "getcontractstate": { { name: "positive, by hash", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { hash, err := util.Uint160DecodeStringLE("1b4357bff5a01bdf2a6581247cf9ed1e24629176") if err != nil { panic(err) @@ -340,7 +340,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ return c.GetContractStateByHash(hash) }, serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"id":0,"nef":{"magic":860243278,"compiler":"neo-go-3.0","script":"VgJXHwIMDWNvbnRyYWN0IGNhbGx4eVMTwEEFB5IWIXhKDANQdXSXJyQAAAAQVUGEGNYNIXJqeRDOeRHOU0FSoUH1IUURQCOPAgAASgwLdG90YWxTdXBwbHmXJxEAAABFAkBCDwBAI28CAABKDAhkZWNpbWFsc5cnDQAAAEUSQCNWAgAASgwEbmFtZZcnEgAAAEUMBFJ1YmxAIzwCAABKDAZzeW1ib2yXJxEAAABFDANSVUJAIyECAABKDAliYWxhbmNlT2aXJ2IAAAAQVUGEGNYNIXN5EM50bMoAFLQnIwAAAAwPaW52YWxpZCBhZGRyZXNzEVVBNtNSBiFFENsgQGtsUEEfLnsHIXUMCWJhbGFuY2VPZmxtUxPAQQUHkhYhRW1AI7IBAABKDAh0cmFuc2ZlcpcnKwEAABBVQYQY1g0hdnkQzncHbwfKABS0JyoAAAAMFmludmFsaWQgJ2Zyb20nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRHOdwhvCMoAFLQnKAAAAAwUaW52YWxpZCAndG8nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRLOdwlvCRC1JyIAAAAMDmludmFsaWQgYW1vdW50EVVBNtNSBiFFENsgQG5vB1BBHy57ByF3Cm8Kbwm1JyYAAAAMEmluc3VmZmljaWVudCBmdW5kcxFVQTbTUgYhRRDbIEBvCm8Jn3cKbm8HbwpTQVKhQfUhbm8IUEEfLnsHIXcLbwtvCZ53C25vCG8LU0FSoUH1IQwIdHJhbnNmZXJvB28IbwlUFMBBBQeSFiFFEUAjewAAAEoMBGluaXSXJ1AAAAAQVUGEGNYNIXcMEFVBh8PSZCF3DQJAQg8Adw5vDG8Nbw5TQVKhQfUhDAh0cmFuc2ZlcgwA2zBvDW8OVBTAQQUHkhYhRRFAIyMAAAAMEWludmFsaWQgb3BlcmF0aW9uQTbTUgY6IwUAAABFQA==","checksum":2512077441},"manifest":{"name":"Test","abi":{"methods":[],"events":[]},"groups":[],"features":{},"permissions":[],"trusts":[],"supportedstandards":[],"safemethods":[],"extra":null},"hash":"0x1b4357bff5a01bdf2a6581247cf9ed1e24629176"}}`, - result: func(c *Client) interface{} { + result: func(c *Client) any { script, err := base64.StdEncoding.DecodeString("VgJXHwIMDWNvbnRyYWN0IGNhbGx4eVMTwEEFB5IWIXhKDANQdXSXJyQAAAAQVUGEGNYNIXJqeRDOeRHOU0FSoUH1IUURQCOPAgAASgwLdG90YWxTdXBwbHmXJxEAAABFAkBCDwBAI28CAABKDAhkZWNpbWFsc5cnDQAAAEUSQCNWAgAASgwEbmFtZZcnEgAAAEUMBFJ1YmxAIzwCAABKDAZzeW1ib2yXJxEAAABFDANSVUJAIyECAABKDAliYWxhbmNlT2aXJ2IAAAAQVUGEGNYNIXN5EM50bMoAFLQnIwAAAAwPaW52YWxpZCBhZGRyZXNzEVVBNtNSBiFFENsgQGtsUEEfLnsHIXUMCWJhbGFuY2VPZmxtUxPAQQUHkhYhRW1AI7IBAABKDAh0cmFuc2ZlcpcnKwEAABBVQYQY1g0hdnkQzncHbwfKABS0JyoAAAAMFmludmFsaWQgJ2Zyb20nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRHOdwhvCMoAFLQnKAAAAAwUaW52YWxpZCAndG8nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRLOdwlvCRC1JyIAAAAMDmludmFsaWQgYW1vdW50EVVBNtNSBiFFENsgQG5vB1BBHy57ByF3Cm8Kbwm1JyYAAAAMEmluc3VmZmljaWVudCBmdW5kcxFVQTbTUgYhRRDbIEBvCm8Jn3cKbm8HbwpTQVKhQfUhbm8IUEEfLnsHIXcLbwtvCZ53C25vCG8LU0FSoUH1IQwIdHJhbnNmZXJvB28IbwlUFMBBBQeSFiFFEUAjewAAAEoMBGluaXSXJ1AAAAAQVUGEGNYNIXcMEFVBh8PSZCF3DQJAQg8Adw5vDG8Nbw5TQVKhQfUhDAh0cmFuc2ZlcgwA2zBvDW8OVBTAQQUHkhYhRRFAIyMAAAAMEWludmFsaWQgb3BlcmF0aW9uQTbTUgY6IwUAAABFQA==") if err != nil { panic(err) @@ -359,11 +359,11 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ }, { name: "positive, by address", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetContractStateByAddressOrName("NWiu5oejTu925aeL9Hc1LX8SvaJhE23h15") }, serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"id":0,"nef":{"magic":860243278,"compiler":"neo-go-3.0","script":"VgJXHwIMDWNvbnRyYWN0IGNhbGx4eVMTwEEFB5IWIXhKDANQdXSXJyQAAAAQVUGEGNYNIXJqeRDOeRHOU0FSoUH1IUURQCOPAgAASgwLdG90YWxTdXBwbHmXJxEAAABFAkBCDwBAI28CAABKDAhkZWNpbWFsc5cnDQAAAEUSQCNWAgAASgwEbmFtZZcnEgAAAEUMBFJ1YmxAIzwCAABKDAZzeW1ib2yXJxEAAABFDANSVUJAIyECAABKDAliYWxhbmNlT2aXJ2IAAAAQVUGEGNYNIXN5EM50bMoAFLQnIwAAAAwPaW52YWxpZCBhZGRyZXNzEVVBNtNSBiFFENsgQGtsUEEfLnsHIXUMCWJhbGFuY2VPZmxtUxPAQQUHkhYhRW1AI7IBAABKDAh0cmFuc2ZlcpcnKwEAABBVQYQY1g0hdnkQzncHbwfKABS0JyoAAAAMFmludmFsaWQgJ2Zyb20nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRHOdwhvCMoAFLQnKAAAAAwUaW52YWxpZCAndG8nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRLOdwlvCRC1JyIAAAAMDmludmFsaWQgYW1vdW50EVVBNtNSBiFFENsgQG5vB1BBHy57ByF3Cm8Kbwm1JyYAAAAMEmluc3VmZmljaWVudCBmdW5kcxFVQTbTUgYhRRDbIEBvCm8Jn3cKbm8HbwpTQVKhQfUhbm8IUEEfLnsHIXcLbwtvCZ53C25vCG8LU0FSoUH1IQwIdHJhbnNmZXJvB28IbwlUFMBBBQeSFiFFEUAjewAAAEoMBGluaXSXJ1AAAAAQVUGEGNYNIXcMEFVBh8PSZCF3DQJAQg8Adw5vDG8Nbw5TQVKhQfUhDAh0cmFuc2ZlcgwA2zBvDW8OVBTAQQUHkhYhRRFAIyMAAAAMEWludmFsaWQgb3BlcmF0aW9uQTbTUgY6IwUAAABFQA==","checksum":2512077441},"manifest":{"name":"Test","abi":{"methods":[],"events":[]},"groups":[],"features":{},"permissions":[],"trusts":[],"supportedstandards":[],"safemethods":[],"extra":null},"hash":"0x1b4357bff5a01bdf2a6581247cf9ed1e24629176"}}`, - result: func(c *Client) interface{} { + result: func(c *Client) any { script, err := base64.StdEncoding.DecodeString("VgJXHwIMDWNvbnRyYWN0IGNhbGx4eVMTwEEFB5IWIXhKDANQdXSXJyQAAAAQVUGEGNYNIXJqeRDOeRHOU0FSoUH1IUURQCOPAgAASgwLdG90YWxTdXBwbHmXJxEAAABFAkBCDwBAI28CAABKDAhkZWNpbWFsc5cnDQAAAEUSQCNWAgAASgwEbmFtZZcnEgAAAEUMBFJ1YmxAIzwCAABKDAZzeW1ib2yXJxEAAABFDANSVUJAIyECAABKDAliYWxhbmNlT2aXJ2IAAAAQVUGEGNYNIXN5EM50bMoAFLQnIwAAAAwPaW52YWxpZCBhZGRyZXNzEVVBNtNSBiFFENsgQGtsUEEfLnsHIXUMCWJhbGFuY2VPZmxtUxPAQQUHkhYhRW1AI7IBAABKDAh0cmFuc2ZlcpcnKwEAABBVQYQY1g0hdnkQzncHbwfKABS0JyoAAAAMFmludmFsaWQgJ2Zyb20nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRHOdwhvCMoAFLQnKAAAAAwUaW52YWxpZCAndG8nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRLOdwlvCRC1JyIAAAAMDmludmFsaWQgYW1vdW50EVVBNtNSBiFFENsgQG5vB1BBHy57ByF3Cm8Kbwm1JyYAAAAMEmluc3VmZmljaWVudCBmdW5kcxFVQTbTUgYhRRDbIEBvCm8Jn3cKbm8HbwpTQVKhQfUhbm8IUEEfLnsHIXcLbwtvCZ53C25vCG8LU0FSoUH1IQwIdHJhbnNmZXJvB28IbwlUFMBBBQeSFiFFEUAjewAAAEoMBGluaXSXJ1AAAAAQVUGEGNYNIXcMEFVBh8PSZCF3DQJAQg8Adw5vDG8Nbw5TQVKhQfUhDAh0cmFuc2ZlcgwA2zBvDW8OVBTAQQUHkhYhRRFAIyMAAAAMEWludmFsaWQgb3BlcmF0aW9uQTbTUgY6IwUAAABFQA==") if err != nil { panic(err) @@ -382,11 +382,11 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ }, { name: "positive, by id", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetContractStateByID(0) }, serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"id":0,"nef":{"magic":860243278,"compiler":"neo-go-3.0","script":"VgJXHwIMDWNvbnRyYWN0IGNhbGx4eVMTwEEFB5IWIXhKDANQdXSXJyQAAAAQVUGEGNYNIXJqeRDOeRHOU0FSoUH1IUURQCOPAgAASgwLdG90YWxTdXBwbHmXJxEAAABFAkBCDwBAI28CAABKDAhkZWNpbWFsc5cnDQAAAEUSQCNWAgAASgwEbmFtZZcnEgAAAEUMBFJ1YmxAIzwCAABKDAZzeW1ib2yXJxEAAABFDANSVUJAIyECAABKDAliYWxhbmNlT2aXJ2IAAAAQVUGEGNYNIXN5EM50bMoAFLQnIwAAAAwPaW52YWxpZCBhZGRyZXNzEVVBNtNSBiFFENsgQGtsUEEfLnsHIXUMCWJhbGFuY2VPZmxtUxPAQQUHkhYhRW1AI7IBAABKDAh0cmFuc2ZlcpcnKwEAABBVQYQY1g0hdnkQzncHbwfKABS0JyoAAAAMFmludmFsaWQgJ2Zyb20nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRHOdwhvCMoAFLQnKAAAAAwUaW52YWxpZCAndG8nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRLOdwlvCRC1JyIAAAAMDmludmFsaWQgYW1vdW50EVVBNtNSBiFFENsgQG5vB1BBHy57ByF3Cm8Kbwm1JyYAAAAMEmluc3VmZmljaWVudCBmdW5kcxFVQTbTUgYhRRDbIEBvCm8Jn3cKbm8HbwpTQVKhQfUhbm8IUEEfLnsHIXcLbwtvCZ53C25vCG8LU0FSoUH1IQwIdHJhbnNmZXJvB28IbwlUFMBBBQeSFiFFEUAjewAAAEoMBGluaXSXJ1AAAAAQVUGEGNYNIXcMEFVBh8PSZCF3DQJAQg8Adw5vDG8Nbw5TQVKhQfUhDAh0cmFuc2ZlcgwA2zBvDW8OVBTAQQUHkhYhRRFAIyMAAAAMEWludmFsaWQgb3BlcmF0aW9uQTbTUgY6IwUAAABFQA==","checksum":2512077441},"manifest":{"name":"Test","abi":{"methods":[],"events":[]},"groups":[],"features":{},"permissions":[],"trusts":[],"supportedstandards":[],"safemethods":[],"extra":null},"hash":"0x1b4357bff5a01bdf2a6581247cf9ed1e24629176"}}`, - result: func(c *Client) interface{} { + result: func(c *Client) any { script, err := base64.StdEncoding.DecodeString("VgJXHwIMDWNvbnRyYWN0IGNhbGx4eVMTwEEFB5IWIXhKDANQdXSXJyQAAAAQVUGEGNYNIXJqeRDOeRHOU0FSoUH1IUURQCOPAgAASgwLdG90YWxTdXBwbHmXJxEAAABFAkBCDwBAI28CAABKDAhkZWNpbWFsc5cnDQAAAEUSQCNWAgAASgwEbmFtZZcnEgAAAEUMBFJ1YmxAIzwCAABKDAZzeW1ib2yXJxEAAABFDANSVUJAIyECAABKDAliYWxhbmNlT2aXJ2IAAAAQVUGEGNYNIXN5EM50bMoAFLQnIwAAAAwPaW52YWxpZCBhZGRyZXNzEVVBNtNSBiFFENsgQGtsUEEfLnsHIXUMCWJhbGFuY2VPZmxtUxPAQQUHkhYhRW1AI7IBAABKDAh0cmFuc2ZlcpcnKwEAABBVQYQY1g0hdnkQzncHbwfKABS0JyoAAAAMFmludmFsaWQgJ2Zyb20nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRHOdwhvCMoAFLQnKAAAAAwUaW52YWxpZCAndG8nIGFkZHJlc3MRVUE201IGIUUQ2yBAeRLOdwlvCRC1JyIAAAAMDmludmFsaWQgYW1vdW50EVVBNtNSBiFFENsgQG5vB1BBHy57ByF3Cm8Kbwm1JyYAAAAMEmluc3VmZmljaWVudCBmdW5kcxFVQTbTUgYhRRDbIEBvCm8Jn3cKbm8HbwpTQVKhQfUhbm8IUEEfLnsHIXcLbwtvCZ53C25vCG8LU0FSoUH1IQwIdHJhbnNmZXJvB28IbwlUFMBBBQeSFiFFEUAjewAAAEoMBGluaXSXJ1AAAAAQVUGEGNYNIXcMEFVBh8PSZCF3DQJAQg8Adw5vDG8Nbw5TQVKhQfUhDAh0cmFuc2ZlcgwA2zBvDW8OVBTAQQUHkhYhRRFAIyMAAAAMEWludmFsaWQgb3BlcmF0aW9uQTbTUgY6IwUAAABFQA==") if err != nil { panic(err) @@ -407,11 +407,11 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ "getFeePerByte": { { name: "positive", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetFeePerByte() }, serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"state":"HALT","gasconsumed":"2007390","script":"EMAMDWdldEZlZVBlckJ5dGUMFJphpG7sl7iTBtfOgfFbRiCR0AkyQWJ9W1I=","stack":[{"type":"Integer","value":"1000"}],"tx":null}}`, - result: func(c *Client) interface{} { + result: func(c *Client) any { return int64(1000) }, }, @@ -419,11 +419,11 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ "getExecFeeFactor": { { name: "positive", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetExecFeeFactor() }, serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"state":"HALT","gasconsumed":"2007390","script":"EMAMDWdldEZlZVBlckJ5dGUMFJphpG7sl7iTBtfOgfFbRiCR0AkyQWJ9W1I=","stack":[{"type":"Integer","value":"1000"}],"tx":null}}`, - result: func(c *Client) interface{} { + result: func(c *Client) any { return int64(1000) }, }, @@ -431,11 +431,11 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ "getStoragePrice": { { name: "positive", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetStoragePrice() }, serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"state":"HALT","gasconsumed":"2007390","script":"EMAMDWdldEZlZVBlckJ5dGUMFJphpG7sl7iTBtfOgfFbRiCR0AkyQWJ9W1I=","stack":[{"type":"Integer","value":"100000"}],"tx":null}}`, - result: func(c *Client) interface{} { + result: func(c *Client) any { return int64(100000) }, }, @@ -443,11 +443,11 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ "getOraclePrice": { { name: "positive", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetOraclePrice() }, serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"state":"HALT","gasconsumed":"2007390","script":"EMAMDWdldEZlZVBlckJ5dGUMFJphpG7sl7iTBtfOgfFbRiCR0AkyQWJ9W1I=","stack":[{"type":"Integer","value":"10000000"}],"tx":null}}`, - result: func(c *Client) interface{} { + result: func(c *Client) any { return int64(10000000) }, }, @@ -455,11 +455,11 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ "getNNSPrice": { { name: "positive", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetNNSPrice(util.Uint160{1, 2, 3}) }, serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"state":"HALT","gasconsumed":"2007390","script":"EMAMDWdldEZlZVBlckJ5dGUMFJphpG7sl7iTBtfOgfFbRiCR0AkyQWJ9W1I=","stack":[{"type":"Integer","value":"1000000"}],"tx":null}}`, - result: func(c *Client) interface{} { + result: func(c *Client) any { return int64(1000000) }, }, @@ -467,11 +467,11 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ "getGasPerBlock": { { name: "positive", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetGasPerBlock() }, serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"state":"HALT","gasconsumed":"2007390","script":"EMAMDWdldEZlZVBlckJ5dGUMFJphpG7sl7iTBtfOgfFbRiCR0AkyQWJ9W1I=","stack":[{"type":"Integer","value":"500000000"}],"tx":null}}`, - result: func(c *Client) interface{} { + result: func(c *Client) any { return int64(500000000) }, }, @@ -479,11 +479,11 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ "getCandidateRegisterPrice": { { name: "positive", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetCandidateRegisterPrice() }, serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"state":"HALT","gasconsumed":"2007390","script":"EMAMDWdldEZlZVBlckJ5dGUMFJphpG7sl7iTBtfOgfFbRiCR0AkyQWJ9W1I=","stack":[{"type":"Integer","value":"100000000000"}],"tx":null}}`, - result: func(c *Client) interface{} { + result: func(c *Client) any { return int64(100000000000) }, }, @@ -491,11 +491,11 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ "getDesignatedByRole": { { name: "positive", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetDesignatedByRole(noderoles.P2PNotary, 10) }, serverResponse: `{"id" : 1,"result" : {"stack" : [{"value" : [{"type":"ByteString","value":"Aw0WkQoDc8WqpG18xPMTEgfHO6gRTVtMN0Mw6zw06fzl"},{"type":"ByteString","value":"A+bmJ9wIaj96Ygr+uQQvQ0AaUrQmj2b3AGnztAOkU3/L"}],"type" : "Array"}],"exception" : null,"script" : "ERQSwB8ME2dldERlc2lnbmF0ZWRCeVJvbGUMFOKV45FUTBeK2U8D7E3N/3hTTs9JQWJ9W1I=","gasconsumed" : "2028150","state" : "HALT"}, "jsonrpc" : "2.0"}`, - result: func(c *Client) interface{} { + result: func(c *Client) any { pk1Bytes, _ := base64.StdEncoding.DecodeString("Aw0WkQoDc8WqpG18xPMTEgfHO6gRTVtMN0Mw6zw06fzl") pk1, err := keys.NewPublicKeyFromBytes(pk1Bytes, elliptic.P256()) if err != nil { @@ -513,11 +513,11 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ "getMaxNotValidBeforeDelta": { { name: "positive", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetMaxNotValidBeforeDelta() }, serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"state":"HALT","gasconsumed":"2007390","script":"EMAMD2dldE1heEJsb2NrU2l6ZQwUmmGkbuyXuJMG186B8VtGIJHQCTJBYn1bUg==","stack":[{"type":"Integer","value":"262144"}],"tx":null}}`, - result: func(c *Client) interface{} { + result: func(c *Client) any { return int64(262144) }, }, @@ -525,11 +525,11 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ "isBlocked": { { name: "positive", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.IsBlocked(util.Uint160{1, 2, 3}) }, serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"state":"HALT","gasconsumed":"2007390","script":"EMAMEmdldEJsb2NrZWRBY2NvdW50cwwUmmGkbuyXuJMG186B8VtGIJHQCTJBYn1bUg==","stack":[{"type":"Boolean","value":false}],"tx":null}}`, - result: func(c *Client) interface{} { + result: func(c *Client) any { return false }, }, @@ -537,7 +537,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ "getnep11balances": { { name: "positive", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { hash, err := util.Uint160DecodeStringLE("1aada0032aba1ef6d1f07bbd8bec1d85f5380fb3") if err != nil { panic(err) @@ -545,7 +545,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ return c.GetNEP11Balances(hash) }, serverResponse: `{"jsonrpc":"2.0","id":1,"result":{"balance":[{"assethash":"a48b6e1291ba24211ad11bb90ae2a10bf1fcd5a8","symbol":"SOME","decimals":"42","name":"Contract","tokens":[{"tokenid":"abcdef","amount":"1","lastupdatedblock":251604}]}],"address":"NcEkNmgWmf7HQVQvzhxpengpnt4DXjmZLe"}}`, - result: func(c *Client) interface{} { + result: func(c *Client) any { hash, err := util.Uint160DecodeStringLE("a48b6e1291ba24211ad11bb90ae2a10bf1fcd5a8") if err != nil { panic(err) @@ -570,7 +570,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ "getnep17balances": { { name: "positive", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { hash, err := util.Uint160DecodeStringLE("1aada0032aba1ef6d1f07bbd8bec1d85f5380fb3") if err != nil { panic(err) @@ -578,7 +578,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ return c.GetNEP17Balances(hash) }, serverResponse: `{"jsonrpc":"2.0","id":1,"result":{"balance":[{"assethash":"a48b6e1291ba24211ad11bb90ae2a10bf1fcd5a8","symbol":"N17","decimals":"8","name":"Token","amount":"50000000000","lastupdatedblock":251604}],"address":"AY6eqWjsUFCzsVELG7yG72XDukKvC34p2w"}}`, - result: func(c *Client) interface{} { + result: func(c *Client) any { hash, err := util.Uint160DecodeStringLE("a48b6e1291ba24211ad11bb90ae2a10bf1fcd5a8") if err != nil { panic(err) @@ -600,7 +600,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ "getnep11properties": { { name: "positive", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { hash, err := util.Uint160DecodeStringLE("1aada0032aba1ef6d1f07bbd8bec1d85f5380fb3") if err != nil { panic(err) @@ -608,8 +608,8 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ return c.GetNEP11Properties(hash, []byte("abcdef")) }, // NcEkNmgWmf7HQVQvzhxpengpnt4DXjmZLe serverResponse: `{"jsonrpc":"2.0","id":1,"result":{"name":"sometoken","field1":"c29tZXRoaW5n","field2":null}}`, - result: func(c *Client) interface{} { - return map[string]interface{}{ + result: func(c *Client) any { + return map[string]any{ "name": "sometoken", "field1": []byte("something"), "field2": nil, @@ -620,7 +620,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ "getnep11transfers": { { name: "positive", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { hash, err := address.StringToUint160("NcEkNmgWmf7HQVQvzhxpengpnt4DXjmZLe") if err != nil { panic(err) @@ -628,7 +628,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ return c.GetNEP11Transfers(hash, nil, nil, nil, nil) }, serverResponse: `{"jsonrpc":"2.0","id":1,"result":{"sent":[],"received":[{"timestamp":1555651816,"assethash":"600c4f5200db36177e3e8a09e9f18e2fc7d12a0f","transferaddress":"NfgHwwTi3wHAS8aFAN243C5vGbkYDpqLHP","amount":"1","tokenid":"abcdef","blockindex":436036,"transfernotifyindex":0,"txhash":"df7683ece554ecfb85cf41492c5f143215dd43ef9ec61181a28f922da06aba58"}],"address":"NcEkNmgWmf7HQVQvzhxpengpnt4DXjmZLe"}}`, - result: func(c *Client) interface{} { + result: func(c *Client) any { assetHash, err := util.Uint160DecodeStringLE("600c4f5200db36177e3e8a09e9f18e2fc7d12a0f") if err != nil { panic(err) @@ -659,7 +659,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ "getnep17transfers": { { name: "positive", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { hash, err := address.StringToUint160("NcEkNmgWmf7HQVQvzhxpengpnt4DXjmZLe") if err != nil { panic(err) @@ -667,7 +667,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ return c.GetNEP17Transfers(hash, nil, nil, nil, nil) }, serverResponse: `{"jsonrpc":"2.0","id":1,"result":{"sent":[],"received":[{"timestamp":1555651816,"assethash":"600c4f5200db36177e3e8a09e9f18e2fc7d12a0f","transferaddress":"AYwgBNMepiv5ocGcyNT4mA8zPLTQ8pDBis","amount":"1000000","blockindex":436036,"transfernotifyindex":0,"txhash":"df7683ece554ecfb85cf41492c5f143215dd43ef9ec61181a28f922da06aba58"}],"address":"NcEkNmgWmf7HQVQvzhxpengpnt4DXjmZLe"}}`, - result: func(c *Client) interface{} { + result: func(c *Client) any { assetHash, err := util.Uint160DecodeStringLE("600c4f5200db36177e3e8a09e9f18e2fc7d12a0f") if err != nil { panic(err) @@ -697,11 +697,11 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ "getpeers": { { name: "positive", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetPeers() }, serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"unconnected":[{"address":"172.200.0.1","port":"20333"}],"connected":[{"address":"127.0.0.1","port":"20335"}],"bad":[{"address":"172.200.0.254","port":"20332"}]}}`, - result: func(c *Client) interface{} { + result: func(c *Client) any { return &result.GetPeers{ Unconnected: result.Peers{ { @@ -728,11 +728,11 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ "getrawmempool": { { name: "positive", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetRawMemPool() }, serverResponse: `{"jsonrpc":"2.0","id":1,"result":["0x9786cce0dddb524c40ddbdd5e31a41ed1f6b5c8a683c122f627ca4a007a7cf4e"]}`, - result: func(c *Client) interface{} { + result: func(c *Client) any { hash, err := util.Uint256DecodeStringLE("9786cce0dddb524c40ddbdd5e31a41ed1f6b5c8a683c122f627ca4a007a7cf4e") if err != nil { panic(err) @@ -744,7 +744,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ "getrawtransaction": { { name: "positive", - invoke: func(c *Client) (i interface{}, err error) { + invoke: func(c *Client) (i any, err error) { hash, err := util.Uint256DecodeStringLE("f5fbd303799f24ba247529d7544d4276cca54ea79f4b98095f2b0557313c5275") if err != nil { panic(err) @@ -752,14 +752,14 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ return c.GetRawTransaction(hash) }, serverResponse: `{"id":1,"jsonrpc":"2.0","result":"` + base64TxMoveNeo + `"}`, - result: func(c *Client) interface{} { + result: func(c *Client) any { tx := getTxMoveNeo() return &tx.Transaction }, }, { name: "verbose_positive", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { hash, err := util.Uint256DecodeStringLE("f5fbd303799f24ba247529d7544d4276cca54ea79f4b98095f2b0557313c5275") if err != nil { panic(err) @@ -772,7 +772,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ return out, nil }, serverResponse: `{"id":1,"jsonrpc":"2.0","result":` + txMoveNeoVerbose + `}`, - result: func(c *Client) interface{} { + result: func(c *Client) any { return getTxMoveNeo() }, }, @@ -780,11 +780,11 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ "getstateroot": { { name: "positive, by height", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetStateRootByHeight(5) }, serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"version":0,"index":5,"roothash":"0x65d19151694321e70c6d184b37a2bcf7af4a2c60c099af332a4f7815e3670686","witnesses":[]}}`, - result: func(c *Client) interface{} { + result: func(c *Client) any { h, err := util.Uint256DecodeStringLE("65d19151694321e70c6d184b37a2bcf7af4a2c60c099af332a4f7815e3670686") if err != nil { panic(err) @@ -799,7 +799,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ }, { name: "positive, by hash", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { hash, err := util.Uint256DecodeStringLE("86fe1061140b2ea791b0739fb9732abc6e5e47de4927228a1ac41de3d93eb7cb") if err != nil { panic(err) @@ -807,7 +807,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ return c.GetStateRootByBlockHash(hash) }, serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"version":0,"index":5,"roothash":"0x65d19151694321e70c6d184b37a2bcf7af4a2c60c099af332a4f7815e3670686","witnesses":[]}}`, - result: func(c *Client) interface{} { + result: func(c *Client) any { h, _ := util.Uint256DecodeStringLE("65d19151694321e70c6d184b37a2bcf7af4a2c60c099af332a4f7815e3670686") return &state.MPTRoot{ Version: 0, @@ -821,13 +821,13 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ "getstate": { { name: "positive", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { root, _ := util.Uint256DecodeStringLE("252e9d73d49c95c7618d40650da504e05183a1b2eed0685e42c360413c329170") cHash, _ := util.Uint160DecodeStringLE("5c9e40a12055c6b9e3f72271c9779958c842135d") return c.GetState(root, cHash, []byte("testkey")) }, serverResponse: `{"id":1,"jsonrpc":"2.0","result":"dGVzdHZhbHVl"}`, - result: func(c *Client) interface{} { + result: func(c *Client) any { return []byte("testvalue") }, }, @@ -835,14 +835,14 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ "getproof": { { name: "positive", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { root, _ := util.Uint256DecodeStringLE("272002b11a6a39035c719defec3e4e6a8d1f4ae37a995b44734911413fcc2ba5") cHash, _ := util.Uint160DecodeStringLE("cc5e4edd9f5f8dba8bb65734541df7a1c081c67b") key := []byte{10} return c.GetProof(root, cHash, key) }, serverResponse: `{"jsonrpc":"2.0","id":1,"result":"Bfn///8KBiQBAQ8DogBnMdiiPTEW05A6bJPmQ2TNVpuca/nB1rJRdQX7R4SyAAQEBAQEBAQDHvo5Rc9v\u002BWSpfsnMXM75ku\u002BZjvbLJhWXn/lh6L\u002B1yB0EA4k\u002Bsx4f7IgmdHNm3wRMpj5kTU4l0gChSGppo5p5wZyWA2\u002BKSFn16W6tRrGSfJob\u002BgqJukLcNDk0DBFYW2wIS2/NAzkugdLfZRXHOLqq5XJr89ElzlqyXU1o9D87l9YOcXjGBAQEA7oDTOxuU4iMAKPuhn5eJjzsM56bQrx3uORa8LKm42oDBCkBBg8PDw8PDwN96s39UOSCwMJmMQZzNjfNAPCbRRyke1B4VRKqOZ0NHlIAA2woQ13XO4Ug2aQ/cW4WBricVcUVqobFUU0dnRPtfIHeAxuYERXsV6HwdGjW\u002BhtpM0FEkw/mllbH5pyhn\u002BBx4r8wBAQEBAQEBAQEBAQEBAQEJAEBCgPXvpMqBogTeGhXjtFY4Rsn9bY/PgNX0l4iYOHMzUBQQgQCAugD"}`, - result: func(c *Client) interface{} { + result: func(c *Client) any { b, _ := base64.StdEncoding.DecodeString("Bfn///8KBiQBAQ8DogBnMdiiPTEW05A6bJPmQ2TNVpuca/nB1rJRdQX7R4SyAAQEBAQEBAQDHvo5Rc9v\u002BWSpfsnMXM75ku\u002BZjvbLJhWXn/lh6L\u002B1yB0EA4k\u002Bsx4f7IgmdHNm3wRMpj5kTU4l0gChSGppo5p5wZyWA2\u002BKSFn16W6tRrGSfJob\u002BgqJukLcNDk0DBFYW2wIS2/NAzkugdLfZRXHOLqq5XJr89ElzlqyXU1o9D87l9YOcXjGBAQEA7oDTOxuU4iMAKPuhn5eJjzsM56bQrx3uORa8LKm42oDBCkBBg8PDw8PDwN96s39UOSCwMJmMQZzNjfNAPCbRRyke1B4VRKqOZ0NHlIAA2woQ13XO4Ug2aQ/cW4WBricVcUVqobFUU0dnRPtfIHeAxuYERXsV6HwdGjW\u002BhtpM0FEkw/mllbH5pyhn\u002BBx4r8wBAQEBAQEBAQEBAQEBAQEJAEBCgPXvpMqBogTeGhXjtFY4Rsn9bY/PgNX0l4iYOHMzUBQQgQCAugD") proof := &result.ProofWithKey{} r := io.NewBinReaderFromBuf(b) @@ -852,7 +852,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ }, { name: "not found", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { root, _ := util.Uint256DecodeStringLE("272002b11a6a39035c719defec3e4e6a8d1f4ae37a995b44734911413fcc2ba5") cHash, _ := util.Uint160DecodeStringLE("cc5e4edd9f5f8dba8bb65734541df7a1c081c67b") key := []byte{01} @@ -865,7 +865,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ "verifyproof": { { name: "positive", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { root, _ := util.Uint256DecodeStringLE("272002b11a6a39035c719defec3e4e6a8d1f4ae37a995b44734911413fcc2ba5") b, _ := base64.StdEncoding.DecodeString("Bfn///8KBiQBAQ8DogBnMdiiPTEW05A6bJPmQ2TNVpuca/nB1rJRdQX7R4SyAAQEBAQEBAQDHvo5Rc9v\u002BWSpfsnMXM75ku\u002BZjvbLJhWXn/lh6L\u002B1yB0EA4k\u002Bsx4f7IgmdHNm3wRMpj5kTU4l0gChSGppo5p5wZyWA2\u002BKSFn16W6tRrGSfJob\u002BgqJukLcNDk0DBFYW2wIS2/NAzkugdLfZRXHOLqq5XJr89ElzlqyXU1o9D87l9YOcXjGBAQEA7oDTOxuU4iMAKPuhn5eJjzsM56bQrx3uORa8LKm42oDBCkBBg8PDw8PDwN96s39UOSCwMJmMQZzNjfNAPCbRRyke1B4VRKqOZ0NHlIAA2woQ13XO4Ug2aQ/cW4WBricVcUVqobFUU0dnRPtfIHeAxuYERXsV6HwdGjW\u002BhtpM0FEkw/mllbH5pyhn\u002BBx4r8wBAQEBAQEBAQEBAQEBAQEJAEBCgPXvpMqBogTeGhXjtFY4Rsn9bY/PgNX0l4iYOHMzUBQQgQCAugD") proof := &result.ProofWithKey{} @@ -874,13 +874,13 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ return c.VerifyProof(root, proof) }, serverResponse: `{"jsonrpc":"2.0","id":1,"result":"6AM="}`, - result: func(c *Client) interface{} { + result: func(c *Client) any { return bigint.ToPreallocatedBytes(big.NewInt(1000), nil) }, }, { name: "fail", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { root, _ := util.Uint256DecodeStringLE("272002b11a6a39035c719defec3e4e6a8d1f4ae37a995b44734911413fcc2ba5") b, _ := base64.StdEncoding.DecodeString("Bfn///8KBiQBAQ8DogBnMdiiPTEW05A6bJPmQ2TNVpuca/nB1rJRdQX7R4SyAAQEBAQEBAQDHvo5Rc9v\u002BWSpfsnMXM75ku\u002BZjvbLJhWXn/lh6L\u002B1yB0EA4k\u002Bsx4f7IgmdHNm3wRMpj5kTU4l0gChSGppo5p5wZyWA2\u002BKSFn16W6tRrGSfJob\u002BgqJukLcNDk0DBFYW2wIS2/NAzkugdLfZRXHOLqq5XJr89ElzlqyXU1o9D87l9YOcXjGBAQEA7oDTOxuU4iMAKPuhn5eJjzsM56bQrx3uORa8LKm42oDBCkBBg8PDw8PDwN96s39UOSCwMJmMQZzNjfNAPCbRRyke1B4VRKqOZ0NHlIAA2woQ13XO4Ug2aQ/cW4WBricVcUVqobFUU0dnRPtfIHeAxuYERXsV6HwdGjW\u002BhtpM0FEkw/mllbH5pyhn\u002BBx4r8wBAQEBAQEBAQEBAQEBAQEJAEBCgPXvpMqBogTeGhXjtFY4Rsn9bY/PgNX0l4iYOHMzUBQQgQCAugD") proof := &result.ProofWithKey{} @@ -895,14 +895,14 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ "findstates": { { name: "positive", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { root, _ := util.Uint256DecodeStringLE("252e9d73d49c95c7618d40650da504e05183a1b2eed0685e42c360413c329170") cHash, _ := util.Uint160DecodeStringLE("5c9e40a12055c6b9e3f72271c9779958c842135d") count := 1 return c.FindStates(root, cHash, []byte("aa"), []byte("aa00"), &count) }, serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"results":[{"key":"YWExMA==","value":"djI="}],"firstProof":"CAEAAABhYTEwCXIAA5KNHjQ1+LFX4lQBLjMAhaLtTJnfuI86O7WnNdlshsYWBAQEBAQEBAQDTzD7MJp2KW6E8BNVjjjgZMTAjI/GI3ZrTmR2UUOtSeIEBAQEBAPKPqb0qnb4Ywz6gqpNKCUNQsfBmAnKc5p3dxokSQRpwgRSAAQDPplG1wee4KOfkehaF94R5uoKSgvQL1j5gkFTN4ywYaIEBAOhOyI39MZfoKc940g57XeqwRnxh7P62fKjnfEtBzQxHQQEBAQEBAQEBAQEBCkBBgAAAAAAAAM6A1UrwFYZAEMfe6go3jX25xz2sHsovQ2UO/UHqZZOXLIABAOwg7pkXyaTR85yQIvYnoGaG/OVRLRHOj+nhZnXb6dVtAQEBAPnciBUp3uspLQTajKTlAxgrNe+3tlqlbwlNRkz0eNmhQMzoMcWOFi9nCyn+eM5lA6Pq67DxzTQDlHljh8g8kRtJAPq9hxzTgreK0qDTavsethixguZYfV7wDmKfumMglnoqQQEBAQEBAM1x2dVBdf5BJ0Xvw2qqhvpKqxdHb8/HMFWiXkJj1uAAQQEJgEDAQYBA5kV2WLkgey9C5z6gZT69VLKcEuwyY8P853rNtGhT3NeUgAEBAQDiX59K9PuJ5RE7Z1uj7q/QJ8FGf8avLdWM7hwmWkVH2gEBAQEBAQEBAQEBAQD1SubX5XhFHcUOWdUzg1bXmDwWJwt+wpU3FOdFkU1PXBSAAQDHCzfEQyqwOO263EE6HER1vWDrwz8JiEHEOXfZ3kX7NYEBAQDEH++Hy8wBcniKuWVevaAwzHCh60kzncU30E5fDC3gJsEBAQEBAQEBAQEBCUBAgMAA1wt18LbxMKdYcJ+nEDMMWZbRsu550l8HGhcYhpl6DjSBAICdjI=","truncated":true}}`, - result: func(c *Client) interface{} { + result: func(c *Client) any { proofB, _ := base64.StdEncoding.DecodeString("CAEAAABhYTEwCXIAA5KNHjQ1+LFX4lQBLjMAhaLtTJnfuI86O7WnNdlshsYWBAQEBAQEBAQDTzD7MJp2KW6E8BNVjjjgZMTAjI/GI3ZrTmR2UUOtSeIEBAQEBAPKPqb0qnb4Ywz6gqpNKCUNQsfBmAnKc5p3dxokSQRpwgRSAAQDPplG1wee4KOfkehaF94R5uoKSgvQL1j5gkFTN4ywYaIEBAOhOyI39MZfoKc940g57XeqwRnxh7P62fKjnfEtBzQxHQQEBAQEBAQEBAQEBCkBBgAAAAAAAAM6A1UrwFYZAEMfe6go3jX25xz2sHsovQ2UO/UHqZZOXLIABAOwg7pkXyaTR85yQIvYnoGaG/OVRLRHOj+nhZnXb6dVtAQEBAPnciBUp3uspLQTajKTlAxgrNe+3tlqlbwlNRkz0eNmhQMzoMcWOFi9nCyn+eM5lA6Pq67DxzTQDlHljh8g8kRtJAPq9hxzTgreK0qDTavsethixguZYfV7wDmKfumMglnoqQQEBAQEBAM1x2dVBdf5BJ0Xvw2qqhvpKqxdHb8/HMFWiXkJj1uAAQQEJgEDAQYBA5kV2WLkgey9C5z6gZT69VLKcEuwyY8P853rNtGhT3NeUgAEBAQDiX59K9PuJ5RE7Z1uj7q/QJ8FGf8avLdWM7hwmWkVH2gEBAQEBAQEBAQEBAQD1SubX5XhFHcUOWdUzg1bXmDwWJwt+wpU3FOdFkU1PXBSAAQDHCzfEQyqwOO263EE6HER1vWDrwz8JiEHEOXfZ3kX7NYEBAQDEH++Hy8wBcniKuWVevaAwzHCh60kzncU30E5fDC3gJsEBAQEBAQEBAQEBCUBAgMAA1wt18LbxMKdYcJ+nEDMMWZbRsu550l8HGhcYhpl6DjSBAICdjI=") proof := &result.ProofWithKey{} r := io.NewBinReaderFromBuf(proofB) @@ -918,11 +918,11 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ "getstateheight": { { name: "positive", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetStateHeight() }, serverResponse: `{"jsonrpc":"2.0","id":1,"result":{"localrootindex":11646,"validatedrootindex":11645}}`, - result: func(c *Client) interface{} { + result: func(c *Client) any { return &result.StateHeight{ Local: 11646, Validated: 11645, @@ -933,7 +933,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ "getstorage": { { name: "by hash, positive", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { hash, err := util.Uint160DecodeStringLE("03febccf81ac85e3d795bc5cbd4e84e907812aa3") if err != nil { panic(err) @@ -945,7 +945,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ return c.GetStorageByHash(hash, key) }, serverResponse: `{"jsonrpc":"2.0","id":1,"result":"TGlu"}`, - result: func(c *Client) interface{} { + result: func(c *Client) any { value, err := hex.DecodeString("4c696e") if err != nil { panic(err) @@ -955,7 +955,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ }, { name: "by ID, positive", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { key, err := hex.DecodeString("5065746572") if err != nil { panic(err) @@ -963,7 +963,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ return c.GetStorageByID(-1, key) }, serverResponse: `{"jsonrpc":"2.0","id":1,"result":"TGlu"}`, - result: func(c *Client) interface{} { + result: func(c *Client) any { value, err := hex.DecodeString("4c696e") if err != nil { panic(err) @@ -975,7 +975,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ "gettransactionheight": { { name: "positive", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { hash, err := util.Uint256DecodeStringLE("cb6ddb5f99d6af4c94a6c396d5294472f2eebc91a2c933e0f527422296fa9fb2") if err != nil { panic(err) @@ -983,7 +983,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ return c.GetTransactionHeight(hash) }, serverResponse: `{"jsonrpc":"2.0","id":1,"result":1}`, - result: func(c *Client) interface{} { + result: func(c *Client) any { return uint32(1) }, }, @@ -991,11 +991,11 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ "getunclaimedgas": { { name: "positive", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetUnclaimedGas("NMipL5VsNoLUBUJKPKLhxaEbPQVCZnyJyB") }, serverResponse: `{"jsonrpc":"2.0","id":1,"result":{"address":"NMipL5VsNoLUBUJKPKLhxaEbPQVCZnyJyB","unclaimed":"897299680935"}}`, - result: func(c *Client) interface{} { + result: func(c *Client) any { addr, err := address.StringToUint160("NMipL5VsNoLUBUJKPKLhxaEbPQVCZnyJyB") if err != nil { panic(fmt.Errorf("failed to parse UnclaimedGas address: %w", err)) @@ -1010,12 +1010,12 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ "getcandidates": { { name: "positive", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetCandidates() }, serverResponse: `{"id":1,"jsonrpc":"2.0","result":[{"publickey":"02b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc2","votes":"0","active":true},{"publickey":"02103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e","votes":"0","active":true},{"publickey":"03d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699","votes":"0","active":true},{"publickey":"02a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd62","votes":"0","active":true}]}`, - result: func(c *Client) interface{} { return []result.Candidate{} }, - check: func(t *testing.T, c *Client, uns interface{}) { + result: func(c *Client) any { return []result.Candidate{} }, + check: func(t *testing.T, c *Client, uns any) { res, ok := uns.([]result.Candidate) require.True(t, ok) assert.Equal(t, 4, len(res)) @@ -1025,12 +1025,12 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ "getvalidators": { { name: "positive", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetNextBlockValidators() }, serverResponse: `{"id":1,"jsonrpc":"2.0","result":[{"publickey":"02b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc2","votes":"0","active":true},{"publickey":"02103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e","votes":"0","active":true},{"publickey":"03d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699","votes":"0","active":true},{"publickey":"02a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd62","votes":"0","active":true}]}`, - result: func(c *Client) interface{} { return []result.Validator{} }, - check: func(t *testing.T, c *Client, uns interface{}) { + result: func(c *Client) any { return []result.Validator{} }, + check: func(t *testing.T, c *Client, uns any) { res, ok := uns.([]result.Validator) require.True(t, ok) assert.Equal(t, 4, len(res)) @@ -1040,11 +1040,11 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ "getversion": { { name: "positive", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetVersion() }, serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"tcpport":20332,"wsport":20342,"nonce":2153672787,"useragent":"/NEO-GO:0.73.1-pre-273-ge381358/"}}`, - result: func(c *Client) interface{} { + result: func(c *Client) any { return &result.Version{ TCPPort: uint16(20332), WSPort: uint16(20342), @@ -1060,7 +1060,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ "invokefunction": { { name: "positive, by scripthash", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { hash, err := util.Uint160DecodeStringLE("91b83e96f2a7c4fdf0c1688441ec61986c7cae26") if err != nil { panic(err) @@ -1079,10 +1079,10 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ }}) }, serverResponse: `{"jsonrpc":"2.0","id":1,"result":{"script":"FCaufGyYYexBhGjB8P3Ep/KWPriRUcEJYmFsYW5jZU9mZ74557Vi9gy/4q68o3Wi5e4oc3yv","state":"HALT","gasconsumed":"31100000","stack":[{"type":"ByteString","value":"JivsCEQy"}],"tx":"AAgAAACAlpgAAAAAAAIEEwAAAAAAsAQAAAGqis+FnU/kArNOZz8hVoIXlqSI6wEAVwHoAwwUqorPhZ1P5AKzTmc/IVaCF5akiOsMFOeetm08E0pKd27oB9LluEbdpP2wE8AMCHRyYW5zZmVyDBTnnrZtPBNKSndu6AfS5bhG3aT9sEFifVtSOAFCDEDYNAh3TUvYsZrocFYdBvJ0Trdnj1jRuQzy9Q6YroP2Cwgk4v7q3vbeZBikz8Q7vB+RbDPsWUy+ZiqdkkeG4XoUKQwhArNiK/QBe9/jF8WK7V9MdT8ga324lgRvp9d0u8S/f43CC0GVRA14"}}`, - result: func(c *Client) interface{} { + result: func(c *Client) any { return &result.Invoke{} }, - check: func(t *testing.T, c *Client, uns interface{}) { + check: func(t *testing.T, c *Client, uns any) { res, ok := uns.(*result.Invoke) require.True(t, ok) bytes, err := hex.DecodeString("262bec084432") @@ -1102,7 +1102,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ }, { name: "positive, FAULT state", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { hash, err := util.Uint160DecodeStringLE("91b83e96f2a7c4fdf0c1688441ec61986c7cae26") if err != nil { panic(err) @@ -1121,10 +1121,10 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ }}) }, serverResponse: `{"jsonrpc":"2.0","id":1,"result":{"script":"FCaufGyYYexBhGjB8P3Ep/KWPriRUcEJYmFsYW5jZU9mZ74557Vi9gy/4q68o3Wi5e4oc3yv","state":"FAULT","gasconsumed":"31100000","stack":[{"type":"ByteString","value":"JivsCEQy"}],"tx":"AAgAAACAlpgAAAAAAAIEEwAAAAAAsAQAAAGqis+FnU/kArNOZz8hVoIXlqSI6wEAVwHoAwwUqorPhZ1P5AKzTmc/IVaCF5akiOsMFOeetm08E0pKd27oB9LluEbdpP2wE8AMCHRyYW5zZmVyDBTnnrZtPBNKSndu6AfS5bhG3aT9sEFifVtSOAFCDEDYNAh3TUvYsZrocFYdBvJ0Trdnj1jRuQzy9Q6YroP2Cwgk4v7q3vbeZBikz8Q7vB+RbDPsWUy+ZiqdkkeG4XoUKQwhArNiK/QBe9/jF8WK7V9MdT8ga324lgRvp9d0u8S/f43CC0GVRA14","exception":"gas limit exceeded"}}`, - result: func(c *Client) interface{} { + result: func(c *Client) any { return &result.Invoke{} }, - check: func(t *testing.T, c *Client, uns interface{}) { + check: func(t *testing.T, c *Client, uns any) { res, ok := uns.(*result.Invoke) require.True(t, ok) bytes, err := hex.DecodeString("262bec084432") @@ -1146,7 +1146,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ "invokescript": { { name: "positive", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { script, err := base64.StdEncoding.DecodeString("AARuYW1lZyQFjl4bYAiEfNZicoVJCIqe6CGR") if err != nil { panic(err) @@ -1156,7 +1156,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ }}) }, serverResponse: `{"jsonrpc":"2.0","id":1,"result":{"script":"AARuYW1lZyQFjl4bYAiEfNZicoVJCIqe6CGR","state":"HALT","gasconsumed":"16100000","stack":[{"type":"ByteString","value":"TkVQNSBHQVM="}],"tx":null}}`, - result: func(c *Client) interface{} { + result: func(c *Client) any { bytes, err := hex.DecodeString("4e45503520474153") if err != nil { panic(err) @@ -1177,7 +1177,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ "invokecontractverify": { { name: "positive", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { contr, err := util.Uint160DecodeStringLE("af7c7328eee5a275a3bcaee2bf0cf662b5e739be") if err != nil { panic(err) @@ -1185,10 +1185,10 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ return c.InvokeContractVerify(contr, nil, []transaction.Signer{{Account: util.Uint160{1, 2, 3}}}, transaction.Witness{InvocationScript: []byte{1, 2, 3}}) }, serverResponse: `{"jsonrpc":"2.0","id":1,"result":{"script":"FCaufGyYYexBhGjB8P3Ep/KWPriRUcEJYmFsYW5jZU9mZ74557Vi9gy/4q68o3Wi5e4oc3yv","state":"HALT","gasconsumed":"31100000","stack":[{"type":"ByteString","value":"JivsCEQy"}],"tx":"AAgAAACAlpgAAAAAAAIEEwAAAAAAsAQAAAGqis+FnU/kArNOZz8hVoIXlqSI6wEAVwHoAwwUqorPhZ1P5AKzTmc/IVaCF5akiOsMFOeetm08E0pKd27oB9LluEbdpP2wE8AMCHRyYW5zZmVyDBTnnrZtPBNKSndu6AfS5bhG3aT9sEFifVtSOAFCDEDYNAh3TUvYsZrocFYdBvJ0Trdnj1jRuQzy9Q6YroP2Cwgk4v7q3vbeZBikz8Q7vB+RbDPsWUy+ZiqdkkeG4XoUKQwhArNiK/QBe9/jF8WK7V9MdT8ga324lgRvp9d0u8S/f43CC0GVRA14"}}`, - result: func(c *Client) interface{} { + result: func(c *Client) any { return &result.Invoke{} }, - check: func(t *testing.T, c *Client, uns interface{}) { + check: func(t *testing.T, c *Client, uns any) { res, ok := uns.(*result.Invoke) require.True(t, ok) bytes, err := hex.DecodeString("262bec084432") @@ -1208,7 +1208,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ }, { name: "bad witness number", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.InvokeContractVerify(util.Uint160{}, nil, []transaction.Signer{{}}, []transaction.Witness{{}, {}}...) }, fails: true, @@ -1217,11 +1217,11 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ "sendrawtransaction": { { name: "positive", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.SendRawTransaction(transaction.New([]byte{byte(opcode.PUSH1)}, 0)) }, serverResponse: `{"jsonrpc":"2.0","id":1,"result":{"hash":"0x72159b0cf1221110daad6e1df6ef4ff03012173b63c86910bd7134deb659c875"}}`, - result: func(c *Client) interface{} { + result: func(c *Client) any { h, err := util.Uint256DecodeStringLE("72159b0cf1221110daad6e1df6ef4ff03012173b63c86910bd7134deb659c875") if err != nil { panic(fmt.Errorf("can't decode `sendrawtransaction` result hash: %w", err)) @@ -1233,7 +1233,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ "submitblock": { { name: "positive", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.SubmitBlock(block.Block{ Header: block.Header{}, Transactions: nil, @@ -1241,7 +1241,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ }) }, serverResponse: `{"jsonrpc":"2.0","id":1,"result":{"hash":"0x1bdea8f80eb5bd97fade38d5e7fb93b02c9d3e01394e9f4324218132293f7ea6"}}`, - result: func(c *Client) interface{} { + result: func(c *Client) any { h, err := util.Uint256DecodeStringLE("1bdea8f80eb5bd97fade38d5e7fb93b02c9d3e01394e9f4324218132293f7ea6") if err != nil { panic(fmt.Errorf("can't decode `submitblock` result hash: %w", err)) @@ -1253,11 +1253,11 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ "validateaddress": { { name: "positive", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return nil, c.ValidateAddress("AQVh2pG732YvtNaxEGkQUei3YA4cvo7d2i") }, serverResponse: `{"jsonrpc":"2.0","id":1,"result":{"address":"AQVh2pG732YvtNaxEGkQUei3YA4cvo7d2i","isvalid":true}}`, - result: func(c *Client) interface{} { + result: func(c *Client) any { // no error expected return nil }, @@ -1267,14 +1267,14 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ type rpcClientErrorCase struct { name string - invoke func(c *Client) (interface{}, error) + invoke func(c *Client) (any, error) } var rpcClientErrorCases = map[string][]rpcClientErrorCase{ `{"jsonrpc":"2.0","id":1,"result":{"name":"name","bad":42}}`: { { name: "getnep11properties_unmarshalling_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetNEP11Properties(util.Uint160{}, []byte{}) }, }, @@ -1282,7 +1282,7 @@ var rpcClientErrorCases = map[string][]rpcClientErrorCase{ `{"jsonrpc":"2.0","id":1,"result":{"name":100500,"good":"c29tZXRoaW5n"}}`: { { name: "getnep11properties_unmarshalling_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetNEP11Properties(util.Uint160{}, []byte{}) }, }, @@ -1290,13 +1290,13 @@ var rpcClientErrorCases = map[string][]rpcClientErrorCase{ `{"jsonrpc":"2.0","id":1,"result":"not-a-hex-string"}`: { { name: "getblock_not_a_hex_response", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetBlockByIndex(1) }, }, { name: "getblockheader_not_a_hex_response", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { hash, err := util.Uint256DecodeStringLE("e93d17a52967f9e69314385482bf86f85260e811b46bf4d4b261a7f4135a623c") if err != nil { panic(err) @@ -1306,7 +1306,7 @@ var rpcClientErrorCases = map[string][]rpcClientErrorCase{ }, { name: "getrawtransaction_not_a_hex_response", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { hash, err := util.Uint256DecodeStringLE("e93d17a52967f9e69314385482bf86f85260e811b46bf4d4b261a7f4135a623c") if err != nil { panic(err) @@ -1316,7 +1316,7 @@ var rpcClientErrorCases = map[string][]rpcClientErrorCase{ }, { name: "getstoragebyhash_not_a_hex_response", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { hash, err := util.Uint160DecodeStringLE("03febccf81ac85e3d795bc5cbd4e84e907812aa3") if err != nil { panic(err) @@ -1330,7 +1330,7 @@ var rpcClientErrorCases = map[string][]rpcClientErrorCase{ }, { name: "getstoragebyid_not_a_hex_response", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { key, err := hex.DecodeString("5065746572") if err != nil { panic(err) @@ -1342,13 +1342,13 @@ var rpcClientErrorCases = map[string][]rpcClientErrorCase{ `{"jsonrpc":"2.0","id":1,"result":"01"}`: { { name: "getblock_decodebin_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetBlockByIndex(1) }, }, { name: "getheader_decodebin_err", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { hash, err := util.Uint256DecodeStringLE("e93d17a52967f9e69314385482bf86f85260e811b46bf4d4b261a7f4135a623c") if err != nil { panic(err) @@ -1358,7 +1358,7 @@ var rpcClientErrorCases = map[string][]rpcClientErrorCase{ }, { name: "getrawtransaction_decodebin_err", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { hash, err := util.Uint256DecodeStringLE("e93d17a52967f9e69314385482bf86f85260e811b46bf4d4b261a7f4135a623c") if err != nil { panic(err) @@ -1370,13 +1370,13 @@ var rpcClientErrorCases = map[string][]rpcClientErrorCase{ `{"jsonrpc":"2.0","id":1,"result":false}`: { { name: "sendrawtransaction_bad_server_answer", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.SendRawTransaction(transaction.New([]byte{byte(opcode.PUSH1)}, 0)) }, }, { name: "submitblock_bad_server_answer", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.SubmitBlock(block.Block{ Header: block.Header{}, Transactions: nil, @@ -1386,7 +1386,7 @@ var rpcClientErrorCases = map[string][]rpcClientErrorCase{ }, { name: "validateaddress_bad_server_answer", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return nil, c.ValidateAddress("AQVh2pG732YvtNaxEGkQUei3YA4cvo7d2i") }, }, @@ -1394,116 +1394,116 @@ var rpcClientErrorCases = map[string][]rpcClientErrorCase{ `{"id":1,"jsonrpc":"2.0","error":{"code":-32602,"message":"Invalid Params"}}`: { { name: "getapplicationlog_invalid_params_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetApplicationLog(util.Uint256{}, nil) }, }, { name: "getbestblockhash_invalid_params_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetBestBlockHash() }, }, { name: "getblock_byindex_invalid_params_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetBlockByIndex(1) }, }, { name: "getblock_byindex_verbose_invalid_params_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetBlockByIndexVerbose(1) }, }, { name: "getblock_byhash_invalid_params_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetBlockByHash(util.Uint256{}) }, }, { name: "getblock_byhash_verbose_invalid_params_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetBlockByHashVerbose(util.Uint256{}) }, }, { name: "getblockhash_invalid_params_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetBlockHash(0) }, }, { name: "getblockheader_invalid_params_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetBlockHeader(util.Uint256{}) }, }, { name: "getblockheader_verbose_invalid_params_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetBlockHeaderVerbose(util.Uint256{}) }, }, { name: "getblocksysfee_invalid_params_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetBlockSysFee(1) }, }, { name: "getconnectioncount_invalid_params_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetConnectionCount() }, }, { name: "getcontractstate_invalid_params_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetContractStateByHash(util.Uint160{}) }, }, { name: "getnep11balances_invalid_params_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetNEP11Balances(util.Uint160{}) }, }, { name: "getnep17balances_invalid_params_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetNEP17Balances(util.Uint160{}) }, }, { name: "getnep11properties_invalid_params_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetNEP11Properties(util.Uint160{}, []byte{}) }, }, { name: "getnep11transfers_invalid_params_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetNEP11Transfers(util.Uint160{}, nil, nil, nil, nil) }, }, { name: "getnep17transfers_invalid_params_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetNEP17Transfers(util.Uint160{}, nil, nil, nil, nil) }, }, { name: "getnep17transfers_invalid_params_error 2", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { var stop uint64 return c.GetNEP17Transfers(util.Uint160{}, nil, &stop, nil, nil) }, }, { name: "getnep17transfers_invalid_params_error 3", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { var start uint64 var limit int return c.GetNEP17Transfers(util.Uint160{}, &start, nil, &limit, nil) @@ -1511,7 +1511,7 @@ var rpcClientErrorCases = map[string][]rpcClientErrorCase{ }, { name: "getnep17transfers_invalid_params_error 4", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { var start, stop uint64 var page int return c.GetNEP17Transfers(util.Uint160{}, &start, &stop, nil, &page) @@ -1519,67 +1519,67 @@ var rpcClientErrorCases = map[string][]rpcClientErrorCase{ }, { name: "getrawtransaction_invalid_params_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetRawTransaction(util.Uint256{}) }, }, { name: "getrawtransaction_verbose_invalid_params_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetRawTransactionVerbose(util.Uint256{}) }, }, { name: "getstoragebyhash_invalid_params_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetStorageByHash(util.Uint160{}, []byte{}) }, }, { name: "getstoragebyid_invalid_params_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetStorageByID(-1, []byte{}) }, }, { name: "gettransactionheight_invalid_params_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetTransactionHeight(util.Uint256{}) }, }, { name: "getunclaimedgas_invalid_params_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetUnclaimedGas("") }, }, { name: "invokefunction_invalid_params_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.InvokeFunction(util.Uint160{}, "", []smartcontract.Parameter{}, nil) }, }, { name: "invokescript_invalid_params_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.InvokeScript([]byte{}, nil) }, }, { name: "sendrawtransaction_invalid_params_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.SendRawTransaction(&transaction.Transaction{}) }, }, { name: "submitblock_invalid_params_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.SubmitBlock(block.Block{}) }, }, { name: "validateaddress_invalid_params_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return nil, c.ValidateAddress("") }, }, @@ -1587,193 +1587,193 @@ var rpcClientErrorCases = map[string][]rpcClientErrorCase{ `{}`: { { name: "getapplicationlog_unmarshalling_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetApplicationLog(util.Uint256{}, nil) }, }, { name: "getbestblockhash_unmarshalling_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetBestBlockHash() }, }, { name: "getblock_byindex_unmarshalling_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetBlockByIndex(1) }, }, { name: "getblock_byindex_verbose_unmarshalling_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetBlockByIndexVerbose(1) }, }, { name: "getblock_byhash_unmarshalling_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetBlockByHash(util.Uint256{}) }, }, { name: "getblock_byhash_verbose_unmarshalling_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetBlockByHashVerbose(util.Uint256{}) }, }, { name: "getblockcount_unmarshalling_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetBlockCount() }, }, { name: "getblockhash_unmarshalling_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetBlockHash(1) }, }, { name: "getblockheader_unmarshalling_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetBlockHeader(util.Uint256{}) }, }, { name: "getblockheader_verbose_unmarshalling_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetBlockHeaderVerbose(util.Uint256{}) }, }, { name: "getblocksysfee_unmarshalling_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetBlockSysFee(1) }, }, { name: "getcommittee_unmarshalling_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetCommittee() }, }, { name: "getconnectioncount_unmarshalling_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetConnectionCount() }, }, { name: "getcontractstate_unmarshalling_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetContractStateByHash(util.Uint160{}) }, }, { name: "getnep11balances_unmarshalling_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetNEP11Balances(util.Uint160{}) }, }, { name: "getnep17balances_unmarshalling_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetNEP17Balances(util.Uint160{}) }, }, { name: "getnep11transfers_unmarshalling_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetNEP11Transfers(util.Uint160{}, nil, nil, nil, nil) }, }, { name: "getnep17transfers_unmarshalling_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetNEP17Transfers(util.Uint160{}, nil, nil, nil, nil) }, }, { name: "getpeers_unmarshalling_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetPeers() }, }, { name: "getrawmempool_unmarshalling_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetRawMemPool() }, }, { name: "getrawtransaction_unmarshalling_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetRawTransaction(util.Uint256{}) }, }, { name: "getrawtransaction_verbose_unmarshalling_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetRawTransactionVerbose(util.Uint256{}) }, }, { name: "getstoragebyhash_unmarshalling_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetStorageByHash(util.Uint160{}, []byte{}) }, }, { name: "getstoragebyid_unmarshalling_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetStorageByID(-1, []byte{}) }, }, { name: "gettransactionheight_unmarshalling_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetTransactionHeight(util.Uint256{}) }, }, { name: "getunclaimedgas_unmarshalling_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetUnclaimedGas("") }, }, { name: "getcandidates_unmarshalling_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetCandidates() }, }, { name: "getvalidators_unmarshalling_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.GetNextBlockValidators() }, }, { name: "invokefunction_unmarshalling_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.InvokeFunction(util.Uint160{}, "", []smartcontract.Parameter{}, nil) }, }, { name: "invokescript_unmarshalling_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.InvokeScript([]byte{}, nil) }, }, { name: "sendrawtransaction_unmarshalling_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.SendRawTransaction(transaction.New([]byte{byte(opcode.PUSH1)}, 0)) }, }, { name: "submitblock_unmarshalling_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return c.SubmitBlock(block.Block{ Header: block.Header{}, Transactions: nil, @@ -1783,7 +1783,7 @@ var rpcClientErrorCases = map[string][]rpcClientErrorCase{ }, { name: "validateaddress_unmarshalling_error", - invoke: func(c *Client) (interface{}, error) { + invoke: func(c *Client) (any, error) { return nil, c.ValidateAddress("") }, }, diff --git a/pkg/rpcclient/unwrap/unwrap_test.go b/pkg/rpcclient/unwrap/unwrap_test.go index b26876a58..9ec9f3cc0 100644 --- a/pkg/rpcclient/unwrap/unwrap_test.go +++ b/pkg/rpcclient/unwrap/unwrap_test.go @@ -15,66 +15,66 @@ import ( ) func TestStdErrors(t *testing.T) { - funcs := []func(r *result.Invoke, err error) (interface{}, error){ - func(r *result.Invoke, err error) (interface{}, error) { + funcs := []func(r *result.Invoke, err error) (any, error){ + func(r *result.Invoke, err error) (any, error) { return BigInt(r, err) }, - func(r *result.Invoke, err error) (interface{}, error) { + func(r *result.Invoke, err error) (any, error) { return Bool(r, err) }, - func(r *result.Invoke, err error) (interface{}, error) { + func(r *result.Invoke, err error) (any, error) { return Int64(r, err) }, - func(r *result.Invoke, err error) (interface{}, error) { + func(r *result.Invoke, err error) (any, error) { return LimitedInt64(r, err, 0, 1) }, - func(r *result.Invoke, err error) (interface{}, error) { + func(r *result.Invoke, err error) (any, error) { return Bytes(r, err) }, - func(r *result.Invoke, err error) (interface{}, error) { + func(r *result.Invoke, err error) (any, error) { return UTF8String(r, err) }, - func(r *result.Invoke, err error) (interface{}, error) { + func(r *result.Invoke, err error) (any, error) { return PrintableASCIIString(r, err) }, - func(r *result.Invoke, err error) (interface{}, error) { + func(r *result.Invoke, err error) (any, error) { return Uint160(r, err) }, - func(r *result.Invoke, err error) (interface{}, error) { + func(r *result.Invoke, err error) (any, error) { return Uint256(r, err) }, - func(r *result.Invoke, err error) (interface{}, error) { + func(r *result.Invoke, err error) (any, error) { return PublicKey(r, err) }, - func(r *result.Invoke, err error) (interface{}, error) { + func(r *result.Invoke, err error) (any, error) { _, _, err = SessionIterator(r, err) return nil, err }, - func(r *result.Invoke, err error) (interface{}, error) { + func(r *result.Invoke, err error) (any, error) { return Array(r, err) }, - func(r *result.Invoke, err error) (interface{}, error) { + func(r *result.Invoke, err error) (any, error) { return ArrayOfBools(r, err) }, - func(r *result.Invoke, err error) (interface{}, error) { + func(r *result.Invoke, err error) (any, error) { return ArrayOfBigInts(r, err) }, - func(r *result.Invoke, err error) (interface{}, error) { + func(r *result.Invoke, err error) (any, error) { return ArrayOfBytes(r, err) }, - func(r *result.Invoke, err error) (interface{}, error) { + func(r *result.Invoke, err error) (any, error) { return ArrayOfUTF8Strings(r, err) }, - func(r *result.Invoke, err error) (interface{}, error) { + func(r *result.Invoke, err error) (any, error) { return ArrayOfUint160(r, err) }, - func(r *result.Invoke, err error) (interface{}, error) { + func(r *result.Invoke, err error) (any, error) { return ArrayOfUint256(r, err) }, - func(r *result.Invoke, err error) (interface{}, error) { + func(r *result.Invoke, err error) (any, error) { return ArrayOfPublicKeys(r, err) }, - func(r *result.Invoke, err error) (interface{}, error) { + func(r *result.Invoke, err error) (any, error) { return Map(r, err) }, } diff --git a/pkg/rpcclient/wsclient.go b/pkg/rpcclient/wsclient.go index 2234260fc..c3f6172a1 100644 --- a/pkg/rpcclient/wsclient.go +++ b/pkg/rpcclient/wsclient.go @@ -79,7 +79,7 @@ type WSClient struct { // It must be accessed with subscriptionsLock taken. Its keys must be used to deliver // notifications, if channel is not in the receivers list and corresponding subscription // still exists, notification must not be sent. - receivers map[interface{}][]string + receivers map[any][]string respLock sync.RWMutex respChannels map[uint64]chan *neorpc.Response @@ -91,7 +91,7 @@ type notificationReceiver interface { // Comparator provides notification filtering functionality. rpcevent.Comparator // Receiver returns notification receiver channel. - Receiver() interface{} + Receiver() any // TrySend checks whether notification passes receiver filter and sends it // to the underlying channel if so. TrySend(ntf Notification) bool @@ -111,7 +111,7 @@ func (r *blockReceiver) EventID() neorpc.EventID { } // Filter implements neorpc.Comparator interface. -func (r *blockReceiver) Filter() interface{} { +func (r *blockReceiver) Filter() any { if r.filter == nil { return nil } @@ -119,7 +119,7 @@ func (r *blockReceiver) Filter() interface{} { } // Receiver implements notificationReceiver interface. -func (r *blockReceiver) Receiver() interface{} { +func (r *blockReceiver) Receiver() any { return r.ch } @@ -149,7 +149,7 @@ func (r *txReceiver) EventID() neorpc.EventID { } // Filter implements neorpc.Comparator interface. -func (r *txReceiver) Filter() interface{} { +func (r *txReceiver) Filter() any { if r.filter == nil { return nil } @@ -157,7 +157,7 @@ func (r *txReceiver) Filter() interface{} { } // Receiver implements notificationReceiver interface. -func (r *txReceiver) Receiver() interface{} { +func (r *txReceiver) Receiver() any { return r.ch } @@ -187,7 +187,7 @@ func (r *executionNotificationReceiver) EventID() neorpc.EventID { } // Filter implements neorpc.Comparator interface. -func (r *executionNotificationReceiver) Filter() interface{} { +func (r *executionNotificationReceiver) Filter() any { if r.filter == nil { return nil } @@ -195,7 +195,7 @@ func (r *executionNotificationReceiver) Filter() interface{} { } // Receiver implements notificationReceiver interface. -func (r *executionNotificationReceiver) Receiver() interface{} { +func (r *executionNotificationReceiver) Receiver() any { return r.ch } @@ -225,7 +225,7 @@ func (r *executionReceiver) EventID() neorpc.EventID { } // Filter implements neorpc.Comparator interface. -func (r *executionReceiver) Filter() interface{} { +func (r *executionReceiver) Filter() any { if r.filter == nil { return nil } @@ -233,7 +233,7 @@ func (r *executionReceiver) Filter() interface{} { } // Receiver implements notificationReceiver interface. -func (r *executionReceiver) Receiver() interface{} { +func (r *executionReceiver) Receiver() any { return r.ch } @@ -263,7 +263,7 @@ func (r *notaryRequestReceiver) EventID() neorpc.EventID { } // Filter implements neorpc.Comparator interface. -func (r *notaryRequestReceiver) Filter() interface{} { +func (r *notaryRequestReceiver) Filter() any { if r.filter == nil { return nil } @@ -271,7 +271,7 @@ func (r *notaryRequestReceiver) Filter() interface{} { } // Receiver implements notificationReceiver interface. -func (r *notaryRequestReceiver) Receiver() interface{} { +func (r *notaryRequestReceiver) Receiver() any { return r.ch } @@ -295,7 +295,7 @@ func (r *notaryRequestReceiver) Close() { // Deprecated: this receiver must be removed after outdated subscriptions API removal. type naiveReceiver struct { eventID neorpc.EventID - filter interface{} + filter any ch chan<- Notification } @@ -305,12 +305,12 @@ func (r *naiveReceiver) EventID() neorpc.EventID { } // Filter implements neorpc.Comparator interface. -func (r *naiveReceiver) Filter() interface{} { +func (r *naiveReceiver) Filter() any { return r.filter } // Receiver implements notificationReceiver interface. -func (r *naiveReceiver) Receiver() interface{} { +func (r *naiveReceiver) Receiver() any { return r.ch } @@ -335,7 +335,7 @@ func (r *naiveReceiver) Close() { // *transaction.Transaction or *subscriptions.NotaryRequestEvent based on Type. type Notification struct { Type neorpc.EventID - Value interface{} + Value any } // EventID implements Container interface and returns notification ID. @@ -345,7 +345,7 @@ func (n Notification) EventID() neorpc.EventID { // EventPayload implements Container interface and returns notification // object. -func (n Notification) EventPayload() interface{} { +func (n Notification) EventPayload() any { return n.Value } @@ -410,7 +410,7 @@ func NewWS(ctx context.Context, endpoint string, opts Options) (*WSClient, error respChannels: make(map[uint64]chan *neorpc.Response), requests: make(chan *neorpc.Request), subscriptions: make(map[string]notificationReceiver), - receivers: make(map[interface{}][]string), + receivers: make(map[any][]string), } err = initClient(ctx, &wsc.Client, endpoint, opts) @@ -644,7 +644,7 @@ func (c *WSClient) makeWsRequest(r *neorpc.Request) (*neorpc.Response, error) { } } -func (c *WSClient) performSubscription(params []interface{}, rcvr notificationReceiver) (string, error) { +func (c *WSClient) performSubscription(params []any, rcvr notificationReceiver) (string, error) { var resp string if err := c.performRequest("subscribe", params, &resp); err != nil { @@ -666,12 +666,12 @@ func (c *WSClient) performSubscription(params []interface{}, rcvr notificationRe // // Deprecated: please, use ReceiveBlocks. This method will be removed in future versions. func (c *WSClient) SubscribeForNewBlocks(primary *int) (string, error) { - var flt interface{} + var flt any if primary != nil { var f = neorpc.BlockFilter{Primary: primary} flt = *f.Copy() } - params := []interface{}{"block_added"} + params := []any{"block_added"} if flt != nil { params = append(params, flt) } @@ -690,7 +690,7 @@ func (c *WSClient) ReceiveBlocks(flt *neorpc.BlockFilter, rcvr chan<- *block.Blo if rcvr == nil { return "", ErrNilNotificationReceiver } - params := []interface{}{"block_added"} + params := []any{"block_added"} if flt != nil { flt = flt.Copy() params = append(params, *flt) @@ -708,12 +708,12 @@ func (c *WSClient) ReceiveBlocks(flt *neorpc.BlockFilter, rcvr chan<- *block.Blo // // Deprecated: please, use ReceiveTransactions. This method will be removed in future versions. func (c *WSClient) SubscribeForNewTransactions(sender *util.Uint160, signer *util.Uint160) (string, error) { - var flt interface{} + var flt any if sender != nil || signer != nil { var f = neorpc.TxFilter{Sender: sender, Signer: signer} flt = *f.Copy() } - params := []interface{}{"transaction_added"} + params := []any{"transaction_added"} if flt != nil { params = append(params, flt) } @@ -732,7 +732,7 @@ func (c *WSClient) ReceiveTransactions(flt *neorpc.TxFilter, rcvr chan<- *transa if rcvr == nil { return "", ErrNilNotificationReceiver } - params := []interface{}{"transaction_added"} + params := []any{"transaction_added"} if flt != nil { flt = flt.Copy() params = append(params, *flt) @@ -751,12 +751,12 @@ func (c *WSClient) ReceiveTransactions(flt *neorpc.TxFilter, rcvr chan<- *transa // // Deprecated: please, use ReceiveExecutionNotifications. This method will be removed in future versions. func (c *WSClient) SubscribeForExecutionNotifications(contract *util.Uint160, name *string) (string, error) { - var flt interface{} + var flt any if contract != nil || name != nil { var f = neorpc.NotificationFilter{Contract: contract, Name: name} flt = *f.Copy() } - params := []interface{}{"notification_from_execution"} + params := []any{"notification_from_execution"} if flt != nil { params = append(params, flt) } @@ -775,7 +775,7 @@ func (c *WSClient) ReceiveExecutionNotifications(flt *neorpc.NotificationFilter, if rcvr == nil { return "", ErrNilNotificationReceiver } - params := []interface{}{"notification_from_execution"} + params := []any{"notification_from_execution"} if flt != nil { flt = flt.Copy() params = append(params, *flt) @@ -794,7 +794,7 @@ func (c *WSClient) ReceiveExecutionNotifications(flt *neorpc.NotificationFilter, // // Deprecated: please, use ReceiveExecutions. This method will be removed in future versions. func (c *WSClient) SubscribeForTransactionExecutions(state *string) (string, error) { - var flt interface{} + var flt any if state != nil { if *state != "HALT" && *state != "FAULT" { return "", errors.New("bad state parameter") @@ -802,7 +802,7 @@ func (c *WSClient) SubscribeForTransactionExecutions(state *string) (string, err var f = neorpc.ExecutionFilter{State: state} flt = *f.Copy() } - params := []interface{}{"transaction_executed"} + params := []any{"transaction_executed"} if flt != nil { params = append(params, flt) } @@ -822,7 +822,7 @@ func (c *WSClient) ReceiveExecutions(flt *neorpc.ExecutionFilter, rcvr chan<- *s if rcvr == nil { return "", ErrNilNotificationReceiver } - params := []interface{}{"transaction_executed"} + params := []any{"transaction_executed"} if flt != nil { if flt.State != nil { if *flt.State != "HALT" && *flt.State != "FAULT" { @@ -846,12 +846,12 @@ func (c *WSClient) ReceiveExecutions(flt *neorpc.ExecutionFilter, rcvr chan<- *s // // Deprecated: please, use ReceiveNotaryRequests. This method will be removed in future versions. func (c *WSClient) SubscribeForNotaryRequests(sender *util.Uint160, mainSigner *util.Uint160) (string, error) { - var flt interface{} + var flt any if sender != nil || mainSigner != nil { var f = neorpc.TxFilter{Sender: sender, Signer: mainSigner} flt = *f.Copy() } - params := []interface{}{"notary_request_event"} + params := []any{"notary_request_event"} if flt != nil { params = append(params, flt) } @@ -872,7 +872,7 @@ func (c *WSClient) ReceiveNotaryRequests(flt *neorpc.TxFilter, rcvr chan<- *resu if rcvr == nil { return "", ErrNilNotificationReceiver } - params := []interface{}{"notary_request_event"} + params := []any{"notary_request_event"} if flt != nil { flt = flt.Copy() params = append(params, *flt) @@ -918,10 +918,10 @@ func (c *WSClient) UnsubscribeAll() error { err := c.performUnsubscription(id) if err != nil { errFmt := "failed to unsubscribe from feed %d: %v" - errArgs := []interface{}{err} + errArgs := []any{err} if resErr != nil { errFmt = "%w; " + errFmt - errArgs = append([]interface{}{resErr}, errArgs...) + errArgs = append([]any{resErr}, errArgs...) } resErr = fmt.Errorf(errFmt, errArgs...) } @@ -935,7 +935,7 @@ func (c *WSClient) UnsubscribeAll() error { // may still receive WS notifications. func (c *WSClient) performUnsubscription(id string) error { var resp bool - if err := c.performRequest("unsubscribe", []interface{}{id}, &resp); err != nil { + if err := c.performRequest("unsubscribe", []any{id}, &resp); err != nil { return err } if !resp { diff --git a/pkg/services/helpers/rpcbroadcaster/broadcaster.go b/pkg/services/helpers/rpcbroadcaster/broadcaster.go index 2738f3b47..33464f0fd 100644 --- a/pkg/services/helpers/rpcbroadcaster/broadcaster.go +++ b/pkg/services/helpers/rpcbroadcaster/broadcaster.go @@ -10,7 +10,7 @@ import ( type RPCBroadcaster struct { Clients map[string]*RPCClient Log *zap.Logger - Responses chan []interface{} + Responses chan []any close chan struct{} finished chan struct{} @@ -24,7 +24,7 @@ func NewRPCBroadcaster(log *zap.Logger, sendTimeout time.Duration) *RPCBroadcast Log: log, close: make(chan struct{}), finished: make(chan struct{}), - Responses: make(chan []interface{}), + Responses: make(chan []any), sendTimeout: sendTimeout, } } @@ -65,7 +65,7 @@ drain: } // SendParams sends a request using all clients if the broadcaster is active. -func (r *RPCBroadcaster) SendParams(params []interface{}) { +func (r *RPCBroadcaster) SendParams(params []any) { select { case <-r.close: case r.Responses <- params: diff --git a/pkg/services/helpers/rpcbroadcaster/client.go b/pkg/services/helpers/rpcbroadcaster/client.go index 43c4e97c2..841336d43 100644 --- a/pkg/services/helpers/rpcbroadcaster/client.go +++ b/pkg/services/helpers/rpcbroadcaster/client.go @@ -14,17 +14,17 @@ type RPCClient struct { addr string close chan struct{} finished chan struct{} - responses chan []interface{} + responses chan []any log *zap.Logger sendTimeout time.Duration method SendMethod } // SendMethod represents an rpc method for sending data to other nodes. -type SendMethod func(*rpcclient.Client, []interface{}) error +type SendMethod func(*rpcclient.Client, []any) error // NewRPCClient returns a new rpc client for the provided address and method. -func (r *RPCBroadcaster) NewRPCClient(addr string, method SendMethod, timeout time.Duration, ch chan []interface{}) *RPCClient { +func (r *RPCBroadcaster) NewRPCClient(addr string, method SendMethod, timeout time.Duration, ch chan []any) *RPCClient { return &RPCClient{ addr: addr, close: r.close, diff --git a/pkg/services/notary/core_test.go b/pkg/services/notary/core_test.go index c383c39be..657a2bc90 100644 --- a/pkg/services/notary/core_test.go +++ b/pkg/services/notary/core_test.go @@ -154,7 +154,7 @@ func TestNotary(t *testing.T) { mp1.StopSubscriptions() }) - notaryNodes := []interface{}{acc1.PublicKey().Bytes(), acc2.PrivateKey().PublicKey().Bytes()} + notaryNodes := []any{acc1.PublicKey().Bytes(), acc2.PrivateKey().PublicKey().Bytes()} designationSuperInvoker.Invoke(t, stackitem.Null{}, "designateAsRole", int64(noderoles.P2PNotary), notaryNodes) @@ -721,9 +721,9 @@ func TestNotary(t *testing.T) { requester1, _ := wallet.NewAccount() requester2, _ := wallet.NewAccount() amount := int64(100_0000_0000) - gasValidatorInvoker.Invoke(t, true, "transfer", e.Validator.ScriptHash(), bc.GetNotaryContractScriptHash(), amount, []interface{}{requester1.ScriptHash(), int64(bc.BlockHeight() + 50)}) + gasValidatorInvoker.Invoke(t, true, "transfer", e.Validator.ScriptHash(), bc.GetNotaryContractScriptHash(), amount, []any{requester1.ScriptHash(), int64(bc.BlockHeight() + 50)}) e.CheckGASBalance(t, notaryHash, big.NewInt(amount)) - gasValidatorInvoker.Invoke(t, true, "transfer", e.Validator.ScriptHash(), bc.GetNotaryContractScriptHash(), amount, []interface{}{requester2.ScriptHash(), int64(bc.BlockHeight() + 50)}) + gasValidatorInvoker.Invoke(t, true, "transfer", e.Validator.ScriptHash(), bc.GetNotaryContractScriptHash(), amount, []any{requester2.ScriptHash(), int64(bc.BlockHeight() + 50)}) e.CheckGASBalance(t, notaryHash, big.NewInt(2*amount)) // create request for 2 standard signatures => main tx should be completed after the second request is added to the pool diff --git a/pkg/services/oracle/broadcaster/oracle.go b/pkg/services/oracle/broadcaster/oracle.go index 0655580b6..b5e5cd2aa 100644 --- a/pkg/services/oracle/broadcaster/oracle.go +++ b/pkg/services/oracle/broadcaster/oracle.go @@ -34,7 +34,7 @@ func New(cfg config.OracleConfiguration, log *zap.Logger) *OracleBroadcaster { } for i := range cfg.Nodes { r.Clients[cfg.Nodes[i]] = r.NewRPCClient(cfg.Nodes[i], (*rpcclient.Client).SubmitRawOracleResponse, - cfg.ResponseTimeout, make(chan []interface{}, defaultChanCapacity)) + cfg.ResponseTimeout, make(chan []any, defaultChanCapacity)) } return r } @@ -44,7 +44,7 @@ func (r *OracleBroadcaster) SendResponse(priv *keys.PrivateKey, resp *transactio pub := priv.PublicKey() data := GetMessage(pub.Bytes(), resp.ID, txSig) msgSig := priv.Sign(data) - params := []interface{}{ + params := []any{ base64.StdEncoding.EncodeToString(pub.Bytes()), resp.ID, base64.StdEncoding.EncodeToString(txSig), diff --git a/pkg/services/oracle/filter.go b/pkg/services/oracle/filter.go index 5c13030a8..2c92f3d0d 100644 --- a/pkg/services/oracle/filter.go +++ b/pkg/services/oracle/filter.go @@ -19,7 +19,7 @@ func filter(value []byte, path string) ([]byte, error) { d := json.NewDecoder(buf) d.UseOrderedObject() - var v interface{} + var v any if err := d.Decode(&v); err != nil { return nil, err } diff --git a/pkg/services/oracle/jsonpath/jsonpath.go b/pkg/services/oracle/jsonpath/jsonpath.go index 18b1294ac..7ccf41bf7 100644 --- a/pkg/services/oracle/jsonpath/jsonpath.go +++ b/pkg/services/oracle/jsonpath/jsonpath.go @@ -40,9 +40,9 @@ const ( // Get returns substructures of value selected by path. // The result is always non-nil unless the path is invalid. -func Get(path string, value interface{}) ([]interface{}, bool) { +func Get(path string, value any) ([]any, bool) { if path == "" { - return []interface{}{value}, true + return []any{value}, true } p := pathParser{ @@ -55,7 +55,7 @@ func Get(path string, value interface{}) ([]interface{}, bool) { return nil, false } - objs := []interface{}{value} + objs := []any{value} for p.i < len(p.s) { var ok bool @@ -72,7 +72,7 @@ func Get(path string, value interface{}) ([]interface{}, bool) { } if objs == nil { - objs = []interface{}{} + objs = []any{} } return objs, true } @@ -173,7 +173,7 @@ func (p *pathParser) parseNumber() (string, int, bool) { // processDot handles `.` operator. // It either descends 1 level down or performs recursive descent. -func (p *pathParser) processDot(objs []interface{}) ([]interface{}, bool) { +func (p *pathParser) processDot(objs []any) ([]any, bool) { typ, value := p.nextToken() switch typ { case pathAsterisk: @@ -189,16 +189,16 @@ func (p *pathParser) processDot(objs []interface{}) ([]interface{}, bool) { // descend descends 1 level down. // It flattens arrays and returns map values for maps. -func (p *pathParser) descend(objs []interface{}) ([]interface{}, bool) { +func (p *pathParser) descend(objs []any) ([]any, bool) { if p.depth <= 0 { return nil, false } p.depth-- - var values []interface{} + var values []any for i := range objs { switch obj := objs[i].(type) { - case []interface{}: + case []any: if maxObjects < len(values)+len(obj) { return nil, false } @@ -217,13 +217,13 @@ func (p *pathParser) descend(objs []interface{}) ([]interface{}, bool) { } // descendRecursive performs recursive descent. -func (p *pathParser) descendRecursive(objs []interface{}) ([]interface{}, bool) { +func (p *pathParser) descendRecursive(objs []any) ([]any, bool) { typ, val := p.nextToken() if typ != pathIdentifier { return nil, false } - var values []interface{} + var values []any for len(objs) > 0 { newObjs, _ := p.descendByIdentAux(objs, false, val) @@ -238,11 +238,11 @@ func (p *pathParser) descendRecursive(objs []interface{}) ([]interface{}, bool) } // descendByIdent performs map's field access by name. -func (p *pathParser) descendByIdent(objs []interface{}, names ...string) ([]interface{}, bool) { +func (p *pathParser) descendByIdent(objs []any, names ...string) ([]any, bool) { return p.descendByIdentAux(objs, true, names...) } -func (p *pathParser) descendByIdentAux(objs []interface{}, checkDepth bool, names ...string) ([]interface{}, bool) { +func (p *pathParser) descendByIdentAux(objs []any, checkDepth bool, names ...string) ([]any, bool) { if checkDepth { if p.depth <= 0 { return nil, false @@ -250,7 +250,7 @@ func (p *pathParser) descendByIdentAux(objs []interface{}, checkDepth bool, name p.depth-- } - var values []interface{} + var values []any for i := range objs { obj, ok := objs[i].(json.OrderedObject) if !ok { @@ -273,15 +273,15 @@ func (p *pathParser) descendByIdentAux(objs []interface{}, checkDepth bool, name } // descendByIndex performs array access by index. -func (p *pathParser) descendByIndex(objs []interface{}, indices ...int) ([]interface{}, bool) { +func (p *pathParser) descendByIndex(objs []any, indices ...int) ([]any, bool) { if p.depth <= 0 { return nil, false } p.depth-- - var values []interface{} + var values []any for i := range objs { - obj, ok := objs[i].([]interface{}) + obj, ok := objs[i].([]any) if !ok { continue } @@ -304,7 +304,7 @@ func (p *pathParser) descendByIndex(objs []interface{}, indices ...int) ([]inter // processLeftBracket processes index expressions which can be either // array/map access, array sub-slice or union of indices. -func (p *pathParser) processLeftBracket(objs []interface{}) ([]interface{}, bool) { +func (p *pathParser) processLeftBracket(objs []any) ([]any, bool) { typ, value := p.nextToken() switch typ { case pathAsterisk: @@ -360,7 +360,7 @@ func (p *pathParser) processLeftBracket(objs []interface{}) ([]interface{}, bool // processUnion processes union of multiple indices. // firstTyp is assumed to be either pathNumber or pathString. -func (p *pathParser) processUnion(objs []interface{}, firstTyp pathTokenType, firstVal string) ([]interface{}, bool) { +func (p *pathParser) processUnion(objs []any, firstTyp pathTokenType, firstVal string) ([]any, bool) { items := []string{firstVal} for { typ, val := p.nextToken() @@ -403,7 +403,7 @@ func (p *pathParser) processUnion(objs []interface{}, firstTyp pathTokenType, fi } // processSlice processes a slice with the specified start index. -func (p *pathParser) processSlice(objs []interface{}, start int) ([]interface{}, bool) { +func (p *pathParser) processSlice(objs []any, start int) ([]any, bool) { typ, val := p.nextToken() switch typ { case pathNumber: @@ -426,15 +426,15 @@ func (p *pathParser) processSlice(objs []interface{}, start int) ([]interface{}, } // descendByRange is similar to descend but skips maps and returns sub-slices for arrays. -func (p *pathParser) descendByRange(objs []interface{}, start, end int) ([]interface{}, bool) { +func (p *pathParser) descendByRange(objs []any, start, end int) ([]any, bool) { if p.depth <= 0 { return nil, false } p.depth-- - var values []interface{} + var values []any for i := range objs { - arr, ok := objs[i].([]interface{}) + arr, ok := objs[i].([]any) if !ok { continue } diff --git a/pkg/services/oracle/jsonpath/jsonpath_test.go b/pkg/services/oracle/jsonpath/jsonpath_test.go index eaeacbe2d..e537fb1db 100644 --- a/pkg/services/oracle/jsonpath/jsonpath_test.go +++ b/pkg/services/oracle/jsonpath/jsonpath_test.go @@ -16,8 +16,8 @@ type pathTestCase struct { result string } -func unmarshalGet(t *testing.T, js string, path string) ([]interface{}, bool) { - var v interface{} +func unmarshalGet(t *testing.T, js string, path string) ([]any, bool) { + var v any buf := bytes.NewBuffer([]byte(js)) d := json.NewDecoder(buf) d.UseOrderedObject() diff --git a/pkg/services/oracle/oracle_test.go b/pkg/services/oracle/oracle_test.go index 9cc43bcee..acc0f6509 100644 --- a/pkg/services/oracle/oracle_test.go +++ b/pkg/services/oracle/oracle_test.go @@ -41,7 +41,7 @@ var pathToInternalContracts = filepath.Join("..", "..", "..", "internal", "contr func putOracleRequest(t *testing.T, oracleValidatorInvoker *neotest.ContractInvoker, url string, filter *string, cb string, userData []byte, gas int64) util.Uint256 { - var filtItem interface{} + var filtItem any if filter != nil { filtItem = *filter } @@ -153,7 +153,7 @@ func TestOracle(t *testing.T) { oracleNodes := keys.PublicKeys{acc1.PublicKey(), acc2.PrivateKey().PublicKey()} // Must be set in native contract for tx verification. designationSuperInvoker.Invoke(t, stackitem.Null{}, "designateAsRole", - int64(roles.Oracle), []interface{}{oracleNodes[0].Bytes(), oracleNodes[1].Bytes()}) + int64(roles.Oracle), []any{oracleNodes[0].Bytes(), oracleNodes[1].Bytes()}) orc1.UpdateOracleNodes(oracleNodes.Copy()) orc2.UpdateOracleNodes(oracleNodes.Copy()) @@ -357,7 +357,7 @@ func TestOracleFull(t *testing.T) { }) designationSuperInvoker.Invoke(t, stackitem.Null{}, "designateAsRole", - int64(roles.Oracle), []interface{}{acc.PublicKey().Bytes()}) + int64(roles.Oracle), []any{acc.PublicKey().Bytes()}) cs := contracts.GetOracleContractState(t, pathToInternalContracts, validator.ScriptHash(), 0) e.DeployContract(t, &neotest.Contract{ @@ -391,7 +391,7 @@ func TestNotYetRunningOracle(t *testing.T) { t.Cleanup(bc.Close) designationSuperInvoker.Invoke(t, stackitem.Null{}, "designateAsRole", - int64(roles.Oracle), []interface{}{acc.PublicKey().Bytes()}) + int64(roles.Oracle), []any{acc.PublicKey().Bytes()}) var req state.OracleRequest var reqs = make(map[uint64]*state.OracleRequest) diff --git a/pkg/services/rpcsrv/client_test.go b/pkg/services/rpcsrv/client_test.go index 86d8c7346..de0606f8d 100644 --- a/pkg/services/rpcsrv/client_test.go +++ b/pkg/services/rpcsrv/client_test.go @@ -2298,7 +2298,7 @@ func testSubClientWaitWithMissedEvent(t *testing.T, local bool) { overNotification := neorpc.Notification{ JSONRPC: neorpc.JSONRPCVersion, Event: neorpc.MissedEventID, - Payload: make([]interface{}, 0), + Payload: make([]any, 0), } overEvent, err := json.Marshal(overNotification) require.NoError(t, err) diff --git a/pkg/services/rpcsrv/error.go b/pkg/services/rpcsrv/error.go index 819b40b8a..89fb64538 100644 --- a/pkg/services/rpcsrv/error.go +++ b/pkg/services/rpcsrv/error.go @@ -17,7 +17,7 @@ type abstractResult interface { type abstract struct { neorpc.Header Error *neorpc.Error `json:"error,omitempty"` - Result interface{} `json:"result,omitempty"` + Result any `json:"result,omitempty"` } // RunForErrors implements abstractResult interface. diff --git a/pkg/services/rpcsrv/params/param.go b/pkg/services/rpcsrv/params/param.go index db392d58d..e0a56db3f 100644 --- a/pkg/services/rpcsrv/params/param.go +++ b/pkg/services/rpcsrv/params/param.go @@ -25,7 +25,7 @@ type ( // the client. Param struct { json.RawMessage - cache interface{} + cache any } // FuncParam represents a function argument parameter used in the @@ -193,7 +193,7 @@ func (p *Param) GetIntStrict() (int, error) { return 0, errNotAnInt } -func (p *Param) fillIntCache() (interface{}, error) { +func (p *Param) fillIntCache() (any, error) { if p.cache != nil { return p.cache, nil } diff --git a/pkg/services/rpcsrv/params/params.go b/pkg/services/rpcsrv/params/params.go index 23e5fe189..805625856 100644 --- a/pkg/services/rpcsrv/params/params.go +++ b/pkg/services/rpcsrv/params/params.go @@ -12,7 +12,7 @@ type ( // FromAny allows to create Params for a slice of abstract values (by // JSON-marshaling them). -func FromAny(arr []interface{}) (Params, error) { +func FromAny(arr []any) (Params, error) { var res Params for i := range arr { b, err := json.Marshal(arr[i]) diff --git a/pkg/services/rpcsrv/params/params_test.go b/pkg/services/rpcsrv/params/params_test.go index 8fd066951..415203182 100644 --- a/pkg/services/rpcsrv/params/params_test.go +++ b/pkg/services/rpcsrv/params/params_test.go @@ -10,7 +10,7 @@ import ( func TestParamsFromAny(t *testing.T) { str := "jajaja" - ps, err := FromAny([]interface{}{str, smartcontract.Parameter{Type: smartcontract.StringType, Value: str}}) + ps, err := FromAny([]any{str, smartcontract.Parameter{Type: smartcontract.StringType, Value: str}}) require.NoError(t, err) require.Equal(t, 2, len(ps)) @@ -26,6 +26,6 @@ func TestParamsFromAny(t *testing.T) { require.Equal(t, resStr, str) // Invalid item. - _, err = FromAny([]interface{}{smartcontract.Parameter{Type: smartcontract.IntegerType, Value: str}}) + _, err = FromAny([]any{smartcontract.Parameter{Type: smartcontract.IntegerType, Value: str}}) require.Error(t, err) } diff --git a/pkg/services/rpcsrv/server.go b/pkg/services/rpcsrv/server.go index 6531ccaf8..88fb38942 100644 --- a/pkg/services/rpcsrv/server.go +++ b/pkg/services/rpcsrv/server.go @@ -195,7 +195,7 @@ const ( defaultSessionPoolSize = 20 ) -var rpcHandlers = map[string]func(*Server, params.Params) (interface{}, *neorpc.Error){ +var rpcHandlers = map[string]func(*Server, params.Params) (any, *neorpc.Error){ "calculatenetworkfee": (*Server).calculateNetworkFee, "findstates": (*Server).findStates, "getapplicationlog": (*Server).getApplicationLog, @@ -244,7 +244,7 @@ var rpcHandlers = map[string]func(*Server, params.Params) (interface{}, *neorpc. "verifyproof": (*Server).verifyProof, } -var rpcWsHandlers = map[string]func(*Server, params.Params, *subscriber) (interface{}, *neorpc.Error){ +var rpcWsHandlers = map[string]func(*Server, params.Params, *subscriber) (any, *neorpc.Error){ "subscribe": (*Server).subscribe, "unsubscribe": (*Server).unsubscribe, } @@ -534,7 +534,7 @@ func (s *Server) handleRequest(req *params.Request, sub *subscriber) abstractRes // handleInternal is an experimental interface to handle client requests directly. func (s *Server) handleInternal(req *neorpc.Request, sub *subscriber) (*neorpc.Response, error) { var ( - res interface{} + res any rpcRes = &neorpc.Response{ HeaderAndError: neorpc.HeaderAndError{ Header: neorpc.Header{ @@ -577,7 +577,7 @@ func (s *Server) handleInternal(req *neorpc.Request, sub *subscriber) (*neorpc.R } func (s *Server) handleIn(req *params.In, sub *subscriber) abstract { - var res interface{} + var res any var resErr *neorpc.Error if req.JSONRPC != neorpc.JSONRPCVersion { return s.packResponse(req, nil, neorpc.NewInvalidParamsError(fmt.Sprintf("problem parsing JSON: invalid version, expected 2.0 got '%s'", req.JSONRPC))) @@ -721,19 +721,19 @@ func (s *Server) dropSubscriber(subscr *subscriber) { s.subsCounterLock.Unlock() } -func (s *Server) getBestBlockHash(_ params.Params) (interface{}, *neorpc.Error) { +func (s *Server) getBestBlockHash(_ params.Params) (any, *neorpc.Error) { return "0x" + s.chain.CurrentBlockHash().StringLE(), nil } -func (s *Server) getBlockCount(_ params.Params) (interface{}, *neorpc.Error) { +func (s *Server) getBlockCount(_ params.Params) (any, *neorpc.Error) { return s.chain.BlockHeight() + 1, nil } -func (s *Server) getBlockHeaderCount(_ params.Params) (interface{}, *neorpc.Error) { +func (s *Server) getBlockHeaderCount(_ params.Params) (any, *neorpc.Error) { return s.chain.HeaderHeight() + 1, nil } -func (s *Server) getConnectionCount(_ params.Params) (interface{}, *neorpc.Error) { +func (s *Server) getConnectionCount(_ params.Params) (any, *neorpc.Error) { return s.coreServer.PeerCount(), nil } @@ -769,7 +769,7 @@ func (s *Server) fillBlockMetadata(obj io.Serializable, h *block.Header) result. return res } -func (s *Server) getBlock(reqParams params.Params) (interface{}, *neorpc.Error) { +func (s *Server) getBlock(reqParams params.Params) (any, *neorpc.Error) { param := reqParams.Value(0) hash, respErr := s.blockHashFromParam(param) if respErr != nil { @@ -793,7 +793,7 @@ func (s *Server) getBlock(reqParams params.Params) (interface{}, *neorpc.Error) return writer.Bytes(), nil } -func (s *Server) getBlockHash(reqParams params.Params) (interface{}, *neorpc.Error) { +func (s *Server) getBlockHash(reqParams params.Params) (any, *neorpc.Error) { num, err := s.blockHeightFromParam(reqParams.Value(0)) if err != nil { return nil, neorpc.ErrInvalidParams @@ -802,7 +802,7 @@ func (s *Server) getBlockHash(reqParams params.Params) (interface{}, *neorpc.Err return s.chain.GetHeaderHash(num), nil } -func (s *Server) getVersion(_ params.Params) (interface{}, *neorpc.Error) { +func (s *Server) getVersion(_ params.Params) (any, *neorpc.Error) { port, err := s.coreServer.Port(nil) // any port will suite if err != nil { return nil, neorpc.NewInternalServerError(fmt.Sprintf("cannot fetch tcp port: %s", err)) @@ -832,7 +832,7 @@ func (s *Server) getVersion(_ params.Params) (interface{}, *neorpc.Error) { }, nil } -func (s *Server) getPeers(_ params.Params) (interface{}, *neorpc.Error) { +func (s *Server) getPeers(_ params.Params) (any, *neorpc.Error) { peers := result.NewGetPeers() peers.AddUnconnected(s.coreServer.UnconnectedPeers()) peers.AddConnected(s.coreServer.ConnectedPeers()) @@ -840,7 +840,7 @@ func (s *Server) getPeers(_ params.Params) (interface{}, *neorpc.Error) { return peers, nil } -func (s *Server) getRawMempool(reqParams params.Params) (interface{}, *neorpc.Error) { +func (s *Server) getRawMempool(reqParams params.Params) (any, *neorpc.Error) { verbose, _ := reqParams.Value(0).GetBoolean() mp := s.chain.GetMemPool() hashList := make([]util.Uint256, 0) @@ -857,7 +857,7 @@ func (s *Server) getRawMempool(reqParams params.Params) (interface{}, *neorpc.Er }, nil } -func (s *Server) validateAddress(reqParams params.Params) (interface{}, *neorpc.Error) { +func (s *Server) validateAddress(reqParams params.Params) (any, *neorpc.Error) { param, err := reqParams.Value(0).GetString() if err != nil { return nil, neorpc.ErrInvalidParams @@ -870,7 +870,7 @@ func (s *Server) validateAddress(reqParams params.Params) (interface{}, *neorpc. } // calculateNetworkFee calculates network fee for the transaction. -func (s *Server) calculateNetworkFee(reqParams params.Params) (interface{}, *neorpc.Error) { +func (s *Server) calculateNetworkFee(reqParams params.Params) (any, *neorpc.Error) { if len(reqParams) < 1 { return 0, neorpc.ErrInvalidParams } @@ -938,7 +938,7 @@ func (s *Server) calculateNetworkFee(reqParams params.Params) (interface{}, *neo } // getApplicationLog returns the contract log based on the specified txid or blockid. -func (s *Server) getApplicationLog(reqParams params.Params) (interface{}, *neorpc.Error) { +func (s *Server) getApplicationLog(reqParams params.Params) (any, *neorpc.Error) { hash, err := reqParams.Value(0).GetUint256() if err != nil { return nil, neorpc.ErrInvalidParams @@ -964,7 +964,7 @@ func (s *Server) getApplicationLog(reqParams params.Params) (interface{}, *neorp } func (s *Server) getNEP11Tokens(h util.Uint160, acc util.Uint160, bw *io.BufBinWriter) ([]stackitem.Item, string, int, error) { - items, finalize, err := s.invokeReadOnlyMulti(bw, h, []string{"tokensOf", "symbol", "decimals"}, [][]interface{}{{acc}, nil, nil}) + items, finalize, err := s.invokeReadOnlyMulti(bw, h, []string{"tokensOf", "symbol", "decimals"}, [][]any{{acc}, nil, nil}) if err != nil { return nil, "", 0, err } @@ -987,7 +987,7 @@ func (s *Server) getNEP11Tokens(h util.Uint160, acc util.Uint160, bw *io.BufBinW return vals, sym, int(dec.Int64()), nil } -func (s *Server) getNEP11Balances(ps params.Params) (interface{}, *neorpc.Error) { +func (s *Server) getNEP11Balances(ps params.Params) (any, *neorpc.Error) { u, err := ps.Value(0).GetUint160FromAddressOrHex() if err != nil { return nil, neorpc.ErrInvalidParams @@ -1076,7 +1076,7 @@ func (s *Server) invokeNEP11Properties(h util.Uint160, id []byte, bw *io.BufBinW return item.Value().([]stackitem.MapElement), nil } -func (s *Server) getNEP11Properties(ps params.Params) (interface{}, *neorpc.Error) { +func (s *Server) getNEP11Properties(ps params.Params) (any, *neorpc.Error) { asset, err := ps.Value(0).GetUint160FromAddressOrHex() if err != nil { return nil, neorpc.ErrInvalidParams @@ -1089,13 +1089,13 @@ func (s *Server) getNEP11Properties(ps params.Params) (interface{}, *neorpc.Erro if err != nil { return nil, neorpc.NewRPCError("Failed to get NEP-11 properties", err.Error()) } - res := make(map[string]interface{}) + res := make(map[string]any) for _, kv := range props { key, err := kv.Key.TryBytes() if err != nil { continue } - var val interface{} + var val any if result.KnownNEP11Properties[string(key)] || kv.Value.Type() != stackitem.AnyT { v, err := kv.Value.TryBytes() if err != nil { @@ -1112,7 +1112,7 @@ func (s *Server) getNEP11Properties(ps params.Params) (interface{}, *neorpc.Erro return res, nil } -func (s *Server) getNEP17Balances(ps params.Params) (interface{}, *neorpc.Error) { +func (s *Server) getNEP17Balances(ps params.Params) (any, *neorpc.Error) { u, err := ps.Value(0).GetUint160FromAddressOrHex() if err != nil { return nil, neorpc.ErrInvalidParams @@ -1160,15 +1160,15 @@ func (s *Server) getNEP17Balances(ps params.Params) (interface{}, *neorpc.Error) return bs, nil } -func (s *Server) invokeReadOnly(bw *io.BufBinWriter, h util.Uint160, method string, params ...interface{}) (stackitem.Item, func(), error) { - r, f, err := s.invokeReadOnlyMulti(bw, h, []string{method}, [][]interface{}{params}) +func (s *Server) invokeReadOnly(bw *io.BufBinWriter, h util.Uint160, method string, params ...any) (stackitem.Item, func(), error) { + r, f, err := s.invokeReadOnlyMulti(bw, h, []string{method}, [][]any{params}) if err != nil { return nil, nil, err } return r[0], f, nil } -func (s *Server) invokeReadOnlyMulti(bw *io.BufBinWriter, h util.Uint160, methods []string, params [][]interface{}) ([]stackitem.Item, func(), error) { +func (s *Server) invokeReadOnlyMulti(bw *io.BufBinWriter, h util.Uint160, methods []string, params [][]any) ([]stackitem.Item, func(), error) { if bw == nil { bw = io.NewBufBinWriter() } else { @@ -1205,7 +1205,7 @@ func (s *Server) invokeReadOnlyMulti(bw *io.BufBinWriter, h util.Uint160, method } func (s *Server) getNEP17TokenBalance(h util.Uint160, acc util.Uint160, bw *io.BufBinWriter) (*big.Int, string, int, error) { - items, finalize, err := s.invokeReadOnlyMulti(bw, h, []string{"balanceOf", "symbol", "decimals"}, [][]interface{}{{acc}, nil, nil}) + items, finalize, err := s.invokeReadOnlyMulti(bw, h, []string{"balanceOf", "symbol", "decimals"}, [][]any{{acc}, nil, nil}) if err != nil { return nil, "", 0, err } @@ -1291,15 +1291,15 @@ func getTimestampsAndLimit(ps params.Params, index int) (uint64, uint64, int, in return start, end, limit, page, nil } -func (s *Server) getNEP11Transfers(ps params.Params) (interface{}, *neorpc.Error) { +func (s *Server) getNEP11Transfers(ps params.Params) (any, *neorpc.Error) { return s.getTokenTransfers(ps, true) } -func (s *Server) getNEP17Transfers(ps params.Params) (interface{}, *neorpc.Error) { +func (s *Server) getNEP17Transfers(ps params.Params) (any, *neorpc.Error) { return s.getTokenTransfers(ps, false) } -func (s *Server) getTokenTransfers(ps params.Params, isNEP11 bool) (interface{}, *neorpc.Error) { +func (s *Server) getTokenTransfers(ps params.Params, isNEP11 bool) (any, *neorpc.Error) { u, err := ps.Value(0).GetUint160FromAddressOrHex() if err != nil { return nil, neorpc.ErrInvalidParams @@ -1312,8 +1312,8 @@ func (s *Server) getTokenTransfers(ps params.Params, isNEP11 bool) (interface{}, bs := &tokenTransfers{ Address: address.Uint160ToString(u), - Received: []interface{}{}, - Sent: []interface{}{}, + Received: []any{}, + Sent: []any{}, } cache := make(map[int32]util.Uint160) var resCount, frameCount int @@ -1478,7 +1478,7 @@ func makeStorageKey(id int32, key []byte) []byte { var errKeepOnlyLatestState = errors.New("'KeepOnlyLatestState' setting is enabled") -func (s *Server) getProof(ps params.Params) (interface{}, *neorpc.Error) { +func (s *Server) getProof(ps params.Params) (any, *neorpc.Error) { if s.chain.GetConfig().Ledger.KeepOnlyLatestState { return nil, neorpc.NewInvalidRequestError(fmt.Sprintf("'getproof' is not supported: %s", errKeepOnlyLatestState)) } @@ -1509,7 +1509,7 @@ func (s *Server) getProof(ps params.Params) (interface{}, *neorpc.Error) { }, nil } -func (s *Server) verifyProof(ps params.Params) (interface{}, *neorpc.Error) { +func (s *Server) verifyProof(ps params.Params) (any, *neorpc.Error) { if s.chain.GetConfig().Ledger.KeepOnlyLatestState { return nil, neorpc.NewInvalidRequestError(fmt.Sprintf("'verifyproof' is not supported: %s", errKeepOnlyLatestState)) } @@ -1533,7 +1533,7 @@ func (s *Server) verifyProof(ps params.Params) (interface{}, *neorpc.Error) { return vp, nil } -func (s *Server) getState(ps params.Params) (interface{}, *neorpc.Error) { +func (s *Server) getState(ps params.Params) (any, *neorpc.Error) { root, err := ps.Value(0).GetUint256() if err != nil { return nil, neorpc.WrapErrorWithData(neorpc.ErrInvalidParams, "invalid stateroot") @@ -1567,7 +1567,7 @@ func (s *Server) getState(ps params.Params) (interface{}, *neorpc.Error) { return res, nil } -func (s *Server) findStates(ps params.Params) (interface{}, *neorpc.Error) { +func (s *Server) findStates(ps params.Params) (any, *neorpc.Error) { root, err := ps.Value(0).GetUint256() if err != nil { return nil, neorpc.WrapErrorWithData(neorpc.ErrInvalidParams, "invalid stateroot") @@ -1675,7 +1675,7 @@ func (s *Server) getHistoricalContractState(root util.Uint256, csHash util.Uint1 return contract, nil } -func (s *Server) getStateHeight(_ params.Params) (interface{}, *neorpc.Error) { +func (s *Server) getStateHeight(_ params.Params) (any, *neorpc.Error) { var height = s.chain.BlockHeight() var stateHeight = s.chain.GetStateModule().CurrentValidatedHeight() if s.chain.GetConfig().StateRootInHeader { @@ -1687,7 +1687,7 @@ func (s *Server) getStateHeight(_ params.Params) (interface{}, *neorpc.Error) { }, nil } -func (s *Server) getStateRoot(ps params.Params) (interface{}, *neorpc.Error) { +func (s *Server) getStateRoot(ps params.Params) (any, *neorpc.Error) { p := ps.Value(0) if p == nil { return nil, neorpc.NewInvalidParamsError("missing stateroot identifier") @@ -1713,7 +1713,7 @@ func (s *Server) getStateRoot(ps params.Params) (interface{}, *neorpc.Error) { return rt, nil } -func (s *Server) getStorage(ps params.Params) (interface{}, *neorpc.Error) { +func (s *Server) getStorage(ps params.Params) (any, *neorpc.Error) { id, rErr := s.contractIDFromParam(ps.Value(0)) if rErr == neorpc.ErrUnknown { return nil, nil @@ -1735,7 +1735,7 @@ func (s *Server) getStorage(ps params.Params) (interface{}, *neorpc.Error) { return []byte(item), nil } -func (s *Server) getrawtransaction(reqParams params.Params) (interface{}, *neorpc.Error) { +func (s *Server) getrawtransaction(reqParams params.Params) (any, *neorpc.Error) { txHash, err := reqParams.Value(0).GetUint256() if err != nil { return nil, neorpc.ErrInvalidParams @@ -1774,7 +1774,7 @@ func (s *Server) getrawtransaction(reqParams params.Params) (interface{}, *neorp return tx.Bytes(), nil } -func (s *Server) getTransactionHeight(ps params.Params) (interface{}, *neorpc.Error) { +func (s *Server) getTransactionHeight(ps params.Params) (any, *neorpc.Error) { h, err := ps.Value(0).GetUint256() if err != nil { return nil, neorpc.ErrInvalidParams @@ -1790,7 +1790,7 @@ func (s *Server) getTransactionHeight(ps params.Params) (interface{}, *neorpc.Er // getContractState returns contract state (contract information, according to the contract script hash, // contract id or native contract name). -func (s *Server) getContractState(reqParams params.Params) (interface{}, *neorpc.Error) { +func (s *Server) getContractState(reqParams params.Params) (any, *neorpc.Error) { scriptHash, err := s.contractScriptHashFromParam(reqParams.Value(0)) if err != nil { return nil, err @@ -1802,12 +1802,12 @@ func (s *Server) getContractState(reqParams params.Params) (interface{}, *neorpc return cs, nil } -func (s *Server) getNativeContracts(_ params.Params) (interface{}, *neorpc.Error) { +func (s *Server) getNativeContracts(_ params.Params) (any, *neorpc.Error) { return s.chain.GetNatives(), nil } // getBlockSysFee returns the system fees of the block, based on the specified index. -func (s *Server) getBlockSysFee(reqParams params.Params) (interface{}, *neorpc.Error) { +func (s *Server) getBlockSysFee(reqParams params.Params) (any, *neorpc.Error) { num, err := s.blockHeightFromParam(reqParams.Value(0)) if err != nil { return 0, neorpc.NewRPCError("Invalid height", "invalid block identifier") @@ -1828,7 +1828,7 @@ func (s *Server) getBlockSysFee(reqParams params.Params) (interface{}, *neorpc.E } // getBlockHeader returns the corresponding block header information according to the specified script hash. -func (s *Server) getBlockHeader(reqParams params.Params) (interface{}, *neorpc.Error) { +func (s *Server) getBlockHeader(reqParams params.Params) (any, *neorpc.Error) { param := reqParams.Value(0) hash, respErr := s.blockHashFromParam(param) if respErr != nil { @@ -1858,7 +1858,7 @@ func (s *Server) getBlockHeader(reqParams params.Params) (interface{}, *neorpc.E } // getUnclaimedGas returns unclaimed GAS amount of the specified address. -func (s *Server) getUnclaimedGas(ps params.Params) (interface{}, *neorpc.Error) { +func (s *Server) getUnclaimedGas(ps params.Params) (any, *neorpc.Error) { u, err := ps.Value(0).GetUint160FromAddressOrHex() if err != nil { return nil, neorpc.ErrInvalidParams @@ -1881,7 +1881,7 @@ func (s *Server) getUnclaimedGas(ps params.Params) (interface{}, *neorpc.Error) } // getCandidates returns the current list of candidates with their active/inactive voting status. -func (s *Server) getCandidates(_ params.Params) (interface{}, *neorpc.Error) { +func (s *Server) getCandidates(_ params.Params) (any, *neorpc.Error) { var validators keys.PublicKeys validators, err := s.chain.GetNextBlockValidators() @@ -1904,7 +1904,7 @@ func (s *Server) getCandidates(_ params.Params) (interface{}, *neorpc.Error) { } // getNextBlockValidators returns validators for the next block with voting status. -func (s *Server) getNextBlockValidators(_ params.Params) (interface{}, *neorpc.Error) { +func (s *Server) getNextBlockValidators(_ params.Params) (any, *neorpc.Error) { var validators keys.PublicKeys validators, err := s.chain.GetNextBlockValidators() @@ -1929,7 +1929,7 @@ func (s *Server) getNextBlockValidators(_ params.Params) (interface{}, *neorpc.E } // getCommittee returns the current list of NEO committee members. -func (s *Server) getCommittee(_ params.Params) (interface{}, *neorpc.Error) { +func (s *Server) getCommittee(_ params.Params) (any, *neorpc.Error) { keys, err := s.chain.GetCommittee() if err != nil { return nil, neorpc.NewInternalServerError(fmt.Sprintf("can't get committee members: %s", err)) @@ -1938,7 +1938,7 @@ func (s *Server) getCommittee(_ params.Params) (interface{}, *neorpc.Error) { } // invokeFunction implements the `invokeFunction` RPC call. -func (s *Server) invokeFunction(reqParams params.Params) (interface{}, *neorpc.Error) { +func (s *Server) invokeFunction(reqParams params.Params) (any, *neorpc.Error) { tx, verbose, respErr := s.getInvokeFunctionParams(reqParams) if respErr != nil { return nil, respErr @@ -1947,7 +1947,7 @@ func (s *Server) invokeFunction(reqParams params.Params) (interface{}, *neorpc.E } // invokeFunctionHistoric implements the `invokeFunctionHistoric` RPC call. -func (s *Server) invokeFunctionHistoric(reqParams params.Params) (interface{}, *neorpc.Error) { +func (s *Server) invokeFunctionHistoric(reqParams params.Params) (any, *neorpc.Error) { nextH, respErr := s.getHistoricParams(reqParams) if respErr != nil { return nil, respErr @@ -2005,7 +2005,7 @@ func (s *Server) getInvokeFunctionParams(reqParams params.Params) (*transaction. } // invokescript implements the `invokescript` RPC call. -func (s *Server) invokescript(reqParams params.Params) (interface{}, *neorpc.Error) { +func (s *Server) invokescript(reqParams params.Params) (any, *neorpc.Error) { tx, verbose, respErr := s.getInvokeScriptParams(reqParams) if respErr != nil { return nil, respErr @@ -2014,7 +2014,7 @@ func (s *Server) invokescript(reqParams params.Params) (interface{}, *neorpc.Err } // invokescripthistoric implements the `invokescripthistoric` RPC call. -func (s *Server) invokescripthistoric(reqParams params.Params) (interface{}, *neorpc.Error) { +func (s *Server) invokescripthistoric(reqParams params.Params) (any, *neorpc.Error) { nextH, respErr := s.getHistoricParams(reqParams) if respErr != nil { return nil, respErr @@ -2059,7 +2059,7 @@ func (s *Server) getInvokeScriptParams(reqParams params.Params) (*transaction.Tr } // invokeContractVerify implements the `invokecontractverify` RPC call. -func (s *Server) invokeContractVerify(reqParams params.Params) (interface{}, *neorpc.Error) { +func (s *Server) invokeContractVerify(reqParams params.Params) (any, *neorpc.Error) { scriptHash, tx, invocationScript, respErr := s.getInvokeContractVerifyParams(reqParams) if respErr != nil { return nil, respErr @@ -2068,7 +2068,7 @@ func (s *Server) invokeContractVerify(reqParams params.Params) (interface{}, *ne } // invokeContractVerifyHistoric implements the `invokecontractverifyhistoric` RPC call. -func (s *Server) invokeContractVerifyHistoric(reqParams params.Params) (interface{}, *neorpc.Error) { +func (s *Server) invokeContractVerifyHistoric(reqParams params.Params) (any, *neorpc.Error) { nextH, respErr := s.getHistoricParams(reqParams) if respErr != nil { return nil, respErr @@ -2312,7 +2312,7 @@ func (s *Server) registerOrDumpIterator(item stackitem.Item) (stackitem.Item, uu return stackitem.NewInterop(resIterator), iterID } -func (s *Server) traverseIterator(reqParams params.Params) (interface{}, *neorpc.Error) { +func (s *Server) traverseIterator(reqParams params.Params) (any, *neorpc.Error) { if !s.config.SessionEnabled { return nil, neorpc.NewInvalidRequestError("sessions are disabled") } @@ -2369,7 +2369,7 @@ func (s *Server) traverseIterator(reqParams params.Params) (interface{}, *neorpc return result, nil } -func (s *Server) terminateSession(reqParams params.Params) (interface{}, *neorpc.Error) { +func (s *Server) terminateSession(reqParams params.Params) (any, *neorpc.Error) { if !s.config.SessionEnabled { return nil, neorpc.NewInvalidRequestError("sessions are disabled") } @@ -2396,7 +2396,7 @@ func (s *Server) terminateSession(reqParams params.Params) (interface{}, *neorpc } // submitBlock broadcasts a raw block over the Neo network. -func (s *Server) submitBlock(reqParams params.Params) (interface{}, *neorpc.Error) { +func (s *Server) submitBlock(reqParams params.Params) (any, *neorpc.Error) { blockBytes, err := reqParams.Value(0).GetBytesBase64() if err != nil { return nil, neorpc.NewInvalidParamsError(fmt.Sprintf("missing parameter or not a base64: %s", err)) @@ -2422,7 +2422,7 @@ func (s *Server) submitBlock(reqParams params.Params) (interface{}, *neorpc.Erro } // submitNotaryRequest broadcasts P2PNotaryRequest over the Neo network. -func (s *Server) submitNotaryRequest(ps params.Params) (interface{}, *neorpc.Error) { +func (s *Server) submitNotaryRequest(ps params.Params) (any, *neorpc.Error) { if !s.chain.P2PSigExtensionsEnabled() { return nil, neorpc.NewRPCError("P2PSignatureExtensions are disabled", "") } @@ -2439,7 +2439,7 @@ func (s *Server) submitNotaryRequest(ps params.Params) (interface{}, *neorpc.Err } // getRelayResult returns successful relay result or an error. -func getRelayResult(err error, hash util.Uint256) (interface{}, *neorpc.Error) { +func getRelayResult(err error, hash util.Uint256) (any, *neorpc.Error) { switch { case err == nil: return result.RelayResult{ @@ -2456,7 +2456,7 @@ func getRelayResult(err error, hash util.Uint256) (interface{}, *neorpc.Error) { } } -func (s *Server) submitOracleResponse(ps params.Params) (interface{}, *neorpc.Error) { +func (s *Server) submitOracleResponse(ps params.Params) (any, *neorpc.Error) { oracle := s.oracle.Load().(*OracleHandler) if oracle == nil || *oracle == nil { return nil, neorpc.NewRPCError("Oracle is not enabled", "") @@ -2489,7 +2489,7 @@ func (s *Server) submitOracleResponse(ps params.Params) (interface{}, *neorpc.Er return json.RawMessage([]byte("{}")), nil } -func (s *Server) sendrawtransaction(reqParams params.Params) (interface{}, *neorpc.Error) { +func (s *Server) sendrawtransaction(reqParams params.Params) (any, *neorpc.Error) { if len(reqParams) < 1 { return nil, neorpc.NewInvalidParamsError("not enough parameters") } @@ -2505,7 +2505,7 @@ func (s *Server) sendrawtransaction(reqParams params.Params) (interface{}, *neor } // subscribe handles subscription requests from websocket clients. -func (s *Server) subscribe(reqParams params.Params, sub *subscriber) (interface{}, *neorpc.Error) { +func (s *Server) subscribe(reqParams params.Params, sub *subscriber) (any, *neorpc.Error) { streamName, err := reqParams.Value(0).GetString() if err != nil { return nil, neorpc.ErrInvalidParams @@ -2518,7 +2518,7 @@ func (s *Server) subscribe(reqParams params.Params, sub *subscriber) (interface{ return nil, neorpc.WrapErrorWithData(neorpc.ErrInvalidParams, "P2PSigExtensions are disabled") } // Optional filter. - var filter interface{} + var filter any if p := reqParams.Value(1); p != nil { param := *p jd := json.NewDecoder(bytes.NewReader(param.RawMessage)) @@ -2611,7 +2611,7 @@ func (s *Server) subscribeToChannel(event neorpc.EventID) { } // unsubscribe handles unsubscription requests from websocket clients. -func (s *Server) unsubscribe(reqParams params.Params, sub *subscriber) (interface{}, *neorpc.Error) { +func (s *Server) unsubscribe(reqParams params.Params, sub *subscriber) (any, *neorpc.Error) { id, err := reqParams.Value(0).GetInt() if err != nil || id < 0 { return nil, neorpc.ErrInvalidParams @@ -2669,7 +2669,7 @@ func (s *Server) handleSubEvents() { var overflowEvent = neorpc.Notification{ JSONRPC: neorpc.JSONRPCVersion, Event: neorpc.MissedEventID, - Payload: make([]interface{}, 0), + Payload: make([]any, 0), } b, err := json.Marshal(overflowEvent) if err != nil { @@ -2685,7 +2685,7 @@ chloop: for { var resp = neorpc.Notification{ JSONRPC: neorpc.JSONRPCVersion, - Payload: make([]interface{}, 1), + Payload: make([]any, 1), } var msg *websocket.PreparedMessage select { @@ -2798,7 +2798,7 @@ func (s *Server) blockHeightFromParam(param *params.Param) (uint32, *neorpc.Erro return uint32(num), nil } -func (s *Server) packResponse(r *params.In, result interface{}, respErr *neorpc.Error) abstract { +func (s *Server) packResponse(r *params.In, result any, respErr *neorpc.Error) abstract { resp := abstract{ Header: neorpc.Header{ JSONRPC: r.JSONRPC, @@ -2882,7 +2882,7 @@ func (s *Server) writeHTTPServerResponse(r *params.Request, w http.ResponseWrite // validateAddress verifies that the address is a correct Neo address // see https://docs.neo.org/en-us/node/cli/2.9.4/api/validateaddress.html -func validateAddress(addr interface{}) bool { +func validateAddress(addr any) bool { if addr, ok := addr.(string); ok { _, err := address.StringToUint160(addr) return err == nil diff --git a/pkg/services/rpcsrv/server_test.go b/pkg/services/rpcsrv/server_test.go index 08d636d07..c5be0f3e0 100644 --- a/pkg/services/rpcsrv/server_test.go +++ b/pkg/services/rpcsrv/server_test.go @@ -62,8 +62,8 @@ type rpcTestCase struct { name string params string fail bool - result func(e *executor) interface{} - check func(t *testing.T, e *executor, result interface{}) + result func(e *executor) any + check func(t *testing.T, e *executor, result any) } const genesisBlockHash = "0f8fb4e17d2ab9f3097af75ca7fd16064160fb8043db94909e00dd4e257b9dc4" @@ -97,8 +97,8 @@ var rpcTestCases = map[string][]rpcTestCase{ { name: "positive", params: `["` + deploymentTxHash + `"]`, - result: func(e *executor) interface{} { return &result.ApplicationLog{} }, - check: func(t *testing.T, e *executor, acc interface{}) { + result: func(e *executor) any { return &result.ApplicationLog{} }, + check: func(t *testing.T, e *executor, acc any) { res, ok := acc.(*result.ApplicationLog) require.True(t, ok) expectedTxHash, err := util.Uint256DecodeStringLE(deploymentTxHash) @@ -112,8 +112,8 @@ var rpcTestCases = map[string][]rpcTestCase{ { name: "positive, genesis block", params: `["` + genesisBlockHash + `"]`, - result: func(e *executor) interface{} { return &result.ApplicationLog{} }, - check: func(t *testing.T, e *executor, acc interface{}) { + result: func(e *executor) any { return &result.ApplicationLog{} }, + check: func(t *testing.T, e *executor, acc any) { res, ok := acc.(*result.ApplicationLog) require.True(t, ok) assert.Equal(t, genesisBlockHash, res.Container.StringLE()) @@ -126,8 +126,8 @@ var rpcTestCases = map[string][]rpcTestCase{ { name: "positive, genesis block, postPersist", params: `["` + genesisBlockHash + `", "PostPersist"]`, - result: func(e *executor) interface{} { return &result.ApplicationLog{} }, - check: func(t *testing.T, e *executor, acc interface{}) { + result: func(e *executor) any { return &result.ApplicationLog{} }, + check: func(t *testing.T, e *executor, acc any) { res, ok := acc.(*result.ApplicationLog) require.True(t, ok) assert.Equal(t, genesisBlockHash, res.Container.StringLE()) @@ -139,8 +139,8 @@ var rpcTestCases = map[string][]rpcTestCase{ { name: "positive, genesis block, onPersist", params: `["` + genesisBlockHash + `", "OnPersist"]`, - result: func(e *executor) interface{} { return &result.ApplicationLog{} }, - check: func(t *testing.T, e *executor, acc interface{}) { + result: func(e *executor) any { return &result.ApplicationLog{} }, + check: func(t *testing.T, e *executor, acc any) { res, ok := acc.(*result.ApplicationLog) require.True(t, ok) assert.Equal(t, genesisBlockHash, res.Container.StringLE()) @@ -174,8 +174,8 @@ var rpcTestCases = map[string][]rpcTestCase{ { name: "positive, by hash", params: fmt.Sprintf(`["%s"]`, testContractHash), - result: func(e *executor) interface{} { return &state.Contract{} }, - check: func(t *testing.T, e *executor, cs interface{}) { + result: func(e *executor) any { return &state.Contract{} }, + check: func(t *testing.T, e *executor, cs any) { res, ok := cs.(*state.Contract) require.True(t, ok) assert.Equal(t, testContractHash, res.Hash.StringLE()) @@ -184,8 +184,8 @@ var rpcTestCases = map[string][]rpcTestCase{ { name: "positive, by id", params: `[1]`, - result: func(e *executor) interface{} { return &state.Contract{} }, - check: func(t *testing.T, e *executor, cs interface{}) { + result: func(e *executor) any { return &state.Contract{} }, + check: func(t *testing.T, e *executor, cs any) { res, ok := cs.(*state.Contract) require.True(t, ok) assert.Equal(t, int32(1), res.ID) @@ -194,8 +194,8 @@ var rpcTestCases = map[string][]rpcTestCase{ { name: "positive, native by id", params: `[-3]`, - result: func(e *executor) interface{} { return &state.Contract{} }, - check: func(t *testing.T, e *executor, cs interface{}) { + result: func(e *executor) any { return &state.Contract{} }, + check: func(t *testing.T, e *executor, cs any) { res, ok := cs.(*state.Contract) require.True(t, ok) assert.Equal(t, int32(-3), res.ID) @@ -204,8 +204,8 @@ var rpcTestCases = map[string][]rpcTestCase{ { name: "positive, native by name", params: `["PolicyContract"]`, - result: func(e *executor) interface{} { return &state.Contract{} }, - check: func(t *testing.T, e *executor, cs interface{}) { + result: func(e *executor) any { return &state.Contract{} }, + check: func(t *testing.T, e *executor, cs any) { res, ok := cs.(*state.Contract) require.True(t, ok) assert.Equal(t, int32(-7), res.ID) @@ -251,13 +251,13 @@ var rpcTestCases = map[string][]rpcTestCase{ { name: "positive", params: `["` + testchain.PrivateKeyByID(0).GetScriptHash().StringLE() + `"]`, - result: func(e *executor) interface{} { return &result.NEP11Balances{} }, + result: func(e *executor) any { return &result.NEP11Balances{} }, check: checkNep11Balances, }, { name: "positive_address", params: `["` + address.Uint160ToString(testchain.PrivateKeyByID(0).GetScriptHash()) + `"]`, - result: func(e *executor) interface{} { return &result.NEP11Balances{} }, + result: func(e *executor) any { return &result.NEP11Balances{} }, check: checkNep11Balances, }, }, @@ -285,8 +285,8 @@ var rpcTestCases = map[string][]rpcTestCase{ { name: "positive", params: `["` + nnsContractHash + `", "6e656f2e636f6d"]`, - result: func(e *executor) interface{} { - return &map[string]interface{}{ + result: func(e *executor) any { + return &map[string]any{ "name": "neo.com", "expiration": "lhbLRl0B", "admin": nil, @@ -318,7 +318,7 @@ var rpcTestCases = map[string][]rpcTestCase{ { name: "positive", params: `["` + testchain.PrivateKeyByID(0).Address() + `", 0]`, - result: func(e *executor) interface{} { return &result.NEP11Transfers{} }, + result: func(e *executor) any { return &result.NEP11Transfers{} }, check: checkNep11Transfers, }, }, @@ -336,13 +336,13 @@ var rpcTestCases = map[string][]rpcTestCase{ { name: "positive", params: `["` + testchain.PrivateKeyByID(0).GetScriptHash().StringLE() + `"]`, - result: func(e *executor) interface{} { return &result.NEP17Balances{} }, + result: func(e *executor) any { return &result.NEP17Balances{} }, check: checkNep17Balances, }, { name: "positive_address", params: `["` + address.Uint160ToString(testchain.PrivateKeyByID(0).GetScriptHash()) + `"]`, - result: func(e *executor) interface{} { return &result.NEP17Balances{} }, + result: func(e *executor) any { return &result.NEP17Balances{} }, check: checkNep17Balances, }, }, @@ -395,13 +395,13 @@ var rpcTestCases = map[string][]rpcTestCase{ { name: "positive", params: `["` + testchain.PrivateKeyByID(0).Address() + `", 0]`, - result: func(e *executor) interface{} { return &result.NEP17Transfers{} }, + result: func(e *executor) any { return &result.NEP17Transfers{} }, check: checkNep17Transfers, }, { name: "positive_hash", params: `["` + testchain.PrivateKeyByID(0).GetScriptHash().StringLE() + `", 0]`, - result: func(e *executor) interface{} { return &result.NEP17Transfers{} }, + result: func(e *executor) any { return &result.NEP17Transfers{} }, check: checkNep17Transfers, }, }, @@ -495,8 +495,8 @@ var rpcTestCases = map[string][]rpcTestCase{ { name: "positive", params: `[]`, - result: func(_ *executor) interface{} { return new(result.StateHeight) }, - check: func(t *testing.T, e *executor, res interface{}) { + result: func(_ *executor) any { return new(result.StateHeight) }, + check: func(t *testing.T, e *executor, res any) { sh, ok := res.(*result.StateHeight) require.True(t, ok) @@ -521,7 +521,7 @@ var rpcTestCases = map[string][]rpcTestCase{ { name: "positive", params: fmt.Sprintf(`["%s", "dGVzdGtleQ=="]`, testContractHash), - result: func(e *executor) interface{} { + result: func(e *executor) any { v := base64.StdEncoding.EncodeToString([]byte("newtestvalue")) return &v }, @@ -529,7 +529,7 @@ var rpcTestCases = map[string][]rpcTestCase{ { name: "missing key", params: fmt.Sprintf(`["%s", "dGU="]`, testContractHash), - result: func(e *executor) interface{} { + result: func(e *executor) any { v := "" return &v }, @@ -558,7 +558,7 @@ var rpcTestCases = map[string][]rpcTestCase{ "getbestblockhash": { { params: "[]", - result: func(e *executor) interface{} { + result: func(e *executor) any { v := "0x" + e.chain.CurrentBlockHash().StringLE() return &v }, @@ -568,8 +568,8 @@ var rpcTestCases = map[string][]rpcTestCase{ { name: "positive", params: "[3, 1]", - result: func(_ *executor) interface{} { return &result.Block{} }, - check: func(t *testing.T, e *executor, blockRes interface{}) { + result: func(_ *executor) any { return &result.Block{} }, + check: func(t *testing.T, e *executor, blockRes any) { res, ok := blockRes.(*result.Block) require.True(t, ok) @@ -614,7 +614,7 @@ var rpcTestCases = map[string][]rpcTestCase{ "getblockcount": { { params: "[]", - result: func(e *executor) interface{} { + result: func(e *executor) any { v := int(e.chain.BlockHeight() + 1) return &v }, @@ -623,7 +623,7 @@ var rpcTestCases = map[string][]rpcTestCase{ "getblockhash": { { params: "[1]", - result: func(e *executor) interface{} { + result: func(e *executor) any { // We don't have `t` here for proper handling, but // error here would lead to panic down below. block, _ := e.chain.GetBlock(e.chain.GetHeaderHash(1)) @@ -667,7 +667,7 @@ var rpcTestCases = map[string][]rpcTestCase{ "getblockheadercount": { { params: "[]", - result: func(e *executor) interface{} { + result: func(e *executor) any { v := int(e.chain.HeaderHeight() + 1) return &v }, @@ -677,7 +677,7 @@ var rpcTestCases = map[string][]rpcTestCase{ { name: "positive", params: "[1]", - result: func(e *executor) interface{} { + result: func(e *executor) any { block, _ := e.chain.GetBlock(e.chain.GetHeaderHash(1)) var expectedBlockSysFee int64 @@ -706,7 +706,7 @@ var rpcTestCases = map[string][]rpcTestCase{ "getcommittee": { { params: "[]", - result: func(e *executor) interface{} { + result: func(e *executor) any { expected, _ := e.chain.GetCommittee() sort.Sort(expected) return &expected @@ -716,7 +716,7 @@ var rpcTestCases = map[string][]rpcTestCase{ "getconnectioncount": { { params: "[]", - result: func(*executor) interface{} { + result: func(*executor) any { v := 0 return &v }, @@ -725,10 +725,10 @@ var rpcTestCases = map[string][]rpcTestCase{ "getnativecontracts": { { params: "[]", - result: func(e *executor) interface{} { + result: func(e *executor) any { return new([]state.NativeContract) }, - check: func(t *testing.T, e *executor, res interface{}) { + check: func(t *testing.T, e *executor, res any) { lst := res.(*[]state.NativeContract) for i := range *lst { cs := e.chain.GetContractState((*lst)[i].Hash) @@ -742,7 +742,7 @@ var rpcTestCases = map[string][]rpcTestCase{ "getpeers": { { params: "[]", - result: func(*executor) interface{} { + result: func(*executor) any { return &result.GetPeers{ Unconnected: []result.Peer{}, Connected: []result.Peer{}, @@ -772,11 +772,11 @@ var rpcTestCases = map[string][]rpcTestCase{ { name: "positive", params: `["` + deploymentTxHash + `"]`, - result: func(e *executor) interface{} { + result: func(e *executor) any { h := 0 return &h }, - check: func(t *testing.T, e *executor, resp interface{}) { + check: func(t *testing.T, e *executor, resp any) { h, ok := resp.(*int) require.True(t, ok) assert.Equal(t, 2, *h) @@ -812,10 +812,10 @@ var rpcTestCases = map[string][]rpcTestCase{ { name: "positive", params: `["` + testchain.MultisigAddress() + `"]`, - result: func(*executor) interface{} { + result: func(*executor) any { return &result.UnclaimedGas{} }, - check: func(t *testing.T, e *executor, resp interface{}) { + check: func(t *testing.T, e *executor, resp any) { actual, ok := resp.(*result.UnclaimedGas) require.True(t, ok) expected := result.UnclaimedGas{ @@ -829,7 +829,7 @@ var rpcTestCases = map[string][]rpcTestCase{ "getcandidates": { { params: "[]", - result: func(*executor) interface{} { + result: func(*executor) any { return &[]result.Candidate{} }, }, @@ -837,11 +837,11 @@ var rpcTestCases = map[string][]rpcTestCase{ "getnextblockvalidators": { { params: "[]", - result: func(*executor) interface{} { + result: func(*executor) any { return &[]result.Validator{} }, /* preview3 doesn't return any validators until there is a vote - check: func(t *testing.T, e *executor, validators interface{}) { + check: func(t *testing.T, e *executor, validators any) { var expected []result.Validator sBValidators := e.chain.GetStandByValidators() for _, sbValidator := range sBValidators { @@ -863,8 +863,8 @@ var rpcTestCases = map[string][]rpcTestCase{ "getversion": { { params: "[]", - result: func(*executor) interface{} { return &result.Version{} }, - check: func(t *testing.T, e *executor, ver interface{}) { + result: func(*executor) any { return &result.Version{} }, + check: func(t *testing.T, e *executor, ver any) { resp, ok := ver.(*result.Version) require.True(t, ok) require.Equal(t, "/NEO-GO:0.98.6-test/", resp.UserAgent) @@ -891,8 +891,8 @@ var rpcTestCases = map[string][]rpcTestCase{ { name: "positive", params: `["50befd26fdf6e4d957c11e078b24ebce6291456f", "test", []]`, - result: func(e *executor) interface{} { return &result.Invoke{} }, - check: func(t *testing.T, e *executor, inv interface{}) { + result: func(e *executor) any { return &result.Invoke{} }, + check: func(t *testing.T, e *executor, inv any) { res, ok := inv.(*result.Invoke) require.True(t, ok) assert.NotNil(t, res.Script) @@ -903,7 +903,7 @@ var rpcTestCases = map[string][]rpcTestCase{ { name: "positive, with notifications", params: `["` + nnsContractHash + `", "transfer", [{"type":"Hash160", "value":"0x0bcd2978634d961c24f5aea0802297ff128724d6"},{"type":"String", "value":"neo.com"},{"type":"Any", "value":null}],["0xb248508f4ef7088e10c48f14d04be3272ca29eee"]]`, - result: func(e *executor) interface{} { + result: func(e *executor) any { script := append([]byte{0x0b, 0x0c, 0x07, 0x6e, 0x65, 0x6f, 0x2e, 0x63, 0x6f, 0x6d, 0x0c, 0x14, 0xd6, 0x24, 0x87, 0x12, 0xff, 0x97, 0x22, 0x80, 0xa0, 0xae, 0xf5, 0x24, 0x1c, 0x96, 0x4d, 0x63, 0x78, 0x29, 0xcd, 0xb, 0x13, 0xc0, 0x1f, 0xc, 0x8, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x66, 0x65, 0x72, 0xc, 0x14}, nnsHash.BytesBE()...) script = append(script, 0x41, 0x62, 0x7d, 0x5b, 0x52) return &result.Invoke{ @@ -927,8 +927,8 @@ var rpcTestCases = map[string][]rpcTestCase{ { name: "positive, with storage changes", params: `["0xef4073a0f2b305a38ec4050e4d3d28bc40ea63f5", "transfer", [{"type":"Hash160", "value":"0xb248508f4ef7088e10c48f14d04be3272ca29eee"},{"type":"Hash160", "value":"0x0bcd2978634d961c24f5aea0802297ff128724d6"},{"type":"Integer", "value":1},{"type":"Any", "value":null}],["0xb248508f4ef7088e10c48f14d04be3272ca29eee"],true]`, - result: func(e *executor) interface{} { return &result.Invoke{} }, - check: func(t *testing.T, e *executor, inv interface{}) { + result: func(e *executor) any { return &result.Invoke{} }, + check: func(t *testing.T, e *executor, inv any) { res, ok := inv.(*result.Invoke) require.True(t, ok) assert.NotNil(t, res.Script) @@ -959,7 +959,7 @@ var rpcTestCases = map[string][]rpcTestCase{ { name: "positive, verbose", params: `["` + nnsContractHash + `", "resolve", [{"type":"String", "value":"neo.com"},{"type":"Integer","value":1}], [], true]`, - result: func(e *executor) interface{} { + result: func(e *executor) any { script := append([]byte{0x11, 0xc, 0x7, 0x6e, 0x65, 0x6f, 0x2e, 0x63, 0x6f, 0x6d, 0x12, 0xc0, 0x1f, 0xc, 0x7, 0x72, 0x65, 0x73, 0x6f, 0x6c, 0x76, 0x65, 0xc, 0x14}, nnsHash.BytesBE()...) script = append(script, 0x41, 0x62, 0x7d, 0x5b, 0x52) stdHash, _ := e.chain.GetNativeContractScriptHash(nativenames.StdLib) @@ -1026,8 +1026,8 @@ var rpcTestCases = map[string][]rpcTestCase{ { name: "positive, by index", params: `[20, "50befd26fdf6e4d957c11e078b24ebce6291456f", "test", []]`, - result: func(e *executor) interface{} { return &result.Invoke{} }, - check: func(t *testing.T, e *executor, inv interface{}) { + result: func(e *executor) any { return &result.Invoke{} }, + check: func(t *testing.T, e *executor, inv any) { res, ok := inv.(*result.Invoke) require.True(t, ok) assert.NotNil(t, res.Script) @@ -1038,8 +1038,8 @@ var rpcTestCases = map[string][]rpcTestCase{ { name: "positive, by stateroot", params: `["` + block20StateRootLE + `", "50befd26fdf6e4d957c11e078b24ebce6291456f", "test", []]`, - result: func(e *executor) interface{} { return &result.Invoke{} }, - check: func(t *testing.T, e *executor, inv interface{}) { + result: func(e *executor) any { return &result.Invoke{} }, + check: func(t *testing.T, e *executor, inv any) { res, ok := inv.(*result.Invoke) require.True(t, ok) assert.NotNil(t, res.Script) @@ -1050,7 +1050,7 @@ var rpcTestCases = map[string][]rpcTestCase{ { name: "positive, with notifications", params: `[20, "` + nnsContractHash + `", "transfer", [{"type":"Hash160", "value":"0x0bcd2978634d961c24f5aea0802297ff128724d6"},{"type":"String", "value":"neo.com"},{"type":"Any", "value":null}],["0xb248508f4ef7088e10c48f14d04be3272ca29eee"]]`, - result: func(e *executor) interface{} { + result: func(e *executor) any { script := append([]byte{0x0b, 0x0c, 0x07, 0x6e, 0x65, 0x6f, 0x2e, 0x63, 0x6f, 0x6d, 0x0c, 0x14, 0xd6, 0x24, 0x87, 0x12, 0xff, 0x97, 0x22, 0x80, 0xa0, 0xae, 0xf5, 0x24, 0x1c, 0x96, 0x4d, 0x63, 0x78, 0x29, 0xcd, 0xb, 0x13, 0xc0, 0x1f, 0xc, 0x8, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x66, 0x65, 0x72, 0xc, 0x14}, nnsHash.BytesBE()...) script = append(script, 0x41, 0x62, 0x7d, 0x5b, 0x52) return &result.Invoke{ @@ -1074,7 +1074,7 @@ var rpcTestCases = map[string][]rpcTestCase{ { name: "positive, verbose", params: `[20, "` + nnsContractHash + `", "resolve", [{"type":"String", "value":"neo.com"},{"type":"Integer","value":1}], [], true]`, - result: func(e *executor) interface{} { + result: func(e *executor) any { script := append([]byte{0x11, 0xc, 0x7, 0x6e, 0x65, 0x6f, 0x2e, 0x63, 0x6f, 0x6d, 0x12, 0xc0, 0x1f, 0xc, 0x7, 0x72, 0x65, 0x73, 0x6f, 0x6c, 0x76, 0x65, 0xc, 0x14}, nnsHash.BytesBE()...) script = append(script, 0x41, 0x62, 0x7d, 0x5b, 0x52) stdHash, _ := e.chain.GetNativeContractScriptHash(nativenames.StdLib) @@ -1156,8 +1156,8 @@ var rpcTestCases = map[string][]rpcTestCase{ { name: "positive", params: `["UcVrDUhlbGxvLCB3b3JsZCFoD05lby5SdW50aW1lLkxvZ2FsdWY="]`, - result: func(e *executor) interface{} { return &result.Invoke{} }, - check: func(t *testing.T, e *executor, inv interface{}) { + result: func(e *executor) any { return &result.Invoke{} }, + check: func(t *testing.T, e *executor, inv any) { res, ok := inv.(*result.Invoke) require.True(t, ok) assert.NotEqual(t, "", res.Script) @@ -1168,7 +1168,7 @@ var rpcTestCases = map[string][]rpcTestCase{ { name: "positive,verbose", params: `["UcVrDUhlbGxvLCB3b3JsZCFoD05lby5SdW50aW1lLkxvZ2FsdWY=",[],true]`, - result: func(e *executor) interface{} { + result: func(e *executor) any { script := []byte{0x51, 0xc5, 0x6b, 0xd, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x2c, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x21, 0x68, 0xf, 0x4e, 0x65, 0x6f, 0x2e, 0x52, 0x75, 0x6e, 0x74, 0x69, 0x6d, 0x65, 0x2e, 0x4c, 0x6f, 0x67, 0x61, 0x6c, 0x75, 0x66} return &result.Invoke{ State: "FAULT", @@ -1190,8 +1190,8 @@ var rpcTestCases = map[string][]rpcTestCase{ name: "positive, good witness", // script is base64-encoded `invokescript_contract.avm` representation, hashes are hex-encoded LE bytes of hashes used in the contract with `0x` prefix params: fmt.Sprintf(`["%s",["0x0000000009070e030d0f0e020d0c06050e030c01","0x090c060e00010205040307030102000902030f0d"]]`, invokescriptContractAVM), - result: func(e *executor) interface{} { return &result.Invoke{} }, - check: func(t *testing.T, e *executor, inv interface{}) { + result: func(e *executor) any { return &result.Invoke{} }, + check: func(t *testing.T, e *executor, inv any) { res, ok := inv.(*result.Invoke) require.True(t, ok) assert.Equal(t, "HALT", res.State) @@ -1202,8 +1202,8 @@ var rpcTestCases = map[string][]rpcTestCase{ { name: "positive, bad witness of second hash", params: fmt.Sprintf(`["%s",["0x0000000009070e030d0f0e020d0c06050e030c01"]]`, invokescriptContractAVM), - result: func(e *executor) interface{} { return &result.Invoke{} }, - check: func(t *testing.T, e *executor, inv interface{}) { + result: func(e *executor) any { return &result.Invoke{} }, + check: func(t *testing.T, e *executor, inv any) { res, ok := inv.(*result.Invoke) require.True(t, ok) assert.Equal(t, "HALT", res.State) @@ -1214,8 +1214,8 @@ var rpcTestCases = map[string][]rpcTestCase{ { name: "positive, no good hashes", params: fmt.Sprintf(`["%s"]`, invokescriptContractAVM), - result: func(e *executor) interface{} { return &result.Invoke{} }, - check: func(t *testing.T, e *executor, inv interface{}) { + result: func(e *executor) any { return &result.Invoke{} }, + check: func(t *testing.T, e *executor, inv any) { res, ok := inv.(*result.Invoke) require.True(t, ok) assert.Equal(t, "HALT", res.State) @@ -1226,8 +1226,8 @@ var rpcTestCases = map[string][]rpcTestCase{ { name: "positive, bad hashes witness", params: fmt.Sprintf(`["%s",["0x0000000009070e030d0f0e020d0c06050e030c02"]]`, invokescriptContractAVM), - result: func(e *executor) interface{} { return &result.Invoke{} }, - check: func(t *testing.T, e *executor, inv interface{}) { + result: func(e *executor) any { return &result.Invoke{} }, + check: func(t *testing.T, e *executor, inv any) { res, ok := inv.(*result.Invoke) require.True(t, ok) assert.Equal(t, "HALT", res.State) @@ -1255,8 +1255,8 @@ var rpcTestCases = map[string][]rpcTestCase{ { name: "positive, by index", params: `[20,"UcVrDUhlbGxvLCB3b3JsZCFoD05lby5SdW50aW1lLkxvZ2FsdWY="]`, - result: func(e *executor) interface{} { return &result.Invoke{} }, - check: func(t *testing.T, e *executor, inv interface{}) { + result: func(e *executor) any { return &result.Invoke{} }, + check: func(t *testing.T, e *executor, inv any) { res, ok := inv.(*result.Invoke) require.True(t, ok) assert.NotEqual(t, "", res.Script) @@ -1267,8 +1267,8 @@ var rpcTestCases = map[string][]rpcTestCase{ { name: "positive, by stateroot", params: `["` + block20StateRootLE + `","UcVrDUhlbGxvLCB3b3JsZCFoD05lby5SdW50aW1lLkxvZ2FsdWY="]`, - result: func(e *executor) interface{} { return &result.Invoke{} }, - check: func(t *testing.T, e *executor, inv interface{}) { + result: func(e *executor) any { return &result.Invoke{} }, + check: func(t *testing.T, e *executor, inv any) { res, ok := inv.(*result.Invoke) require.True(t, ok) assert.NotEqual(t, "", res.Script) @@ -1279,7 +1279,7 @@ var rpcTestCases = map[string][]rpcTestCase{ { name: "positive,verbose", params: `[20, "UcVrDUhlbGxvLCB3b3JsZCFoD05lby5SdW50aW1lLkxvZ2FsdWY=",[],true]`, - result: func(e *executor) interface{} { + result: func(e *executor) any { script := []byte{0x51, 0xc5, 0x6b, 0xd, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x2c, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x21, 0x68, 0xf, 0x4e, 0x65, 0x6f, 0x2e, 0x52, 0x75, 0x6e, 0x74, 0x69, 0x6d, 0x65, 0x2e, 0x4c, 0x6f, 0x67, 0x61, 0x6c, 0x75, 0x66} return &result.Invoke{ State: "FAULT", @@ -1301,8 +1301,8 @@ var rpcTestCases = map[string][]rpcTestCase{ name: "positive, good witness", // script is base64-encoded `invokescript_contract.avm` representation, hashes are hex-encoded LE bytes of hashes used in the contract with `0x` prefix params: fmt.Sprintf(`[20,"%s",["0x0000000009070e030d0f0e020d0c06050e030c01","0x090c060e00010205040307030102000902030f0d"]]`, invokescriptContractAVM), - result: func(e *executor) interface{} { return &result.Invoke{} }, - check: func(t *testing.T, e *executor, inv interface{}) { + result: func(e *executor) any { return &result.Invoke{} }, + check: func(t *testing.T, e *executor, inv any) { res, ok := inv.(*result.Invoke) require.True(t, ok) assert.Equal(t, "HALT", res.State) @@ -1313,8 +1313,8 @@ var rpcTestCases = map[string][]rpcTestCase{ { name: "positive, bad witness of second hash", params: fmt.Sprintf(`[20,"%s",["0x0000000009070e030d0f0e020d0c06050e030c01"]]`, invokescriptContractAVM), - result: func(e *executor) interface{} { return &result.Invoke{} }, - check: func(t *testing.T, e *executor, inv interface{}) { + result: func(e *executor) any { return &result.Invoke{} }, + check: func(t *testing.T, e *executor, inv any) { res, ok := inv.(*result.Invoke) require.True(t, ok) assert.Equal(t, "HALT", res.State) @@ -1325,8 +1325,8 @@ var rpcTestCases = map[string][]rpcTestCase{ { name: "positive, no good hashes", params: fmt.Sprintf(`[20,"%s"]`, invokescriptContractAVM), - result: func(e *executor) interface{} { return &result.Invoke{} }, - check: func(t *testing.T, e *executor, inv interface{}) { + result: func(e *executor) any { return &result.Invoke{} }, + check: func(t *testing.T, e *executor, inv any) { res, ok := inv.(*result.Invoke) require.True(t, ok) assert.Equal(t, "HALT", res.State) @@ -1337,8 +1337,8 @@ var rpcTestCases = map[string][]rpcTestCase{ { name: "positive, bad hashes witness", params: fmt.Sprintf(`[20,"%s",["0x0000000009070e030d0f0e020d0c06050e030c02"]]`, invokescriptContractAVM), - result: func(e *executor) interface{} { return &result.Invoke{} }, - check: func(t *testing.T, e *executor, inv interface{}) { + result: func(e *executor) any { return &result.Invoke{} }, + check: func(t *testing.T, e *executor, inv any) { res, ok := inv.(*result.Invoke) require.True(t, ok) assert.Equal(t, "HALT", res.State) @@ -1381,8 +1381,8 @@ var rpcTestCases = map[string][]rpcTestCase{ { name: "positive", params: fmt.Sprintf(`["%s", [], [{"account":"%s"}]]`, verifyContractHash, testchain.PrivateKeyByID(0).PublicKey().GetScriptHash().StringLE()), - result: func(e *executor) interface{} { return &result.Invoke{} }, - check: func(t *testing.T, e *executor, inv interface{}) { + result: func(e *executor) any { return &result.Invoke{} }, + check: func(t *testing.T, e *executor, inv any) { res, ok := inv.(*result.Invoke) require.True(t, ok) assert.Nil(t, res.Script) // empty witness invocation script (pushes args of `verify` on stack, but this `verify` don't have args) @@ -1394,8 +1394,8 @@ var rpcTestCases = map[string][]rpcTestCase{ { name: "positive, no signers", params: fmt.Sprintf(`["%s", []]`, verifyContractHash), - result: func(e *executor) interface{} { return &result.Invoke{} }, - check: func(t *testing.T, e *executor, inv interface{}) { + result: func(e *executor) any { return &result.Invoke{} }, + check: func(t *testing.T, e *executor, inv any) { res, ok := inv.(*result.Invoke) require.True(t, ok) assert.Nil(t, res.Script) @@ -1407,8 +1407,8 @@ var rpcTestCases = map[string][]rpcTestCase{ { name: "positive, no arguments", params: fmt.Sprintf(`["%s"]`, verifyContractHash), - result: func(e *executor) interface{} { return &result.Invoke{} }, - check: func(t *testing.T, e *executor, inv interface{}) { + result: func(e *executor) any { return &result.Invoke{} }, + check: func(t *testing.T, e *executor, inv any) { res, ok := inv.(*result.Invoke) require.True(t, ok) assert.Nil(t, res.Script) @@ -1420,8 +1420,8 @@ var rpcTestCases = map[string][]rpcTestCase{ { name: "positive, with signers and scripts", params: fmt.Sprintf(`["%s", [], [{"account":"%s", "invocation":"MQo=", "verification": ""}]]`, verifyContractHash, testchain.PrivateKeyByID(0).PublicKey().GetScriptHash().StringLE()), - result: func(e *executor) interface{} { return &result.Invoke{} }, - check: func(t *testing.T, e *executor, inv interface{}) { + result: func(e *executor) any { return &result.Invoke{} }, + check: func(t *testing.T, e *executor, inv any) { res, ok := inv.(*result.Invoke) require.True(t, ok) assert.Nil(t, res.Script) @@ -1433,8 +1433,8 @@ var rpcTestCases = map[string][]rpcTestCase{ { name: "positive, with arguments, result=true", params: fmt.Sprintf(`["%s", [{"type": "String", "value": "good_string"}, {"type": "Integer", "value": "4"}, {"type":"Boolean", "value": false}]]`, verifyWithArgsContractHash), - result: func(e *executor) interface{} { return &result.Invoke{} }, - check: func(t *testing.T, e *executor, inv interface{}) { + result: func(e *executor) any { return &result.Invoke{} }, + check: func(t *testing.T, e *executor, inv any) { res, ok := inv.(*result.Invoke) require.True(t, ok) expectedInvScript := io.NewBufBinWriter() @@ -1451,8 +1451,8 @@ var rpcTestCases = map[string][]rpcTestCase{ { name: "positive, with arguments, result=false", params: fmt.Sprintf(`["%s", [{"type": "String", "value": "invalid_string"}, {"type": "Integer", "value": "4"}, {"type":"Boolean", "value": false}]]`, verifyWithArgsContractHash), - result: func(e *executor) interface{} { return &result.Invoke{} }, - check: func(t *testing.T, e *executor, inv interface{}) { + result: func(e *executor) any { return &result.Invoke{} }, + check: func(t *testing.T, e *executor, inv any) { res, ok := inv.(*result.Invoke) require.True(t, ok) expectedInvScript := io.NewBufBinWriter() @@ -1486,8 +1486,8 @@ var rpcTestCases = map[string][]rpcTestCase{ { name: "positive, by index", params: fmt.Sprintf(`[20,"%s", [], [{"account":"%s"}]]`, verifyContractHash, testchain.PrivateKeyByID(0).PublicKey().GetScriptHash().StringLE()), - result: func(e *executor) interface{} { return &result.Invoke{} }, - check: func(t *testing.T, e *executor, inv interface{}) { + result: func(e *executor) any { return &result.Invoke{} }, + check: func(t *testing.T, e *executor, inv any) { res, ok := inv.(*result.Invoke) require.True(t, ok) assert.Nil(t, res.Script) // empty witness invocation script (pushes args of `verify` on stack, but this `verify` don't have args) @@ -1499,8 +1499,8 @@ var rpcTestCases = map[string][]rpcTestCase{ { name: "positive, by stateroot", params: fmt.Sprintf(`["`+block20StateRootLE+`","%s", [], [{"account":"%s"}]]`, verifyContractHash, testchain.PrivateKeyByID(0).PublicKey().GetScriptHash().StringLE()), - result: func(e *executor) interface{} { return &result.Invoke{} }, - check: func(t *testing.T, e *executor, inv interface{}) { + result: func(e *executor) any { return &result.Invoke{} }, + check: func(t *testing.T, e *executor, inv any) { res, ok := inv.(*result.Invoke) require.True(t, ok) assert.Nil(t, res.Script) // empty witness invocation script (pushes args of `verify` on stack, but this `verify` don't have args) @@ -1512,8 +1512,8 @@ var rpcTestCases = map[string][]rpcTestCase{ { name: "positive, no signers", params: fmt.Sprintf(`[20,"%s", []]`, verifyContractHash), - result: func(e *executor) interface{} { return &result.Invoke{} }, - check: func(t *testing.T, e *executor, inv interface{}) { + result: func(e *executor) any { return &result.Invoke{} }, + check: func(t *testing.T, e *executor, inv any) { res, ok := inv.(*result.Invoke) require.True(t, ok) assert.Nil(t, res.Script) @@ -1525,8 +1525,8 @@ var rpcTestCases = map[string][]rpcTestCase{ { name: "positive, no arguments", params: fmt.Sprintf(`[20,"%s"]`, verifyContractHash), - result: func(e *executor) interface{} { return &result.Invoke{} }, - check: func(t *testing.T, e *executor, inv interface{}) { + result: func(e *executor) any { return &result.Invoke{} }, + check: func(t *testing.T, e *executor, inv any) { res, ok := inv.(*result.Invoke) require.True(t, ok) assert.Nil(t, res.Script) @@ -1538,8 +1538,8 @@ var rpcTestCases = map[string][]rpcTestCase{ { name: "positive, with signers and scripts", params: fmt.Sprintf(`[20,"%s", [], [{"account":"%s", "invocation":"MQo=", "verification": ""}]]`, verifyContractHash, testchain.PrivateKeyByID(0).PublicKey().GetScriptHash().StringLE()), - result: func(e *executor) interface{} { return &result.Invoke{} }, - check: func(t *testing.T, e *executor, inv interface{}) { + result: func(e *executor) any { return &result.Invoke{} }, + check: func(t *testing.T, e *executor, inv any) { res, ok := inv.(*result.Invoke) require.True(t, ok) assert.Nil(t, res.Script) @@ -1551,8 +1551,8 @@ var rpcTestCases = map[string][]rpcTestCase{ { name: "positive, with arguments, result=true", params: fmt.Sprintf(`[20,"%s", [{"type": "String", "value": "good_string"}, {"type": "Integer", "value": "4"}, {"type":"Boolean", "value": false}]]`, verifyWithArgsContractHash), - result: func(e *executor) interface{} { return &result.Invoke{} }, - check: func(t *testing.T, e *executor, inv interface{}) { + result: func(e *executor) any { return &result.Invoke{} }, + check: func(t *testing.T, e *executor, inv any) { res, ok := inv.(*result.Invoke) require.True(t, ok) expectedInvScript := io.NewBufBinWriter() @@ -1569,8 +1569,8 @@ var rpcTestCases = map[string][]rpcTestCase{ { name: "positive, with arguments, result=false", params: fmt.Sprintf(`[20, "%s", [{"type": "String", "value": "invalid_string"}, {"type": "Integer", "value": "4"}, {"type":"Boolean", "value": false}]]`, verifyWithArgsContractHash), - result: func(e *executor) interface{} { return &result.Invoke{} }, - check: func(t *testing.T, e *executor, inv interface{}) { + result: func(e *executor) any { return &result.Invoke{} }, + check: func(t *testing.T, e *executor, inv any) { res, ok := inv.(*result.Invoke) require.True(t, ok) expectedInvScript := io.NewBufBinWriter() @@ -1609,8 +1609,8 @@ var rpcTestCases = map[string][]rpcTestCase{ { name: "positive", params: `["AB0AAACWP5gAAAAAAEDaEgAAAAAAGAAAAAHunqIsJ+NL0BSPxBCOCPdOj1BIsoAAXgsDAOh2SBcAAAAMFBEmW7QXJQBBvgTo+iQOOPV8HlabDBTunqIsJ+NL0BSPxBCOCPdOj1BIshTAHwwIdHJhbnNmZXIMFPVj6kC8KD1NDgXEjqMFs/Kgc0DvQWJ9W1IBQgxAJ6norhWoZxp+Hj1JFhi+Z3qI9DUkLSbfsbaLSaJIqxTfdmPbNFDVK1G+oa+LWmpRp/bj9+QZM7yC+S6HXUI7rigMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwkFW57Mn"]`, - result: func(e *executor) interface{} { return &result.RelayResult{} }, - check: func(t *testing.T, e *executor, inv interface{}) { + result: func(e *executor) any { return &result.RelayResult{} }, + check: func(t *testing.T, e *executor, inv any) { res, ok := inv.(*result.RelayResult) require.True(t, ok) expectedHash := "c11861dec1dd0f188608b725095041fcfc90abe51eea044993f122f22472753e" @@ -1673,8 +1673,8 @@ var rpcTestCases = map[string][]rpcTestCase{ { name: "positive", params: `["Nbb1qkwcwNSBs9pAnrVVrnFbWnbWBk91U2"]`, - result: func(*executor) interface{} { return &result.ValidateAddress{} }, - check: func(t *testing.T, e *executor, va interface{}) { + result: func(*executor) any { return &result.ValidateAddress{} }, + check: func(t *testing.T, e *executor, va any) { res, ok := va.(*result.ValidateAddress) require.True(t, ok) assert.Equal(t, "Nbb1qkwcwNSBs9pAnrVVrnFbWnbWBk91U2", res.Address) @@ -1684,7 +1684,7 @@ var rpcTestCases = map[string][]rpcTestCase{ { name: "negative", params: "[1]", - result: func(*executor) interface{} { + result: func(*executor) any { return &result.ValidateAddress{ Address: float64(1), IsValid: false, @@ -2266,7 +2266,7 @@ func testRPCProtocol(t *testing.T, doRPCCall func(string, string, *testing.T) [] testHeaderHash := chain.GetHeaderHash(1).StringLE() hdr := e.getHeader(testHeaderHash) - runCase := func(t *testing.T, rpc string, expected, actual interface{}) { + runCase := func(t *testing.T, rpc string, expected, actual any) { body := doRPCCall(rpc, httpSrv.URL, t) data := checkErrGetResult(t, body, false) require.NoError(t, json.Unmarshal(data, actual)) @@ -2616,7 +2616,7 @@ func encodeBlock(t *testing.T, b *block.Block) string { return base64.StdEncoding.EncodeToString(w.Bytes()) } -func (tc rpcTestCase) getResultPair(e *executor) (expected interface{}, res interface{}) { +func (tc rpcTestCase) getResultPair(e *executor) (expected any, res any) { expected = tc.result(e) resVal := reflect.New(reflect.TypeOf(expected).Elem()) res = resVal.Interface() @@ -2682,7 +2682,7 @@ func doRPCCallOverHTTP(rpcCall string, url string, t *testing.T) []byte { return bytes.TrimSpace(body) } -func checkNep11Balances(t *testing.T, e *executor, acc interface{}) { +func checkNep11Balances(t *testing.T, e *executor, acc any) { res, ok := acc.(*result.NEP11Balances) require.True(t, ok) @@ -2720,7 +2720,7 @@ func checkNep11Balances(t *testing.T, e *executor, acc interface{}) { require.ElementsMatch(t, expected.Balances, res.Balances) } -func checkNep17Balances(t *testing.T, e *executor, acc interface{}) { +func checkNep17Balances(t *testing.T, e *executor, acc any) { res, ok := acc.(*result.NEP17Balances) require.True(t, ok) rubles, err := util.Uint160DecodeStringLE(testContractHash) @@ -2756,11 +2756,11 @@ func checkNep17Balances(t *testing.T, e *executor, acc interface{}) { require.ElementsMatch(t, expected.Balances, res.Balances) } -func checkNep11Transfers(t *testing.T, e *executor, acc interface{}) { +func checkNep11Transfers(t *testing.T, e *executor, acc any) { checkNep11TransfersAux(t, e, acc, []int{0}, []int{0, 1, 2}) } -func checkNep11TransfersAux(t *testing.T, e *executor, acc interface{}, sent, rcvd []int) { +func checkNep11TransfersAux(t *testing.T, e *executor, acc any, sent, rcvd []int) { res, ok := acc.(*result.NEP11Transfers) require.True(t, ok) @@ -2858,11 +2858,11 @@ func checkNep11TransfersAux(t *testing.T, e *executor, acc interface{}, sent, rc require.Equal(t, arr, res.Received) } -func checkNep17Transfers(t *testing.T, e *executor, acc interface{}) { +func checkNep17Transfers(t *testing.T, e *executor, acc any) { checkNep17TransfersAux(t, e, acc, []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24}, []int{0, 1, 2, 3, 4, 5, 6, 7, 8}) } -func checkNep17TransfersAux(t *testing.T, e *executor, acc interface{}, sent, rcvd []int) { +func checkNep17TransfersAux(t *testing.T, e *executor, acc any, sent, rcvd []int) { res, ok := acc.(*result.NEP17Transfers) require.True(t, ok) rublesHash, err := util.Uint160DecodeStringLE(testContractHash) diff --git a/pkg/services/rpcsrv/subscription.go b/pkg/services/rpcsrv/subscription.go index 511aed2ef..e8f2336cc 100644 --- a/pkg/services/rpcsrv/subscription.go +++ b/pkg/services/rpcsrv/subscription.go @@ -27,7 +27,7 @@ type ( // feed stores subscriber's desired event ID with filter. feed struct { event neorpc.EventID - filter interface{} + filter any } ) @@ -37,7 +37,7 @@ func (f feed) EventID() neorpc.EventID { } // Filter implements neorpc.EventComparator interface and returns notification filter. -func (f feed) Filter() interface{} { +func (f feed) Filter() any { return f.filter } diff --git a/pkg/services/rpcsrv/subscription_test.go b/pkg/services/rpcsrv/subscription_test.go index 752ed03fa..2aece5b6e 100644 --- a/pkg/services/rpcsrv/subscription_test.go +++ b/pkg/services/rpcsrv/subscription_test.go @@ -171,7 +171,7 @@ func TestFilteredSubscriptions(t *testing.T) { "tx matching sender": { params: `["transaction_added", {"sender":"` + goodSender.StringLE() + `"}]`, check: func(t *testing.T, resp *neorpc.Notification) { - rmap := resp.Payload[0].(map[string]interface{}) + rmap := resp.Payload[0].(map[string]any) require.Equal(t, neorpc.TransactionEventID, resp.Event) sender := rmap["sender"].(string) require.Equal(t, address.Uint160ToString(goodSender), sender) @@ -180,10 +180,10 @@ func TestFilteredSubscriptions(t *testing.T) { "tx matching signer": { params: `["transaction_added", {"signer":"` + goodSender.StringLE() + `"}]`, check: func(t *testing.T, resp *neorpc.Notification) { - rmap := resp.Payload[0].(map[string]interface{}) + rmap := resp.Payload[0].(map[string]any) require.Equal(t, neorpc.TransactionEventID, resp.Event) - signers := rmap["signers"].([]interface{}) - signer0 := signers[0].(map[string]interface{}) + signers := rmap["signers"].([]any) + signer0 := signers[0].(map[string]any) signer0acc := signer0["account"].(string) require.Equal(t, "0x"+goodSender.StringLE(), signer0acc) }, @@ -191,12 +191,12 @@ func TestFilteredSubscriptions(t *testing.T) { "tx matching sender and signer": { params: `["transaction_added", {"sender":"` + goodSender.StringLE() + `", "signer":"` + goodSender.StringLE() + `"}]`, check: func(t *testing.T, resp *neorpc.Notification) { - rmap := resp.Payload[0].(map[string]interface{}) + rmap := resp.Payload[0].(map[string]any) require.Equal(t, neorpc.TransactionEventID, resp.Event) sender := rmap["sender"].(string) require.Equal(t, address.Uint160ToString(goodSender), sender) - signers := rmap["signers"].([]interface{}) - signer0 := signers[0].(map[string]interface{}) + signers := rmap["signers"].([]any) + signer0 := signers[0].(map[string]any) signer0acc := signer0["account"].(string) require.Equal(t, "0x"+goodSender.StringLE(), signer0acc) }, @@ -204,7 +204,7 @@ func TestFilteredSubscriptions(t *testing.T) { "notification matching contract hash": { params: `["notification_from_execution", {"contract":"` + testContractHash + `"}]`, check: func(t *testing.T, resp *neorpc.Notification) { - rmap := resp.Payload[0].(map[string]interface{}) + rmap := resp.Payload[0].(map[string]any) require.Equal(t, neorpc.NotificationEventID, resp.Event) c := rmap["contract"].(string) require.Equal(t, "0x"+testContractHash, c) @@ -213,7 +213,7 @@ func TestFilteredSubscriptions(t *testing.T) { "notification matching name": { params: `["notification_from_execution", {"name":"my_pretty_notification"}]`, check: func(t *testing.T, resp *neorpc.Notification) { - rmap := resp.Payload[0].(map[string]interface{}) + rmap := resp.Payload[0].(map[string]any) require.Equal(t, neorpc.NotificationEventID, resp.Event) n := rmap["name"].(string) require.Equal(t, "my_pretty_notification", n) @@ -222,7 +222,7 @@ func TestFilteredSubscriptions(t *testing.T) { "notification matching contract hash and name": { params: `["notification_from_execution", {"contract":"` + testContractHash + `", "name":"my_pretty_notification"}]`, check: func(t *testing.T, resp *neorpc.Notification) { - rmap := resp.Payload[0].(map[string]interface{}) + rmap := resp.Payload[0].(map[string]any) require.Equal(t, neorpc.NotificationEventID, resp.Event) c := rmap["contract"].(string) require.Equal(t, "0x"+testContractHash, c) @@ -233,7 +233,7 @@ func TestFilteredSubscriptions(t *testing.T) { "execution matching state": { params: `["transaction_executed", {"state":"HALT"}]`, check: func(t *testing.T, resp *neorpc.Notification) { - rmap := resp.Payload[0].(map[string]interface{}) + rmap := resp.Payload[0].(map[string]any) require.Equal(t, neorpc.ExecutionEventID, resp.Event) st := rmap["vmstate"].(string) require.Equal(t, "HALT", st) @@ -242,7 +242,7 @@ func TestFilteredSubscriptions(t *testing.T) { "execution matching container": { params: `["transaction_executed", {"container":"` + deploymentTxHash + `"}]`, check: func(t *testing.T, resp *neorpc.Notification) { - rmap := resp.Payload[0].(map[string]interface{}) + rmap := resp.Payload[0].(map[string]any) require.Equal(t, neorpc.ExecutionEventID, resp.Event) tx := rmap["container"].(string) require.Equal(t, "0x"+deploymentTxHash, tx) @@ -251,7 +251,7 @@ func TestFilteredSubscriptions(t *testing.T) { "execution matching state and container": { params: `["transaction_executed", {"state":"HALT", "container":"` + deploymentTxHash + `"}]`, check: func(t *testing.T, resp *neorpc.Notification) { - rmap := resp.Payload[0].(map[string]interface{}) + rmap := resp.Payload[0].(map[string]any) require.Equal(t, neorpc.ExecutionEventID, resp.Event) tx := rmap["container"].(string) require.Equal(t, "0x"+deploymentTxHash, tx) @@ -299,7 +299,7 @@ func TestFilteredSubscriptions(t *testing.T) { for { resp := getNotification(t, respMsgs) - rmap := resp.Payload[0].(map[string]interface{}) + rmap := resp.Payload[0].(map[string]any) if resp.Event == neorpc.BlockEventID { index := rmap["index"].(float64) if uint32(index) == lastBlock { @@ -331,25 +331,25 @@ func TestFilteredNotaryRequestSubscriptions(t *testing.T) { "matching sender": { params: `["notary_request_event", {"sender":"` + goodSender.StringLE() + `"}]`, check: func(t *testing.T, resp *neorpc.Notification) { - rmap := resp.Payload[0].(map[string]interface{}) + rmap := resp.Payload[0].(map[string]any) require.Equal(t, neorpc.NotaryRequestEventID, resp.Event) require.Equal(t, "added", rmap["type"].(string)) - req := rmap["notaryrequest"].(map[string]interface{}) - fbTx := req["fallbacktx"].(map[string]interface{}) - sender := fbTx["signers"].([]interface{})[1].(map[string]interface{})["account"].(string) + req := rmap["notaryrequest"].(map[string]any) + fbTx := req["fallbacktx"].(map[string]any) + sender := fbTx["signers"].([]any)[1].(map[string]any)["account"].(string) require.Equal(t, "0x"+goodSender.StringLE(), sender) }, }, "matching signer": { params: `["notary_request_event", {"signer":"` + goodSender.StringLE() + `"}]`, check: func(t *testing.T, resp *neorpc.Notification) { - rmap := resp.Payload[0].(map[string]interface{}) + rmap := resp.Payload[0].(map[string]any) require.Equal(t, neorpc.NotaryRequestEventID, resp.Event) require.Equal(t, "added", rmap["type"].(string)) - req := rmap["notaryrequest"].(map[string]interface{}) - mainTx := req["maintx"].(map[string]interface{}) - signers := mainTx["signers"].([]interface{}) - signer0 := signers[0].(map[string]interface{}) + req := rmap["notaryrequest"].(map[string]any) + mainTx := req["maintx"].(map[string]any) + signers := mainTx["signers"].([]any) + signer0 := signers[0].(map[string]any) signer0acc := signer0["account"].(string) require.Equal(t, "0x"+goodSender.StringLE(), signer0acc) }, @@ -357,16 +357,16 @@ func TestFilteredNotaryRequestSubscriptions(t *testing.T) { "matching sender and signer": { params: `["notary_request_event", {"sender":"` + goodSender.StringLE() + `", "signer":"` + goodSender.StringLE() + `"}]`, check: func(t *testing.T, resp *neorpc.Notification) { - rmap := resp.Payload[0].(map[string]interface{}) + rmap := resp.Payload[0].(map[string]any) require.Equal(t, neorpc.NotaryRequestEventID, resp.Event) require.Equal(t, "added", rmap["type"].(string)) - req := rmap["notaryrequest"].(map[string]interface{}) - mainTx := req["maintx"].(map[string]interface{}) - fbTx := req["fallbacktx"].(map[string]interface{}) - sender := fbTx["signers"].([]interface{})[1].(map[string]interface{})["account"].(string) + req := rmap["notaryrequest"].(map[string]any) + mainTx := req["maintx"].(map[string]any) + fbTx := req["fallbacktx"].(map[string]any) + sender := fbTx["signers"].([]any)[1].(map[string]any)["account"].(string) require.Equal(t, "0x"+goodSender.StringLE(), sender) - signers := mainTx["signers"].([]interface{}) - signer0 := signers[0].(map[string]interface{}) + signers := mainTx["signers"].([]any) + signer0 := signers[0].(map[string]any) signer0acc := signer0["account"].(string) require.Equal(t, "0x"+goodSender.StringLE(), signer0acc) }, @@ -443,7 +443,7 @@ func TestFilteredBlockSubscriptions(t *testing.T) { } require.Equal(t, neorpc.BlockEventID, resp.Event) - rmap := resp.Payload[0].(map[string]interface{}) + rmap := resp.Payload[0].(map[string]any) primary := rmap["primary"].(float64) require.Equal(t, 3, int(primary)) } diff --git a/pkg/services/rpcsrv/tokens.go b/pkg/services/rpcsrv/tokens.go index 4844a85d4..38530fa95 100644 --- a/pkg/services/rpcsrv/tokens.go +++ b/pkg/services/rpcsrv/tokens.go @@ -6,9 +6,9 @@ import ( // tokenTransfers is a generic type used to represent NEP-11 and NEP-17 transfers. type tokenTransfers struct { - Sent []interface{} `json:"sent"` - Received []interface{} `json:"received"` - Address string `json:"address"` + Sent []any `json:"sent"` + Received []any `json:"received"` + Address string `json:"address"` } // nep17TransferToNEP11 adds an ID to the provided NEP-17 transfer and returns a new diff --git a/pkg/services/stateroot/service_test.go b/pkg/services/stateroot/service_test.go index d71c2f101..544e30d24 100644 --- a/pkg/services/stateroot/service_test.go +++ b/pkg/services/stateroot/service_test.go @@ -85,7 +85,7 @@ func TestStateRoot(t *testing.T) { gasValidatorInvoker := e.ValidatorInvoker(e.NativeHash(t, nativenames.Gas)) h, pubs, accs := newMajorityMultisigWithGAS(t, 2) - validatorNodes := []interface{}{pubs[0].Bytes(), pubs[1].Bytes()} + validatorNodes := []any{pubs[0].Bytes(), pubs[1].Bytes()} designationSuperInvoker.Invoke(t, stackitem.Null{}, "designateAsRole", int64(roles.StateValidator), validatorNodes) updateIndex := bc.BlockHeight() @@ -166,7 +166,7 @@ func TestStateRootInitNonZeroHeight(t *testing.T) { designationSuperInvoker := e.NewInvoker(e.NativeHash(t, nativenames.Designation), validator, committee) gasValidatorInvoker := e.ValidatorInvoker(e.NativeHash(t, nativenames.Gas)) - validatorNodes := []interface{}{pubs[0].Bytes(), pubs[1].Bytes()} + validatorNodes := []any{pubs[0].Bytes(), pubs[1].Bytes()} designationSuperInvoker.Invoke(t, stackitem.Null{}, "designateAsRole", int64(roles.StateValidator), validatorNodes) gasValidatorInvoker.Invoke(t, true, "transfer", validator.ScriptHash(), h, 1_0000_0000, nil) @@ -244,7 +244,7 @@ func TestStateRootFull(t *testing.T) { srv.Start() t.Cleanup(srv.Shutdown) - validatorNodes := []interface{}{pubs[0].Bytes(), pubs[1].Bytes()} + validatorNodes := []any{pubs[0].Bytes(), pubs[1].Bytes()} designationSuperInvoker.Invoke(t, stackitem.Null{}, "designateAsRole", int64(roles.StateValidator), validatorNodes) gasValidatorInvoker.Invoke(t, true, "transfer", validator.ScriptHash(), h, 1_0000_0000, nil) diff --git a/pkg/smartcontract/binding/generate.go b/pkg/smartcontract/binding/generate.go index 62733b7ac..c02bbd49a 100644 --- a/pkg/smartcontract/binding/generate.go +++ b/pkg/smartcontract/binding/generate.go @@ -126,7 +126,7 @@ func scTypeToGo(name string, typ smartcontract.ParamType, cfg *Config) (string, switch typ { case smartcontract.AnyType: - return "interface{}", "" + return "any", "" case smartcontract.BoolType: return "bool", "" case smartcontract.IntegerType: @@ -144,11 +144,11 @@ func scTypeToGo(name string, typ smartcontract.ParamType, cfg *Config) (string, case smartcontract.SignatureType: return "interop.Signature", "github.com/nspcc-dev/neo-go/pkg/interop" case smartcontract.ArrayType: - return "[]interface{}", "" + return "[]any", "" case smartcontract.MapType: - return "map[string]interface{}", "" + return "map[string]any", "" case smartcontract.InteropInterfaceType: - return "interface{}", "" + return "any", "" case smartcontract.VoidType: return "", "" default: diff --git a/pkg/smartcontract/binding/override.go b/pkg/smartcontract/binding/override.go index 366bd562e..ed861a026 100644 --- a/pkg/smartcontract/binding/override.go +++ b/pkg/smartcontract/binding/override.go @@ -48,7 +48,7 @@ func NewOverrideFromString(s string) Override { } // UnmarshalYAML implements the YAML Unmarshaler interface. -func (o *Override) UnmarshalYAML(unmarshal func(interface{}) error) error { +func (o *Override) UnmarshalYAML(unmarshal func(any) error) error { var s string err := unmarshal(&s) @@ -61,7 +61,7 @@ func (o *Override) UnmarshalYAML(unmarshal func(interface{}) error) error { } // MarshalYAML implements the YAML marshaler interface. -func (o Override) MarshalYAML() (interface{}, error) { +func (o Override) MarshalYAML() (any, error) { if o.Package == "" { return o.TypeName, nil } diff --git a/pkg/smartcontract/builder.go b/pkg/smartcontract/builder.go index 369be1b64..6d5d03331 100644 --- a/pkg/smartcontract/builder.go +++ b/pkg/smartcontract/builder.go @@ -44,7 +44,7 @@ func NewBuilder() *Builder { // contract. The correctness of this invocation (number and type of parameters) is // out of scope of this method, as well as return value, if contract's method returns // something this value just remains on the execution stack. -func (b *Builder) InvokeMethod(contract util.Uint160, method string, params ...interface{}) { +func (b *Builder) InvokeMethod(contract util.Uint160, method string, params ...any) { emit.AppCall(b.bw.BinWriter, contract, method, callflag.All, params...) } @@ -61,7 +61,7 @@ func (b *Builder) Assert() { // that as well as NEO's 'vote'. The ASSERT then allow to simplify transaction // status checking, if action is successful then transaction is successful as // well, if it went wrong than whole transaction fails (ends with vmstate.FAULT). -func (b *Builder) InvokeWithAssert(contract util.Uint160, method string, params ...interface{}) { +func (b *Builder) InvokeWithAssert(contract util.Uint160, method string, params ...any) { b.InvokeMethod(contract, method, params...) b.Assert() } diff --git a/pkg/smartcontract/callflag/call_flags.go b/pkg/smartcontract/callflag/call_flags.go index 224077c4b..03eebd0aa 100644 --- a/pkg/smartcontract/callflag/call_flags.go +++ b/pkg/smartcontract/callflag/call_flags.go @@ -119,12 +119,12 @@ func (f *CallFlag) UnmarshalJSON(data []byte) error { } // MarshalYAML implements the YAML marshaler interface. -func (f CallFlag) MarshalYAML() (interface{}, error) { +func (f CallFlag) MarshalYAML() (any, error) { return f.String(), nil } // UnmarshalYAML implements the YAML unmarshaler interface. -func (f *CallFlag) UnmarshalYAML(unmarshal func(interface{}) error) error { +func (f *CallFlag) UnmarshalYAML(unmarshal func(any) error) error { var s string err := unmarshal(&s) diff --git a/pkg/smartcontract/entry.go b/pkg/smartcontract/entry.go index c6f6b211a..99caed055 100644 --- a/pkg/smartcontract/entry.go +++ b/pkg/smartcontract/entry.go @@ -18,7 +18,7 @@ import ( // processed this way (and this number can't exceed VM limits), the result of the // script is an array containing extracted value elements. This script can be useful // for interactions with RPC server that have iterator sessions disabled. -func CreateCallAndUnwrapIteratorScript(contract util.Uint160, operation string, maxIteratorResultItems int, params ...interface{}) ([]byte, error) { +func CreateCallAndUnwrapIteratorScript(contract util.Uint160, operation string, maxIteratorResultItems int, params ...any) ([]byte, error) { script := io.NewBufBinWriter() emit.Int(script.BinWriter, int64(maxIteratorResultItems)) emit.AppCall(script.BinWriter, contract, operation, callflag.All, params...) // The System.Contract.Call itself, it will push Iterator on estack. @@ -71,7 +71,7 @@ func CreateCallAndUnwrapIteratorScript(contract util.Uint160, operation string, // CreateCallScript returns a script that calls contract's method with // the specified parameters. Whatever this method returns remains on the stack. // See also (*Builder).InvokeMethod. -func CreateCallScript(contract util.Uint160, method string, params ...interface{}) ([]byte, error) { +func CreateCallScript(contract util.Uint160, method string, params ...any) ([]byte, error) { b := NewBuilder() b.InvokeMethod(contract, method, params...) return b.Script() @@ -80,7 +80,7 @@ func CreateCallScript(contract util.Uint160, method string, params ...interface{ // CreateCallWithAssertScript returns a script that calls contract's method with // the specified parameters expecting a Boolean value to be return that then is // used for ASSERT. See also (*Builder).InvokeWithAssert. -func CreateCallWithAssertScript(contract util.Uint160, method string, params ...interface{}) ([]byte, error) { +func CreateCallWithAssertScript(contract util.Uint160, method string, params ...any) ([]byte, error) { b := NewBuilder() b.InvokeWithAssert(contract, method, params...) return b.Script() diff --git a/pkg/smartcontract/manifest/manifest.go b/pkg/smartcontract/manifest/manifest.go index ba391a657..c4e88e9b0 100644 --- a/pkg/smartcontract/manifest/manifest.go +++ b/pkg/smartcontract/manifest/manifest.go @@ -182,7 +182,7 @@ func extraToStackItem(rawExtra []byte) stackitem.Item { // Prevent accidental precision loss. d.UseNumber() - var obj interface{} + var obj any // The error can't really occur because `json.RawMessage` is already a valid json. _ = d.Decode(&obj) diff --git a/pkg/smartcontract/manifest/permission.go b/pkg/smartcontract/manifest/permission.go index 0859871db..260c73b14 100644 --- a/pkg/smartcontract/manifest/permission.go +++ b/pkg/smartcontract/manifest/permission.go @@ -27,7 +27,7 @@ const ( // PermissionDesc is a permission descriptor. type PermissionDesc struct { Type PermissionType - Value interface{} + Value any } // Permission describes which contracts may be invoked and which methods are called. @@ -45,13 +45,13 @@ type permissionAux struct { } // NewPermission returns a new permission of the given type. -func NewPermission(typ PermissionType, args ...interface{}) *Permission { +func NewPermission(typ PermissionType, args ...any) *Permission { return &Permission{ Contract: *newPermissionDesc(typ, args...), } } -func newPermissionDesc(typ PermissionType, args ...interface{}) *PermissionDesc { +func newPermissionDesc(typ PermissionType, args ...any) *PermissionDesc { desc := &PermissionDesc{Type: typ} switch typ { case PermissionWildcard: diff --git a/pkg/smartcontract/manifest/permission_test.go b/pkg/smartcontract/manifest/permission_test.go index 1016bb542..16fa923cc 100644 --- a/pkg/smartcontract/manifest/permission_test.go +++ b/pkg/smartcontract/manifest/permission_test.go @@ -144,7 +144,7 @@ func TestPermissionDesc_MarshalJSON(t *testing.T) { }) } -func testMarshalUnmarshal(t *testing.T, expected, actual interface{}) { +func testMarshalUnmarshal(t *testing.T, expected, actual any) { data, err := json.Marshal(expected) require.NoError(t, err) require.NoError(t, json.Unmarshal(data, actual)) diff --git a/pkg/smartcontract/param_type.go b/pkg/smartcontract/param_type.go index c6d640ae5..403a48649 100644 --- a/pkg/smartcontract/param_type.go +++ b/pkg/smartcontract/param_type.go @@ -123,12 +123,12 @@ func (pt *ParamType) UnmarshalJSON(data []byte) error { } // MarshalYAML implements the YAML Marshaler interface. -func (pt ParamType) MarshalYAML() (interface{}, error) { +func (pt ParamType) MarshalYAML() (any, error) { return pt.String(), nil } // UnmarshalYAML implements the YAML Unmarshaler interface. -func (pt *ParamType) UnmarshalYAML(unmarshal func(interface{}) error) error { +func (pt *ParamType) UnmarshalYAML(unmarshal func(any) error) error { var name string err := unmarshal(&name) @@ -275,7 +275,7 @@ func ParseParamType(typ string) (ParamType, error) { } // adjustValToType is a value type-checker and converter. -func adjustValToType(typ ParamType, val string) (interface{}, error) { +func adjustValToType(typ ParamType, val string) (any, error) { switch typ { case SignatureType: b, err := hex.DecodeString(val) diff --git a/pkg/smartcontract/param_type_test.go b/pkg/smartcontract/param_type_test.go index 88ac51fd6..9d3e51d2f 100644 --- a/pkg/smartcontract/param_type_test.go +++ b/pkg/smartcontract/param_type_test.go @@ -171,7 +171,7 @@ func TestAdjustValToType(t *testing.T) { var inouts = []struct { typ ParamType val string - out interface{} + out any err bool }{{ typ: SignatureType, diff --git a/pkg/smartcontract/parameter.go b/pkg/smartcontract/parameter.go index 06556eca1..afe48dba6 100644 --- a/pkg/smartcontract/parameter.go +++ b/pkg/smartcontract/parameter.go @@ -22,7 +22,7 @@ type Parameter struct { // Type of the parameter. Type ParamType `json:"type"` // The actual value of the parameter. - Value interface{} `json:"value"` + Value any `json:"value"` } // ParameterPair represents a key-value pair, a slice of which is stored in @@ -259,7 +259,7 @@ func NewParameterFromString(in string) (*Parameter, error) { // the value if needed. It does not copy the value if it can avoid doing so. All // regular integers, util.*, keys.PublicKey*, string and bool types are supported, // slice of byte slices is accepted and converted as well. -func NewParameterFromValue(value interface{}) (Parameter, error) { +func NewParameterFromValue(value any) (Parameter, error) { var result = Parameter{ Value: value, } @@ -353,7 +353,7 @@ func NewParameterFromValue(value interface{}) (Parameter, error) { } result.Type = ArrayType result.Value = arr - case []interface{}: + case []any: arr, err := NewParametersFromValues(v...) if err != nil { return result, err @@ -369,7 +369,7 @@ func NewParameterFromValue(value interface{}) (Parameter, error) { // NewParametersFromValues is similar to NewParameterFromValue except that it // works with multiple values and returns a simple slice of Parameter. -func NewParametersFromValues(values ...interface{}) ([]Parameter, error) { +func NewParametersFromValues(values ...any) ([]Parameter, error) { res := make([]Parameter, 0, len(values)) for i := range values { elem, err := NewParameterFromValue(values[i]) @@ -384,12 +384,12 @@ func NewParametersFromValues(values ...interface{}) ([]Parameter, error) { // ExpandParameterToEmitable converts a parameter to a type which can be handled as // an array item by emit.Array. It correlates with the way an RPC server handles // FuncParams for invoke* calls inside the request.ExpandArrayIntoScript function. -func ExpandParameterToEmitable(param Parameter) (interface{}, error) { +func ExpandParameterToEmitable(param Parameter) (any, error) { var err error switch t := param.Type; t { case ArrayType: arr := param.Value.([]Parameter) - res := make([]interface{}, len(arr)) + res := make([]any, len(arr)) for i := range arr { res[i], err = ExpandParameterToEmitable(arr[i]) if err != nil { diff --git a/pkg/smartcontract/parameter_test.go b/pkg/smartcontract/parameter_test.go index 295ed8f93..1150e9cbc 100644 --- a/pkg/smartcontract/parameter_test.go +++ b/pkg/smartcontract/parameter_test.go @@ -452,7 +452,7 @@ func TestExpandParameterToEmitableToStackitem(t *testing.T) { pk, _ := keys.NewPrivateKey() testCases := []struct { In Parameter - Expected interface{} + Expected any ExpectedStackitem stackitem.Item }{ { @@ -520,7 +520,7 @@ func TestExpandParameterToEmitableToStackitem(t *testing.T) { }, }, }}, - Expected: []interface{}{big.NewInt(123), []byte{1, 2, 3}, []interface{}{true}}, + Expected: []any{big.NewInt(123), []byte{1, 2, 3}, []any{true}}, ExpectedStackitem: stackitem.NewArray([]stackitem.Item{ stackitem.NewBigInteger(big.NewInt(123)), stackitem.NewByteArray([]byte{1, 2, 3}), @@ -558,9 +558,9 @@ func TestParameterFromValue(t *testing.T) { pk1, _ := keys.NewPrivateKey() pk2, _ := keys.NewPrivateKey() items := []struct { - value interface{} + value any expType ParamType - expVal interface{} + expVal any }{ { value: []byte{1, 2, 3}, @@ -723,7 +723,7 @@ func TestParameterFromValue(t *testing.T) { }}, }, { - value: []interface{}{-42, "random", []byte{1, 2, 3}}, + value: []any{-42, "random", []byte{1, 2, 3}}, expType: ArrayType, expVal: []Parameter{{ Type: IntegerType, @@ -748,7 +748,7 @@ func TestParameterFromValue(t *testing.T) { } _, err := NewParameterFromValue(make(map[string]int)) require.Error(t, err) - _, err = NewParameterFromValue([]interface{}{1, 2, make(map[string]int)}) + _, err = NewParameterFromValue([]any{1, 2, make(map[string]int)}) require.Error(t, err) } diff --git a/pkg/smartcontract/rpcbinding/binding.go b/pkg/smartcontract/rpcbinding/binding.go index b8f53d91a..3db076bd7 100644 --- a/pkg/smartcontract/rpcbinding/binding.go +++ b/pkg/smartcontract/rpcbinding/binding.go @@ -121,9 +121,9 @@ type Invoker interface { {{if or .IsNep11D .IsNep11ND}} nep11.Invoker {{else -}} {{ if .IsNep17}} nep17.Invoker -{{else if len .SafeMethods}} Call(contract util.Uint160, operation string, params ...interface{}) (*result.Invoke, error) +{{else if len .SafeMethods}} Call(contract util.Uint160, operation string, params ...any) (*result.Invoke, error) {{end -}} -{{if .HasIterator}} CallAndExpandIterator(contract util.Uint160, method string, maxItems int, params ...interface{}) (*result.Invoke, error) +{{if .HasIterator}} CallAndExpandIterator(contract util.Uint160, method string, maxItems int, params ...any) (*result.Invoke, error) TerminateSession(sessionID uuid.UUID) error TraverseIterator(sessionID uuid.UUID, iterator *result.Iterator, num int) ([]stackitem.Item, error) {{end -}} @@ -142,11 +142,11 @@ type Actor interface { nep17.Actor {{end}} {{- if len .Methods}} - MakeCall(contract util.Uint160, method string, params ...interface{}) (*transaction.Transaction, error) + MakeCall(contract util.Uint160, method string, params ...any) (*transaction.Transaction, error) MakeRun(script []byte) (*transaction.Transaction, error) - MakeUnsignedCall(contract util.Uint160, method string, attrs []transaction.Attribute, params ...interface{}) (*transaction.Transaction, error) + MakeUnsignedCall(contract util.Uint160, method string, attrs []transaction.Attribute, params ...any) (*transaction.Transaction, error) MakeUnsignedRun(script []byte, attrs []transaction.Attribute) (*transaction.Transaction, error) - SendCall(contract util.Uint160, method string, params ...interface{}) (util.Uint256, uint32, error) + SendCall(contract util.Uint160, method string, params ...any) (util.Uint256, uint32, error) SendRun(script []byte) (util.Uint256, uint32, error) {{end -}} } @@ -358,7 +358,7 @@ func dropStdMethods(meths []manifest.Method, std *standard.Standard) []manifest. func extendedTypeToGo(et binding.ExtendedType, named map[string]binding.ExtendedType) (string, string) { switch et.Base { case smartcontract.AnyType: - return "interface{}", "" + return "any", "" case smartcontract.BoolType: return "bool", "" case smartcontract.IntegerType: @@ -385,14 +385,14 @@ func extendedTypeToGo(et binding.ExtendedType, named map[string]binding.Extended sub, pkg := extendedTypeToGo(*et.Value, named) return "[]" + sub, pkg } - return "[]interface{}", "" + return "[]any", "" case smartcontract.MapType: kt, _ := extendedTypeToGo(binding.ExtendedType{Base: et.Key}, named) vt, _ := extendedTypeToGo(*et.Value, named) return "map[" + kt + "]" + vt, "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" case smartcontract.InteropInterfaceType: - return "interface{}", "" + return "any", "" case smartcontract.VoidType: return "", "" } @@ -554,7 +554,7 @@ func scTemplateToRPC(cfg binding.Config, ctr ContractTmpl, imports map[string]st for i := range ctr.SafeMethods { switch ctr.SafeMethods[i].ReturnType { - case "interface{}": + case "any": abim := cfg.Manifest.ABI.GetMethod(ctr.SafeMethods[i].NameABI, len(ctr.SafeMethods[i].Arguments)) if abim.ReturnType == smartcontract.InteropInterfaceType { imports["github.com/google/uuid"] = struct{}{} @@ -565,7 +565,7 @@ func scTemplateToRPC(cfg binding.Config, ctr ContractTmpl, imports map[string]st ctr.HasIterator = true } else { imports["github.com/nspcc-dev/neo-go/pkg/vm/stackitem"] = struct{}{} - ctr.SafeMethods[i].ReturnType = "interface{}" + ctr.SafeMethods[i].ReturnType = "any" ctr.SafeMethods[i].Unwrapper = "Item" } case "bool": @@ -582,7 +582,7 @@ func scTemplateToRPC(cfg binding.Config, ctr ContractTmpl, imports map[string]st ctr.SafeMethods[i].Unwrapper = "PublicKey" case "[]byte": ctr.SafeMethods[i].Unwrapper = "Bytes" - case "[]interface{}": + case "[]any": imports["github.com/nspcc-dev/neo-go/pkg/vm/stackitem"] = struct{}{} ctr.SafeMethods[i].ReturnType = "[]stackitem.Item" ctr.SafeMethods[i].Unwrapper = "Array" diff --git a/pkg/util/uint160.go b/pkg/util/uint160.go index 2f107e05e..ddb992a98 100644 --- a/pkg/util/uint160.go +++ b/pkg/util/uint160.go @@ -141,7 +141,7 @@ func (u Uint160) MarshalJSON() ([]byte, error) { } // UnmarshalYAML implements the YAML Unmarshaler interface. -func (u *Uint160) UnmarshalYAML(unmarshal func(interface{}) error) error { +func (u *Uint160) UnmarshalYAML(unmarshal func(any) error) error { var s string err := unmarshal(&s) @@ -155,7 +155,7 @@ func (u *Uint160) UnmarshalYAML(unmarshal func(interface{}) error) error { } // MarshalYAML implements the YAML marshaller interface. -func (u Uint160) MarshalYAML() (interface{}, error) { +func (u Uint160) MarshalYAML() (any, error) { return "0x" + u.StringLE(), nil } diff --git a/pkg/vm/emit/emit.go b/pkg/vm/emit/emit.go index 8292aa30e..b79fcdeac 100644 --- a/pkg/vm/emit/emit.go +++ b/pkg/vm/emit/emit.go @@ -99,14 +99,14 @@ func bigInt(w *io.BinWriter, n *big.Int, trySmall bool) { } // Array emits an array of elements to the given buffer. -func Array(w *io.BinWriter, es ...interface{}) { +func Array(w *io.BinWriter, es ...any) { if len(es) == 0 { Opcodes(w, opcode.NEWARRAY0) return } for i := len(es) - 1; i >= 0; i-- { switch e := es[i].(type) { - case []interface{}: + case []any: Array(w, e...) case int64: Int(w, e) @@ -225,7 +225,7 @@ func AppCallNoArgs(w *io.BinWriter, scriptHash util.Uint160, operation string, f } // AppCall emits SYSCALL with System.Contract.Call parameter for given contract, operation, call flag and arguments. -func AppCall(w *io.BinWriter, scriptHash util.Uint160, operation string, f callflag.CallFlag, args ...interface{}) { +func AppCall(w *io.BinWriter, scriptHash util.Uint160, operation string, f callflag.CallFlag, args ...any) { Array(w, args...) AppCallNoArgs(w, scriptHash, operation, f) } diff --git a/pkg/vm/emit/emit_test.go b/pkg/vm/emit/emit_test.go index a585161b4..63b35cfdb 100644 --- a/pkg/vm/emit/emit_test.go +++ b/pkg/vm/emit/emit_test.go @@ -224,7 +224,7 @@ func TestEmitArray(t *testing.T) { veryBig := new(big.Int).SetUint64(math.MaxUint64) veryBig.Add(veryBig, big.NewInt(1)) Array(buf.BinWriter, p160, p256, &u160, &u256, u160, u256, big.NewInt(0), veryBig, - []interface{}{int64(1), int64(2)}, nil, int64(1), "str", false, true, []byte{0xCA, 0xFE}) + []any{int64(1), int64(2)}, nil, int64(1), "str", false, true, []byte{0xCA, 0xFE}) require.NoError(t, buf.Err) res := buf.Bytes() diff --git a/pkg/vm/exception.go b/pkg/vm/exception.go index 61c509931..5498e9b44 100644 --- a/pkg/vm/exception.go +++ b/pkg/vm/exception.go @@ -45,7 +45,7 @@ func (c *exceptionHandlingContext) String() string { } // Value implements the stackitem.Item interface. -func (c *exceptionHandlingContext) Value() interface{} { +func (c *exceptionHandlingContext) Value() any { return c } diff --git a/pkg/vm/json_test.go b/pkg/vm/json_test.go index ada80b499..8df690145 100644 --- a/pkg/vm/json_test.go +++ b/pkg/vm/json_test.go @@ -54,7 +54,7 @@ type ( vmUTStackItem struct { Type vmUTStackItemType - Value interface{} + Value any } vmUTStep struct { diff --git a/pkg/vm/opcodebench_test.go b/pkg/vm/opcodebench_test.go index 1494dbd9a..e64405e78 100644 --- a/pkg/vm/opcodebench_test.go +++ b/pkg/vm/opcodebench_test.go @@ -43,11 +43,11 @@ func opParamVM(op opcode.Opcode, param []byte) func() *VM { return opParamPushVM(op, param) } -func opParamPushVM(op opcode.Opcode, param []byte, items ...interface{}) func() *VM { +func opParamPushVM(op opcode.Opcode, param []byte, items ...any) func() *VM { return opParamSlotsPushVM(op, param, 0, 0, 0, items...) } -func opParamSlotsPushVM(op opcode.Opcode, param []byte, sslot int, slotloc int, slotarg int, items ...interface{}) func() *VM { +func opParamSlotsPushVM(op opcode.Opcode, param []byte, sslot int, slotloc int, slotarg int, items ...any) func() *VM { return func() *VM { script := []byte{byte(op)} script = append(script, param...) @@ -75,7 +75,7 @@ func opParamSlotsPushVM(op opcode.Opcode, param []byte, sslot int, slotloc int, } } -func exceptParamPushVM(op opcode.Opcode, param []byte, ilen int, elen int, exception bool, items ...interface{}) func() *VM { +func exceptParamPushVM(op opcode.Opcode, param []byte, ilen int, elen int, exception bool, items ...any) func() *VM { return func() *VM { regVMF := opParamPushVM(op, param, items...) v := regVMF() @@ -136,8 +136,8 @@ func arrayOfOnes(size int) []stackitem.Item { return elems } -func arrayOfIfaces(size int) []interface{} { - var elems = make([]interface{}, size) +func arrayOfIfaces(size int) []any { + var elems = make([]any, size) for i := range elems { elems[i] = 1 } @@ -388,14 +388,14 @@ func BenchmarkOpcodes(t *testing.B) { if cp.op == opcode.PICK { name += "/" + strconv.Itoa(cp.pos) } - var getitems = func(element interface{}) []interface{} { + var getitems = func(element any) []any { l := cp.l pos := cp.pos if cp.op == opcode.PICK { pos++ l++ } - var items = make([]interface{}, l) + var items = make([]any, l) for i := range items { items[i] = 0 } @@ -461,12 +461,12 @@ func BenchmarkOpcodes(t *testing.B) { if sw.op == opcode.ROLL || sw.op == opcode.REVERSEN { name += "/" + strconv.Itoa(sw.num) } - var getitems = func(element interface{}) []interface{} { + var getitems = func(element any) []any { l := sw.num if sw.op == opcode.ROLL || sw.op == opcode.REVERSEN { l++ } - var items = make([]interface{}, l) + var items = make([]any, l) for i := range items { items[i] = element } @@ -656,7 +656,7 @@ func BenchmarkOpcodes(t *testing.B) { var nums = []int{1, 255, 1024} for _, n := range nums { t.Run(strconv.Itoa(n), func(t *testing.B) { - var elems = make([]interface{}, n+1) + var elems = make([]any, n+1) for i := range elems { elems[i] = 0 } diff --git a/pkg/vm/stack.go b/pkg/vm/stack.go index 9e609766e..bd83fba6a 100644 --- a/pkg/vm/stack.go +++ b/pkg/vm/stack.go @@ -22,7 +22,7 @@ type Element struct { // NewElement returns a new Element object, with its underlying value inferred // to the corresponding type. -func NewElement(v interface{}) Element { +func NewElement(v any) Element { return Element{stackitem.Make(v)} } @@ -32,7 +32,7 @@ func (e Element) Item() stackitem.Item { } // Value returns the value of the Item contained in the element. -func (e Element) Value() interface{} { +func (e Element) Value() any { return e.value.Value() } @@ -185,7 +185,7 @@ func (s *Stack) PushItem(i stackitem.Item) { // PushVal pushes the given value on the stack. It will infer the // underlying Item to its corresponding type. -func (s *Stack) PushVal(v interface{}) { +func (s *Stack) PushVal(v any) { s.Push(NewElement(v)) } diff --git a/pkg/vm/stackitem/item.go b/pkg/vm/stackitem/item.go index 6e645bf28..8e5952a46 100644 --- a/pkg/vm/stackitem/item.go +++ b/pkg/vm/stackitem/item.go @@ -36,7 +36,7 @@ const ( // Item represents the "real" value that is pushed on the stack. type Item interface { fmt.Stringer - Value() interface{} + Value() any // Dup duplicates current Item. Dup() Item // TryBool converts Item to a boolean value. @@ -88,7 +88,7 @@ func mkInvConversion(from Item, to Type) error { // Make tries to make an appropriate stack item from the provided value. // It will panic if it's not possible. -func Make(v interface{}) Item { +func Make(v any) Item { switch val := v.(type) { case int: return (*BigInteger)(big.NewInt(int64(val))) @@ -122,7 +122,7 @@ func Make(v interface{}) Item { a = append(a, Make(i)) } return Make(a) - case []interface{}: + case []any: res := make([]Item, len(val)) for i := range val { res[i] = Make(val[i]) @@ -210,7 +210,7 @@ func NewStruct(items []Item) *Struct { } // Value implements the Item interface. -func (i *Struct) Value() interface{} { +func (i *Struct) Value() any { return i.value } @@ -374,7 +374,7 @@ func (i Null) String() string { } // Value implements the Item interface. -func (i Null) Value() interface{} { +func (i Null) Value() any { return nil } @@ -483,7 +483,7 @@ func (i *BigInteger) Equals(s Item) bool { } // Value implements the Item interface. -func (i *BigInteger) Value() interface{} { +func (i *BigInteger) Value() any { return i.Big() } @@ -519,7 +519,7 @@ func NewBool(val bool) Bool { } // Value implements the Item interface. -func (i Bool) Value() interface{} { +func (i Bool) Value() any { return bool(i) } @@ -589,7 +589,7 @@ func NewByteArray(b []byte) *ByteArray { } // Value implements the Item interface. -func (i *ByteArray) Value() interface{} { +func (i *ByteArray) Value() any { return []byte(*i) } @@ -697,7 +697,7 @@ func NewArray(items []Item) *Array { } // Value implements the Item interface. -func (i *Array) Value() interface{} { +func (i *Array) Value() any { return i.value } @@ -818,7 +818,7 @@ func NewMapWithValue(value []MapElement) *Map { } // Value implements the Item interface. -func (i *Map) Value() interface{} { +func (i *Map) Value() any { return i.value } @@ -937,18 +937,18 @@ func IsValidMapKey(key Item) error { // Interop represents interop data on the stack. type Interop struct { - value interface{} + value any } // NewInterop returns a new Interop object. -func NewInterop(value interface{}) *Interop { +func NewInterop(value any) *Interop { return &Interop{ value: value, } } // Value implements the Item interface. -func (i *Interop) Value() interface{} { +func (i *Interop) Value() any { return i.value } @@ -1041,7 +1041,7 @@ func (p *Pointer) String() string { } // Value implements the Item interface. -func (p *Pointer) Value() interface{} { +func (p *Pointer) Value() any { return p.pos } @@ -1114,7 +1114,7 @@ func NewBuffer(b []byte) *Buffer { } // Value implements the Item interface. -func (i *Buffer) Value() interface{} { +func (i *Buffer) Value() any { return []byte(*i) } diff --git a/pkg/vm/stackitem/item_test.go b/pkg/vm/stackitem/item_test.go index 210f0a83d..c90763b84 100644 --- a/pkg/vm/stackitem/item_test.go +++ b/pkg/vm/stackitem/item_test.go @@ -10,7 +10,7 @@ import ( ) var makeStackItemTestCases = []struct { - input interface{} + input any result Item }{ { @@ -84,7 +84,7 @@ var makeStackItemTestCases = []struct { } var makeStackItemErrorCases = []struct { - input interface{} + input any }{ { input: map[int]int{1: 2}, diff --git a/pkg/vm/stackitem/json_test.go b/pkg/vm/stackitem/json_test.go index c68db70f0..45227feaf 100644 --- a/pkg/vm/stackitem/json_test.go +++ b/pkg/vm/stackitem/json_test.go @@ -9,7 +9,7 @@ import ( "github.com/stretchr/testify/require" ) -func getTestDecodeFunc(js string, expected ...interface{}) func(t *testing.T) { +func getTestDecodeFunc(js string, expected ...any) func(t *testing.T) { return func(t *testing.T) { actual, err := FromJSON([]byte(js), 20) if expected[0] == nil { diff --git a/pkg/vm/vm.go b/pkg/vm/vm.go index 950dfed7e..5541e25b8 100644 --- a/pkg/vm/vm.go +++ b/pkg/vm/vm.go @@ -30,14 +30,14 @@ import ( type errorAtInstruct struct { ip int op opcode.Opcode - err interface{} + err any } func (e *errorAtInstruct) Error() string { return fmt.Sprintf("at instruction %d (%s): %s", e.ip, e.op, e.err) } -func newError(ip int, op opcode.Opcode, err interface{}) *errorAtInstruct { +func newError(ip int, op opcode.Opcode, err any) *errorAtInstruct { return &errorAtInstruct{ip: ip, op: op, err: err} } @@ -379,7 +379,7 @@ func (v *VM) Context() *Context { // PopResult is used to pop the first item of the evaluation stack. This allows // us to test the compiler and the vm in a bi-directional way. -func (v *VM) PopResult() interface{} { +func (v *VM) PopResult() any { if v.estack.Len() == 0 { return nil } diff --git a/pkg/vm/vm_test.go b/pkg/vm/vm_test.go index d78ab22c3..67af89618 100644 --- a/pkg/vm/vm_test.go +++ b/pkg/vm/vm_test.go @@ -471,7 +471,7 @@ func TestPushData4BigN(t *testing.T) { checkVMFailed(t, vm) } -func getTestCallFlagsFunc(syscall []byte, flags callflag.CallFlag, result interface{}) func(t *testing.T) { +func getTestCallFlagsFunc(syscall []byte, flags callflag.CallFlag, result any) func(t *testing.T) { return func(t *testing.T) { script := append([]byte{byte(opcode.SYSCALL)}, syscall...) v := newTestVM() @@ -535,7 +535,7 @@ func getJMPProgram(op opcode.Opcode) []byte { return append(prog, byte(opcode.PUSH1), byte(opcode.RET), byte(opcode.PUSH2), byte(opcode.RET)) } -func testJMP(t *testing.T, op opcode.Opcode, res interface{}, items ...interface{}) { +func testJMP(t *testing.T, op opcode.Opcode, res any, items ...any) { prog := getJMPProgram(op) v := load(prog) for i := range items { @@ -552,35 +552,35 @@ func testJMP(t *testing.T, op opcode.Opcode, res interface{}, items ...interface func TestJMPs(t *testing.T) { testCases := []struct { name string - items []interface{} + items []any }{ { name: "no condition", }, { name: "single item (true)", - items: []interface{}{true}, + items: []any{true}, }, { name: "single item (false)", - items: []interface{}{false}, + items: []any{false}, }, { name: "24 and 42", - items: []interface{}{24, 42}, + items: []any{24, 42}, }, { name: "42 and 24", - items: []interface{}{42, 24}, + items: []any{42, 24}, }, { name: "42 and 42", - items: []interface{}{42, 42}, + items: []any{42, 42}, }, } // 2 is true, 1 is false - results := map[opcode.Opcode][]interface{}{ + results := map[opcode.Opcode][]any{ opcode.JMP: {2, 2, 2, 2, 2, 2}, opcode.JMPIF: {nil, 2, 1, 2, 2, 2}, opcode.JMPIFNOT: {nil, 1, 2, 1, 1, 1}, @@ -896,11 +896,11 @@ func TestEQUALByteArrayWithLimit(t *testing.T) { }) } -func runWithArgs(t *testing.T, prog []byte, result interface{}, args ...interface{}) { +func runWithArgs(t *testing.T, prog []byte, result any, args ...any) { getTestFuncForVM(prog, result, args...)(t) } -func getCustomTestFuncForVM(prog []byte, check func(t *testing.T, v *VM), args ...interface{}) func(t *testing.T) { +func getCustomTestFuncForVM(prog []byte, check func(t *testing.T, v *VM), args ...any) func(t *testing.T) { return func(t *testing.T) { v := load(prog) for i := range args { @@ -915,7 +915,7 @@ func getCustomTestFuncForVM(prog []byte, check func(t *testing.T, v *VM), args . } } -func getTestFuncForVM(prog []byte, result interface{}, args ...interface{}) func(t *testing.T) { +func getTestFuncForVM(prog []byte, result any, args ...any) func(t *testing.T) { var f func(t *testing.T, v *VM) if result != nil { f = func(t *testing.T, v *VM) { @@ -1057,7 +1057,7 @@ func getTRYProgram(tryBlock, catchBlock, finallyBlock []byte) []byte { return prog } -func getTRYTestFunc(result interface{}, tryBlock, catchBlock, finallyBlock []byte) func(t *testing.T) { +func getTRYTestFunc(result any, tryBlock, catchBlock, finallyBlock []byte) func(t *testing.T) { return func(t *testing.T) { prog := getTRYProgram(tryBlock, catchBlock, finallyBlock) runWithArgs(t, prog, result) @@ -1695,7 +1695,7 @@ func TestROLLGood(t *testing.T) { assert.Equal(t, stackitem.Make(1), vm.estack.Pop().value) } -func getCheckEStackFunc(items ...interface{}) func(t *testing.T, v *VM) { +func getCheckEStackFunc(items ...any) func(t *testing.T, v *VM) { return func(t *testing.T, v *VM) { require.Equal(t, len(items), v.estack.Len()) for i := 0; i < len(items); i++ { @@ -2255,7 +2255,7 @@ func TestCLEARITEMS(t *testing.T) { } func TestPOPITEM(t *testing.T) { - testPOPITEM := func(t *testing.T, item, elem, arr interface{}) { + testPOPITEM := func(t *testing.T, item, elem, arr any) { prog := makeProgram(opcode.DUP, opcode.POPITEM) v := load(prog) v.estack.PushVal(item) @@ -2351,51 +2351,51 @@ func TestDupBool(t *testing.T) { var opcodesTestCases = map[opcode.Opcode][]struct { name string - args []interface{} - expected interface{} - actual func(vm *VM) interface{} + args []any + expected any + actual func(vm *VM) any }{ opcode.AND: { { name: "1_1", - args: []interface{}{1, 1}, + args: []any{1, 1}, expected: int64(1), - actual: func(vm *VM) interface{} { + actual: func(vm *VM) any { return vm.estack.Pop().BigInt().Int64() }, }, { name: "1_0", - args: []interface{}{1, 0}, + args: []any{1, 0}, expected: int64(0), - actual: func(vm *VM) interface{} { + actual: func(vm *VM) any { return vm.estack.Pop().BigInt().Int64() }, }, { name: "0_1", - args: []interface{}{0, 1}, + args: []any{0, 1}, expected: int64(0), - actual: func(vm *VM) interface{} { + actual: func(vm *VM) any { return vm.estack.Pop().BigInt().Int64() }, }, { name: "0_0", - args: []interface{}{0, 0}, + args: []any{0, 0}, expected: int64(0), - actual: func(vm *VM) interface{} { + actual: func(vm *VM) any { return vm.estack.Pop().BigInt().Int64() }, }, { name: "random_values", - args: []interface{}{ + args: []any{ []byte{1, 0, 1, 0, 1, 0, 1, 1}, []byte{1, 1, 0, 0, 0, 0, 0, 1}, }, expected: []byte{1, 0, 0, 0, 0, 0, 0, 1}, - actual: func(vm *VM) interface{} { + actual: func(vm *VM) any { return vm.estack.Pop().Bytes() }, }, @@ -2403,44 +2403,44 @@ var opcodesTestCases = map[opcode.Opcode][]struct { opcode.OR: { { name: "1_1", - args: []interface{}{1, 1}, + args: []any{1, 1}, expected: int64(1), - actual: func(vm *VM) interface{} { + actual: func(vm *VM) any { return vm.estack.Pop().BigInt().Int64() }, }, { name: "0_0", - args: []interface{}{0, 0}, + args: []any{0, 0}, expected: int64(0), - actual: func(vm *VM) interface{} { + actual: func(vm *VM) any { return vm.estack.Pop().BigInt().Int64() }, }, { name: "0_1", - args: []interface{}{0, 1}, + args: []any{0, 1}, expected: int64(1), - actual: func(vm *VM) interface{} { + actual: func(vm *VM) any { return vm.estack.Pop().BigInt().Int64() }, }, { name: "1_0", - args: []interface{}{1, 0}, + args: []any{1, 0}, expected: int64(1), - actual: func(vm *VM) interface{} { + actual: func(vm *VM) any { return vm.estack.Pop().BigInt().Int64() }, }, { name: "random_values", - args: []interface{}{ + args: []any{ []byte{1, 0, 1, 0, 1, 0, 1, 1}, []byte{1, 1, 0, 0, 0, 0, 0, 1}, }, expected: []byte{1, 1, 1, 0, 1, 0, 1, 1}, - actual: func(vm *VM) interface{} { + actual: func(vm *VM) any { return vm.estack.Pop().Bytes() }, }, @@ -2448,44 +2448,44 @@ var opcodesTestCases = map[opcode.Opcode][]struct { opcode.XOR: { { name: "1_1", - args: []interface{}{1, 1}, + args: []any{1, 1}, expected: int64(0), - actual: func(vm *VM) interface{} { + actual: func(vm *VM) any { return vm.estack.Pop().BigInt().Int64() }, }, { name: "0_0", - args: []interface{}{0, 0}, + args: []any{0, 0}, expected: int64(0), - actual: func(vm *VM) interface{} { + actual: func(vm *VM) any { return vm.estack.Pop().BigInt().Int64() }, }, { name: "0_1", - args: []interface{}{0, 1}, + args: []any{0, 1}, expected: int64(1), - actual: func(vm *VM) interface{} { + actual: func(vm *VM) any { return vm.estack.Pop().BigInt().Int64() }, }, { name: "1_0", - args: []interface{}{1, 0}, + args: []any{1, 0}, expected: int64(1), - actual: func(vm *VM) interface{} { + actual: func(vm *VM) any { return vm.estack.Pop().BigInt().Int64() }, }, { name: "random_values", - args: []interface{}{ + args: []any{ []byte{1, 0, 1, 0, 1, 0, 1, 1}, []byte{1, 1, 0, 0, 0, 0, 0, 1}, }, expected: []byte{0, 1, 1, 0, 1, 0, 1}, - actual: func(vm *VM) interface{} { + actual: func(vm *VM) any { return vm.estack.Pop().Bytes() }, }, @@ -2493,33 +2493,33 @@ var opcodesTestCases = map[opcode.Opcode][]struct { opcode.BOOLOR: { { name: "1_1", - args: []interface{}{true, true}, + args: []any{true, true}, expected: true, - actual: func(vm *VM) interface{} { + actual: func(vm *VM) any { return vm.estack.Pop().Bool() }, }, { name: "0_0", - args: []interface{}{false, false}, + args: []any{false, false}, expected: false, - actual: func(vm *VM) interface{} { + actual: func(vm *VM) any { return vm.estack.Pop().Bool() }, }, { name: "0_1", - args: []interface{}{false, true}, + args: []any{false, true}, expected: true, - actual: func(vm *VM) interface{} { + actual: func(vm *VM) any { return vm.estack.Pop().Bool() }, }, { name: "1_0", - args: []interface{}{true, false}, + args: []any{true, false}, expected: true, - actual: func(vm *VM) interface{} { + actual: func(vm *VM) any { return vm.estack.Pop().Bool() }, }, @@ -2527,25 +2527,25 @@ var opcodesTestCases = map[opcode.Opcode][]struct { opcode.MIN: { { name: "3_5", - args: []interface{}{3, 5}, + args: []any{3, 5}, expected: int64(3), - actual: func(vm *VM) interface{} { + actual: func(vm *VM) any { return vm.estack.Pop().BigInt().Int64() }, }, { name: "5_3", - args: []interface{}{5, 3}, + args: []any{5, 3}, expected: int64(3), - actual: func(vm *VM) interface{} { + actual: func(vm *VM) any { return vm.estack.Pop().BigInt().Int64() }, }, { name: "3_3", - args: []interface{}{3, 3}, + args: []any{3, 3}, expected: int64(3), - actual: func(vm *VM) interface{} { + actual: func(vm *VM) any { return vm.estack.Pop().BigInt().Int64() }, }, @@ -2553,25 +2553,25 @@ var opcodesTestCases = map[opcode.Opcode][]struct { opcode.MAX: { { name: "3_5", - args: []interface{}{3, 5}, + args: []any{3, 5}, expected: int64(5), - actual: func(vm *VM) interface{} { + actual: func(vm *VM) any { return vm.estack.Pop().BigInt().Int64() }, }, { name: "5_3", - args: []interface{}{5, 3}, + args: []any{5, 3}, expected: int64(5), - actual: func(vm *VM) interface{} { + actual: func(vm *VM) any { return vm.estack.Pop().BigInt().Int64() }, }, { name: "3_3", - args: []interface{}{3, 3}, + args: []any{3, 3}, expected: int64(3), - actual: func(vm *VM) interface{} { + actual: func(vm *VM) any { return vm.estack.Pop().BigInt().Int64() }, }, @@ -2579,25 +2579,25 @@ var opcodesTestCases = map[opcode.Opcode][]struct { opcode.WITHIN: { { name: "within", - args: []interface{}{4, 3, 5}, + args: []any{4, 3, 5}, expected: true, - actual: func(vm *VM) interface{} { + actual: func(vm *VM) any { return vm.estack.Pop().Bool() }, }, { name: "less", - args: []interface{}{2, 3, 5}, + args: []any{2, 3, 5}, expected: false, - actual: func(vm *VM) interface{} { + actual: func(vm *VM) any { return vm.estack.Pop().Bool() }, }, { name: "more", - args: []interface{}{6, 3, 5}, + args: []any{6, 3, 5}, expected: false, - actual: func(vm *VM) interface{} { + actual: func(vm *VM) any { return vm.estack.Pop().Bool() }, }, @@ -2605,25 +2605,25 @@ var opcodesTestCases = map[opcode.Opcode][]struct { opcode.NEGATE: { { name: "3", - args: []interface{}{3}, + args: []any{3}, expected: int64(-3), - actual: func(vm *VM) interface{} { + actual: func(vm *VM) any { return vm.estack.Pop().BigInt().Int64() }, }, { name: "-3", - args: []interface{}{-3}, + args: []any{-3}, expected: int64(3), - actual: func(vm *VM) interface{} { + actual: func(vm *VM) any { return vm.estack.Pop().BigInt().Int64() }, }, { name: "0", - args: []interface{}{0}, + args: []any{0}, expected: int64(0), - actual: func(vm *VM) interface{} { + actual: func(vm *VM) any { return vm.estack.Pop().BigInt().Int64() }, },