diff --git a/cli/cmdargs/parser.go b/cli/cmdargs/parser.go index cddb51cb7..0379cf7f5 100644 --- a/cli/cmdargs/parser.go +++ b/cli/cmdargs/parser.go @@ -9,7 +9,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/encoding/address" - "github.com/nspcc-dev/neo-go/pkg/rpc/client" + "github.com/nspcc-dev/neo-go/pkg/rpcclient" "github.com/nspcc-dev/neo-go/pkg/smartcontract" "github.com/nspcc-dev/neo-go/pkg/wallet" "github.com/urfave/cli" @@ -188,14 +188,14 @@ func ParseParams(args []string, calledFromMain bool) (int, []smartcontract.Param // GetSignersAccounts returns the list of signers combined with the corresponding // accounts from the provided wallet. -func GetSignersAccounts(wall *wallet.Wallet, signers []transaction.Signer) ([]client.SignerAccount, error) { - signersAccounts := make([]client.SignerAccount, len(signers)) +func GetSignersAccounts(wall *wallet.Wallet, signers []transaction.Signer) ([]rpcclient.SignerAccount, error) { + signersAccounts := make([]rpcclient.SignerAccount, len(signers)) for i := range signers { signerAcc := wall.GetAccount(signers[i].Account) if signerAcc == nil { return nil, fmt.Errorf("no account was found in the wallet for signer #%d (%s)", i, address.Uint160ToString(signers[i].Account)) } - signersAccounts[i] = client.SignerAccount{ + signersAccounts[i] = rpcclient.SignerAccount{ Signer: signers[i], Account: signerAcc, } diff --git a/cli/options/options.go b/cli/options/options.go index ae536dd2f..0f4b72562 100644 --- a/cli/options/options.go +++ b/cli/options/options.go @@ -9,7 +9,7 @@ import ( "time" "github.com/nspcc-dev/neo-go/pkg/config/netmode" - "github.com/nspcc-dev/neo-go/pkg/rpc/client" + "github.com/nspcc-dev/neo-go/pkg/rpcclient" "github.com/urfave/cli" ) @@ -70,12 +70,12 @@ func GetTimeoutContext(ctx *cli.Context) (context.Context, func()) { } // GetRPCClient returns an RPC client instance for the given Context. -func GetRPCClient(gctx context.Context, ctx *cli.Context) (*client.Client, cli.ExitCoder) { +func GetRPCClient(gctx context.Context, ctx *cli.Context) (*rpcclient.Client, cli.ExitCoder) { endpoint := ctx.String(RPCEndpointFlag) if len(endpoint) == 0 { return nil, cli.NewExitError(errNoEndpoint, 1) } - c, err := client.New(gctx, endpoint, client.Options{}) + c, err := rpcclient.New(gctx, endpoint, rpcclient.Options{}) if err != nil { return nil, cli.NewExitError(err, 1) } diff --git a/cli/smartcontract/smart_contract.go b/cli/smartcontract/smart_contract.go index 148c8218f..2e28a586c 100644 --- a/cli/smartcontract/smart_contract.go +++ b/cli/smartcontract/smart_contract.go @@ -21,7 +21,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/encoding/address" "github.com/nspcc-dev/neo-go/pkg/encoding/fixedn" - "github.com/nspcc-dev/neo-go/pkg/rpc/client" + "github.com/nspcc-dev/neo-go/pkg/rpcclient" "github.com/nspcc-dev/neo-go/pkg/rpc/response/result" "github.com/nspcc-dev/neo-go/pkg/smartcontract" "github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest" @@ -645,7 +645,7 @@ func invokeWithArgs(ctx *cli.Context, acc *wallet.Account, wall *wallet.Wallet, var ( err error gas, sysgas fixedn.Fixed8 - cosignersAccounts []client.SignerAccount + cosignersAccounts []rpcclient.SignerAccount resp *result.Invoke sender util.Uint160 signAndPush = acc != nil diff --git a/cli/wallet/nep11.go b/cli/wallet/nep11.go index ab1cb4d5b..0631e8bc8 100644 --- a/cli/wallet/nep11.go +++ b/cli/wallet/nep11.go @@ -13,7 +13,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/encoding/address" "github.com/nspcc-dev/neo-go/pkg/encoding/fixedn" - "github.com/nspcc-dev/neo-go/pkg/rpc/client" + "github.com/nspcc-dev/neo-go/pkg/rpcclient" "github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest" "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" @@ -250,7 +250,7 @@ func transferNEP11(ctx *cli.Context) error { return transferNEP(ctx, manifest.NEP11StandardName) } -func signAndSendNEP11Transfer(ctx *cli.Context, c *client.Client, acc *wallet.Account, token, to util.Uint160, tokenID []byte, amount *big.Int, data interface{}, cosigners []client.SignerAccount) error { +func signAndSendNEP11Transfer(ctx *cli.Context, c *rpcclient.Client, acc *wallet.Account, token, to util.Uint160, tokenID []byte, amount *big.Int, data interface{}, cosigners []rpcclient.SignerAccount) error { gas := flags.Fixed8FromContext(ctx, "gas") sysgas := flags.Fixed8FromContext(ctx, "sysgas") diff --git a/cli/wallet/nep17.go b/cli/wallet/nep17.go index 7b045b3c0..6bda7a68d 100644 --- a/cli/wallet/nep17.go +++ b/cli/wallet/nep17.go @@ -15,8 +15,8 @@ import ( "github.com/nspcc-dev/neo-go/pkg/core/native/nativenames" "github.com/nspcc-dev/neo-go/pkg/encoding/address" "github.com/nspcc-dev/neo-go/pkg/encoding/fixedn" - "github.com/nspcc-dev/neo-go/pkg/rpc/client" "github.com/nspcc-dev/neo-go/pkg/rpc/response/result" + "github.com/nspcc-dev/neo-go/pkg/rpcclient" "github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest" "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/wallet" @@ -278,7 +278,7 @@ func printAssetBalance(ctx *cli.Context, asset util.Uint160, tokenName, tokenSym fmt.Fprintf(ctx.App.Writer, "\tUpdated: %d\n", balance.LastUpdated) } -func getNativeNEP17Symbol(c *client.Client, name string) (string, util.Uint160, error) { +func getNativeNEP17Symbol(c *rpcclient.Client, name string) (string, util.Uint160, error) { h, err := c.GetNativeContractHash(name) if err != nil { return "", util.Uint160{}, fmt.Errorf("failed to get native %s hash: %w", name, err) @@ -296,7 +296,7 @@ func getMatchingToken(ctx *cli.Context, w *wallet.Wallet, name string, standard }, len(w.Extra.Tokens), name, standard) } -func getMatchingTokenRPC(ctx *cli.Context, c *client.Client, addr util.Uint160, name string, standard string) (*wallet.Token, error) { +func getMatchingTokenRPC(ctx *cli.Context, c *rpcclient.Client, addr util.Uint160, name string, standard string) (*wallet.Token, error) { switch standard { case manifest.NEP17StandardName: bs, err := c.GetNEP17Balances(addr) @@ -493,7 +493,7 @@ func multiTransferNEP17(ctx *cli.Context) error { return cli.NewExitError("empty recipients list", 1) } var ( - recipients []client.TransferTarget + recipients []rpcclient.TransferTarget cosignersOffset = ctx.NArg() ) cache := make(map[string]*wallet.Token) @@ -526,7 +526,7 @@ func multiTransferNEP17(ctx *cli.Context) error { if err != nil { return cli.NewExitError(fmt.Errorf("invalid amount: %w", err), 1) } - recipients = append(recipients, client.TransferTarget{ + recipients = append(recipients, rpcclient.TransferTarget{ Token: token.Hash, Address: addr, Amount: amount.Int64(), @@ -608,7 +608,7 @@ func transferNEP(ctx *cli.Context, standard string) error { if err != nil { return cli.NewExitError(fmt.Errorf("invalid amount: %w", err), 1) } - return signAndSendNEP17Transfer(ctx, c, acc, []client.TransferTarget{{ + return signAndSendNEP17Transfer(ctx, c, acc, []rpcclient.TransferTarget{{ Token: token.Hash, Address: to, Amount: amount.Int64(), @@ -636,7 +636,7 @@ func transferNEP(ctx *cli.Context, standard string) error { } } -func signAndSendNEP17Transfer(ctx *cli.Context, c *client.Client, acc *wallet.Account, recipients []client.TransferTarget, cosigners []client.SignerAccount) error { +func signAndSendNEP17Transfer(ctx *cli.Context, c *rpcclient.Client, acc *wallet.Account, recipients []rpcclient.TransferTarget, cosigners []rpcclient.SignerAccount) error { gas := flags.Fixed8FromContext(ctx, "gas") sysgas := flags.Fixed8FromContext(ctx, "sysgas") diff --git a/cli/wallet/validator.go b/cli/wallet/validator.go index dc0511ff4..dd95c57b9 100644 --- a/cli/wallet/validator.go +++ b/cli/wallet/validator.go @@ -11,7 +11,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/encoding/address" "github.com/nspcc-dev/neo-go/pkg/io" - "github.com/nspcc-dev/neo-go/pkg/rpc/client" + "github.com/nspcc-dev/neo-go/pkg/rpcclient" "github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag" "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/vm/emit" @@ -125,7 +125,7 @@ func handleCandidate(ctx *cli.Context, method string, sysGas int64) error { w := io.NewBufBinWriter() emit.AppCall(w.BinWriter, neoContractHash, method, callflag.States, acc.PrivateKey().PublicKey().Bytes()) emit.Opcodes(w.BinWriter, opcode.ASSERT) - res, err := c.SignAndPushInvocationTx(w.Bytes(), acc, sysGas, gas, []client.SignerAccount{{ + res, err := c.SignAndPushInvocationTx(w.Bytes(), acc, sysGas, gas, []rpcclient.SignerAccount{{ Signer: transaction.Signer{ Account: acc.Contract.ScriptHash(), Scopes: transaction.CalledByEntry, @@ -186,7 +186,7 @@ func handleVote(ctx *cli.Context) error { emit.AppCall(w.BinWriter, neoContractHash, "vote", callflag.States, addr.BytesBE(), pubArg) emit.Opcodes(w.BinWriter, opcode.ASSERT) - res, err := c.SignAndPushInvocationTx(w.Bytes(), acc, -1, gas, []client.SignerAccount{{ + res, err := c.SignAndPushInvocationTx(w.Bytes(), acc, -1, gas, []rpcclient.SignerAccount{{ Signer: transaction.Signer{ Account: acc.Contract.ScriptHash(), Scopes: transaction.CalledByEntry, diff --git a/docs/notary.md b/docs/notary.md index 49ffbb991..c70515650 100644 --- a/docs/notary.md +++ b/docs/notary.md @@ -255,7 +255,7 @@ won't pass verification. Notary native contract supports `onNEP17Payment` method. Thus, to deposit funds to the Notary native contract, transfer the desired amount of GAS to the contract address. Use -[func (*Client) TransferNEP17](https://pkg.go.dev/github.com/nspcc-dev/neo-go@v0.97.2/pkg/rpc/client#Client.TransferNEP17) +[func (*Client) TransferNEP17](https://pkg.go.dev/github.com/nspcc-dev/neo-go@v0.97.2/pkg/rpcclient#Client.TransferNEP17) with the `data` parameter matching the following requirements: - `data` should be an array of two elements: `to` and `till`. - `to` denotes the receiver of the deposit. It can be nil in case `to` equals @@ -308,7 +308,7 @@ the steps to create a signature request: constraints: * Notary signer hash is the hash of a native Notary contract that can be fetched from - [func (*Client) GetNativeContractHash](https://pkg.go.dev/github.com/nspcc-dev/neo-go@v0.97.2/pkg/rpc/client#Client.GetNativeContractHash). + [func (*Client) GetNativeContractHash](https://pkg.go.dev/github.com/nspcc-dev/neo-go@v0.97.2/pkg/rpcclient#Client.GetNativeContractHash). * A notary signer must have `None` scope. * A notary signer shouldn't be placed at the beginning of the signer list because Notary contract does not pay main transaction fees. Other positions @@ -317,11 +317,11 @@ the steps to create a signature request: field) and calculate system fee using regular rules (that will be `SystemFee` transaction field). Probably, you'll perform one of these actions: 1. If the script is a contract method call, use `invokefunction` RPC API - [func (*Client) InvokeFunction](https://pkg.go.dev/github.com/nspcc-dev/neo-go@v0.97.2/pkg/rpc/client#Client.InvokeFunction) + [func (*Client) InvokeFunction](https://pkg.go.dev/github.com/nspcc-dev/neo-go@v0.97.2/pkg/rpcclient#Client.InvokeFunction) and fetch the script and the gas consumed from the result. 2. If the script is more complicated than just a contract method call, construct the script manually and use `invokescript` RPC API - [func (*Client) InvokeScript](https://pkg.go.dev/github.com/nspcc-dev/neo-go@v0.97.2/pkg/rpc/client#Client.InvokeScript) + [func (*Client) InvokeScript](https://pkg.go.dev/github.com/nspcc-dev/neo-go@v0.97.2/pkg/rpcclient#Client.InvokeScript) to fetch the gas consumed from the result. 3. Or just construct the script and set system fee manually. 3. Calculate the height main transaction is valid until (that will be @@ -361,12 +361,12 @@ the steps to create a signature request: `NotaryAssisted` attribute usage and for notary contract witness verification (that is to be added by the notary node in the end of signature collection process). Use - [func (*Client) CalculateNotaryFee](https://pkg.go.dev/github.com/nspcc-dev/neo-go@v0.97.2/pkg/rpc/client#Client.CalculateNotaryFee) + [func (*Client) CalculateNotaryFee](https://pkg.go.dev/github.com/nspcc-dev/neo-go@v0.97.2/pkg/rpcclient#Client.CalculateNotaryFee) to calculate notary network fee. Use `NKeys` estimated at step 4 as an argument. - *Regular network fee.* That's the amount of GAS to be paid for other witnesses verification. Use - [func (*Client) AddNetworkFee](https://pkg.go.dev/github.com/nspcc-dev/neo-go@v0.97.2/pkg/rpc/client#Client.AddNetworkFee) + [func (*Client) AddNetworkFee](https://pkg.go.dev/github.com/nspcc-dev/neo-go@v0.97.2/pkg/rpcclient#Client.AddNetworkFee) to calculate regular network fee and add it to the transaction. Use partially-filled main transaction from the previous steps as `tx` argument. Use notary network fee calculated at the previous substep as `extraFee` @@ -402,13 +402,13 @@ the steps to create a signature request: tries to push all associated fallbacks. Use the following rules to define `fallbackValidFor`: - `fallbackValidFor` shouldn't be more than `MaxNotValidBeforeDelta` value. - - Use [func (*Client) GetMaxNotValidBeforeDelta](https://pkg.go.dev/github.com/nspcc-dev/neo-go@v0.97.2/pkg/rpc/client#Client.GetMaxNotValidBeforeDelta) + - Use [func (*Client) GetMaxNotValidBeforeDelta](https://pkg.go.dev/github.com/nspcc-dev/neo-go@v0.97.2/pkg/rpcclient#Client.GetMaxNotValidBeforeDelta) to check `MaxNotValidBefore` value. 11. Construct a script for the fallback transaction. The script may do something useful, i.g. invoke method of a contract. However, if you don't need to perform anything special on fallback invocation, you can use simple `opcode.RET` script. 12. Sign and submit P2P notary request. Use - [func (*Client) SignAndPushP2PNotaryRequest](https://pkg.go.dev/github.com/nspcc-dev/neo-go@v0.97.2/pkg/rpc/client#Client.SignAndPushP2PNotaryRequest) for it. + [func (*Client) SignAndPushP2PNotaryRequest](https://pkg.go.dev/github.com/nspcc-dev/neo-go@v0.97.2/pkg/rpcclient#Client.SignAndPushP2PNotaryRequest) for it. - Use the signed main transaction from step 8 as `mainTx` argument. - Use the fallback script from step 10 as `fallbackScript` argument. - Use `-1` as `fallbackSysFee` argument to define system fee by test diff --git a/internal/basicchain/basic.go b/internal/basicchain/basic.go index b617827d3..f0071cfd3 100644 --- a/internal/basicchain/basic.go +++ b/internal/basicchain/basic.go @@ -14,7 +14,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/encoding/fixedn" "github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/neotest" - "github.com/nspcc-dev/neo-go/pkg/rpc/client/nns" + "github.com/nspcc-dev/neo-go/pkg/rpcclient/nns" "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "github.com/nspcc-dev/neo-go/pkg/wallet" diff --git a/pkg/rpc/client/client.go b/pkg/rpcclient/client.go similarity index 99% rename from pkg/rpc/client/client.go rename to pkg/rpcclient/client.go index b511871b7..2f45522d0 100644 --- a/pkg/rpc/client/client.go +++ b/pkg/rpcclient/client.go @@ -1,4 +1,4 @@ -package client +package rpcclient import ( "bytes" diff --git a/pkg/rpc/client/doc.go b/pkg/rpcclient/doc.go similarity index 90% rename from pkg/rpc/client/doc.go rename to pkg/rpcclient/doc.go index e08927fdf..b93f525fc 100644 --- a/pkg/rpc/client/doc.go +++ b/pkg/rpcclient/doc.go @@ -1,6 +1,6 @@ /* -Package client implements NEO-specific JSON-RPC 2.0 client. -This package is currently in alpha and is subject to change. +Package rpcclient implements NEO-specific JSON-RPC 2.0 client. +This package is currently in beta and is subject to change. Client @@ -77,4 +77,4 @@ Unsupported methods sendtoaddress */ -package client +package rpcclient diff --git a/pkg/rpc/client/doc_test.go b/pkg/rpcclient/doc_test.go similarity index 80% rename from pkg/rpc/client/doc_test.go rename to pkg/rpcclient/doc_test.go index cbaa96fc7..d0fbe3e63 100644 --- a/pkg/rpc/client/doc_test.go +++ b/pkg/rpcclient/doc_test.go @@ -1,4 +1,4 @@ -package client_test +package rpcclient_test import ( "context" @@ -6,14 +6,14 @@ import ( "os" "github.com/nspcc-dev/neo-go/pkg/encoding/address" - "github.com/nspcc-dev/neo-go/pkg/rpc/client" + "github.com/nspcc-dev/neo-go/pkg/rpcclient" ) func Example() { endpoint := "http://seed5.bridgeprotocol.io:10332" - opts := client.Options{} + opts := rpcclient.Options{} - c, err := client.New(context.TODO(), endpoint, opts) + c, err := rpcclient.New(context.TODO(), endpoint, opts) if err != nil { fmt.Println(err) os.Exit(1) diff --git a/pkg/rpc/client/helper.go b/pkg/rpcclient/helper.go similarity index 99% rename from pkg/rpc/client/helper.go rename to pkg/rpcclient/helper.go index 73695ee24..a46f99d98 100644 --- a/pkg/rpc/client/helper.go +++ b/pkg/rpcclient/helper.go @@ -1,4 +1,4 @@ -package client +package rpcclient import ( "crypto/elliptic" @@ -10,7 +10,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/io" - "github.com/nspcc-dev/neo-go/pkg/rpc/client/nns" + "github.com/nspcc-dev/neo-go/pkg/rpcclient/nns" "github.com/nspcc-dev/neo-go/pkg/rpc/response/result" "github.com/nspcc-dev/neo-go/pkg/smartcontract" "github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag" diff --git a/pkg/rpc/client/native.go b/pkg/rpcclient/native.go similarity index 98% rename from pkg/rpc/client/native.go rename to pkg/rpcclient/native.go index d8471a6ce..f5cc6bd16 100644 --- a/pkg/rpc/client/native.go +++ b/pkg/rpcclient/native.go @@ -1,4 +1,4 @@ -package client +package rpcclient // Various non-policy things from native contracts. @@ -11,7 +11,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/core/native/nativenames" "github.com/nspcc-dev/neo-go/pkg/core/native/noderoles" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" - "github.com/nspcc-dev/neo-go/pkg/rpc/client/nns" + "github.com/nspcc-dev/neo-go/pkg/rpcclient/nns" "github.com/nspcc-dev/neo-go/pkg/rpc/response/result" "github.com/nspcc-dev/neo-go/pkg/smartcontract" "github.com/nspcc-dev/neo-go/pkg/util" diff --git a/pkg/rpc/client/nep.go b/pkg/rpcclient/nep.go similarity index 99% rename from pkg/rpc/client/nep.go rename to pkg/rpcclient/nep.go index 3afc79bd2..e761e0352 100644 --- a/pkg/rpc/client/nep.go +++ b/pkg/rpcclient/nep.go @@ -1,4 +1,4 @@ -package client +package rpcclient import ( "fmt" diff --git a/pkg/rpc/client/nep11.go b/pkg/rpcclient/nep11.go similarity index 99% rename from pkg/rpc/client/nep11.go rename to pkg/rpcclient/nep11.go index 6522d3b02..124a49546 100644 --- a/pkg/rpc/client/nep11.go +++ b/pkg/rpcclient/nep11.go @@ -1,4 +1,4 @@ -package client +package rpcclient import ( "fmt" diff --git a/pkg/rpc/client/nep17.go b/pkg/rpcclient/nep17.go similarity index 99% rename from pkg/rpc/client/nep17.go rename to pkg/rpcclient/nep17.go index 3f23a1378..acdff51eb 100644 --- a/pkg/rpc/client/nep17.go +++ b/pkg/rpcclient/nep17.go @@ -1,4 +1,4 @@ -package client +package rpcclient import ( "fmt" diff --git a/pkg/rpc/client/nns/record.go b/pkg/rpcclient/nns/record.go similarity index 100% rename from pkg/rpc/client/nns/record.go rename to pkg/rpcclient/nns/record.go diff --git a/pkg/rpc/client/policy.go b/pkg/rpcclient/policy.go similarity index 99% rename from pkg/rpc/client/policy.go rename to pkg/rpcclient/policy.go index 8fe8f0a2b..481848526 100644 --- a/pkg/rpc/client/policy.go +++ b/pkg/rpcclient/policy.go @@ -1,4 +1,4 @@ -package client +package rpcclient import ( "fmt" diff --git a/pkg/rpc/client/rpc.go b/pkg/rpcclient/rpc.go similarity index 99% rename from pkg/rpc/client/rpc.go rename to pkg/rpcclient/rpc.go index 9cdd148b7..a165d40a7 100644 --- a/pkg/rpc/client/rpc.go +++ b/pkg/rpcclient/rpc.go @@ -1,4 +1,4 @@ -package client +package rpcclient import ( "encoding/base64" diff --git a/pkg/rpc/client/rpc_test.go b/pkg/rpcclient/rpc_test.go similarity index 99% rename from pkg/rpc/client/rpc_test.go rename to pkg/rpcclient/rpc_test.go index ae1f89863..183fcbf9e 100644 --- a/pkg/rpc/client/rpc_test.go +++ b/pkg/rpcclient/rpc_test.go @@ -1,4 +1,4 @@ -package client +package rpcclient import ( "context" diff --git a/pkg/rpc/client/wsclient.go b/pkg/rpcclient/wsclient.go similarity index 99% rename from pkg/rpc/client/wsclient.go rename to pkg/rpcclient/wsclient.go index d98c5093b..758816946 100644 --- a/pkg/rpc/client/wsclient.go +++ b/pkg/rpcclient/wsclient.go @@ -1,4 +1,4 @@ -package client +package rpcclient import ( "context" diff --git a/pkg/rpc/client/wsclient_test.go b/pkg/rpcclient/wsclient_test.go similarity index 99% rename from pkg/rpc/client/wsclient_test.go rename to pkg/rpcclient/wsclient_test.go index 2b6bde70f..7dcd1ee5a 100644 --- a/pkg/rpc/client/wsclient_test.go +++ b/pkg/rpcclient/wsclient_test.go @@ -1,4 +1,4 @@ -package client +package rpcclient import ( "context" diff --git a/pkg/services/helpers/rpcbroadcaster/client.go b/pkg/services/helpers/rpcbroadcaster/client.go index ca45d7135..43c4e97c2 100644 --- a/pkg/services/helpers/rpcbroadcaster/client.go +++ b/pkg/services/helpers/rpcbroadcaster/client.go @@ -4,13 +4,13 @@ import ( "context" "time" - "github.com/nspcc-dev/neo-go/pkg/rpc/client" + "github.com/nspcc-dev/neo-go/pkg/rpcclient" "go.uber.org/zap" ) // RPCClient represent an rpc client for a single node. type RPCClient struct { - client *client.Client + client *rpcclient.Client addr string close chan struct{} finished chan struct{} @@ -21,7 +21,7 @@ type RPCClient struct { } // SendMethod represents an rpc method for sending data to other nodes. -type SendMethod func(*client.Client, []interface{}) error +type SendMethod func(*rpcclient.Client, []interface{}) 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 { @@ -38,7 +38,7 @@ func (r *RPCBroadcaster) NewRPCClient(addr string, method SendMethod, timeout ti func (c *RPCClient) run() { // We ignore error as not every node can be available on startup. - c.client, _ = client.New(context.Background(), c.addr, client.Options{ + c.client, _ = rpcclient.New(context.Background(), c.addr, rpcclient.Options{ DialTimeout: c.sendTimeout, RequestTimeout: c.sendTimeout, }) @@ -50,7 +50,7 @@ run: case ps := <-c.responses: if c.client == nil { var err error - c.client, err = client.New(context.Background(), c.addr, client.Options{ + c.client, err = rpcclient.New(context.Background(), c.addr, rpcclient.Options{ DialTimeout: c.sendTimeout, RequestTimeout: c.sendTimeout, }) diff --git a/pkg/services/oracle/broadcaster/oracle.go b/pkg/services/oracle/broadcaster/oracle.go index 9fc2627e2..b14b09e5c 100644 --- a/pkg/services/oracle/broadcaster/oracle.go +++ b/pkg/services/oracle/broadcaster/oracle.go @@ -8,7 +8,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/config" "github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" - "github.com/nspcc-dev/neo-go/pkg/rpc/client" + "github.com/nspcc-dev/neo-go/pkg/rpcclient" "github.com/nspcc-dev/neo-go/pkg/services/helpers/rpcbroadcaster" "github.com/nspcc-dev/neo-go/pkg/services/oracle" "go.uber.org/zap" @@ -33,7 +33,7 @@ func New(cfg config.OracleConfiguration, log *zap.Logger) oracle.Broadcaster { RPCBroadcaster: *rpcbroadcaster.NewRPCBroadcaster(log, cfg.ResponseTimeout), } for i := range cfg.Nodes { - r.Clients[cfg.Nodes[i]] = r.NewRPCClient(cfg.Nodes[i], (*client.Client).SubmitRawOracleResponse, + r.Clients[cfg.Nodes[i]] = r.NewRPCClient(cfg.Nodes[i], (*rpcclient.Client).SubmitRawOracleResponse, cfg.ResponseTimeout, make(chan []interface{}, defaultChanCapacity)) } return r diff --git a/pkg/services/rpcsrv/client_test.go b/pkg/services/rpcsrv/client_test.go index 33f672cff..1e79df772 100644 --- a/pkg/services/rpcsrv/client_test.go +++ b/pkg/services/rpcsrv/client_test.go @@ -27,9 +27,9 @@ import ( "github.com/nspcc-dev/neo-go/pkg/encoding/address" "github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/network" - "github.com/nspcc-dev/neo-go/pkg/rpc/client" - "github.com/nspcc-dev/neo-go/pkg/rpc/client/nns" "github.com/nspcc-dev/neo-go/pkg/rpc/response/result" + "github.com/nspcc-dev/neo-go/pkg/rpcclient" + "github.com/nspcc-dev/neo-go/pkg/rpcclient/nns" "github.com/nspcc-dev/neo-go/pkg/smartcontract" "github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag" "github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest" @@ -48,7 +48,7 @@ func TestClient_NEP17(t *testing.T) { defer chain.Close() defer rpcSrv.Shutdown() - c, err := client.New(context.Background(), httpSrv.URL, client.Options{}) + c, err := rpcclient.New(context.Background(), httpSrv.URL, rpcclient.Options{}) require.NoError(t, err) require.NoError(t, c.Init()) @@ -93,7 +93,7 @@ func TestAddNetworkFeeCalculateNetworkFee(t *testing.T) { const extraFee = 10 var nonce uint32 - c, err := client.New(context.Background(), httpSrv.URL, client.Options{}) + c, err := rpcclient.New(context.Background(), httpSrv.URL, rpcclient.Options{}) require.NoError(t, err) require.NoError(t, c.Init()) @@ -341,7 +341,7 @@ func TestCalculateNetworkFee(t *testing.T) { defer rpcSrv.Shutdown() const extraFee = 10 - c, err := client.New(context.Background(), httpSrv.URL, client.Options{}) + c, err := rpcclient.New(context.Background(), httpSrv.URL, rpcclient.Options{}) require.NoError(t, err) require.NoError(t, c.Init()) @@ -410,7 +410,7 @@ func TestSignAndPushInvocationTx(t *testing.T) { defer chain.Close() defer rpcSrv.Shutdown() - c, err := client.New(context.Background(), httpSrv.URL, client.Options{}) + c, err := rpcclient.New(context.Background(), httpSrv.URL, rpcclient.Options{}) require.NoError(t, err) require.NoError(t, c.Init()) @@ -458,7 +458,7 @@ func TestSignAndPushInvocationTx(t *testing.T) { t.Run("good", func(t *testing.T) { t.Run("signer0: sig", func(t *testing.T) { - h, err := c.SignAndPushInvocationTx([]byte{byte(opcode.PUSH1)}, acc0, 30, 0, []client.SignerAccount{ + h, err := c.SignAndPushInvocationTx([]byte{byte(opcode.PUSH1)}, acc0, 30, 0, []rpcclient.SignerAccount{ { Signer: transaction.Signer{ Account: priv0.GetScriptHash(), @@ -471,7 +471,7 @@ func TestSignAndPushInvocationTx(t *testing.T) { check(t, h) }) t.Run("signer0: sig; signer1: sig", func(t *testing.T) { - h, err := c.SignAndPushInvocationTx([]byte{byte(opcode.PUSH1)}, acc0, 30, 0, []client.SignerAccount{ + h, err := c.SignAndPushInvocationTx([]byte{byte(opcode.PUSH1)}, acc0, 30, 0, []rpcclient.SignerAccount{ { Signer: transaction.Signer{ Account: priv0.GetScriptHash(), @@ -491,7 +491,7 @@ func TestSignAndPushInvocationTx(t *testing.T) { check(t, h) }) t.Run("signer0: sig; signer1: contract-based paramless", func(t *testing.T) { - h, err := c.SignAndPushInvocationTx([]byte{byte(opcode.PUSH1)}, acc0, 30, 0, []client.SignerAccount{ + h, err := c.SignAndPushInvocationTx([]byte{byte(opcode.PUSH1)}, acc0, 30, 0, []rpcclient.SignerAccount{ { Signer: transaction.Signer{ Account: priv0.GetScriptHash(), @@ -513,7 +513,7 @@ func TestSignAndPushInvocationTx(t *testing.T) { }) t.Run("error", func(t *testing.T) { t.Run("signer0: sig; signer1: contract-based with params", func(t *testing.T) { - _, err := c.SignAndPushInvocationTx([]byte{byte(opcode.PUSH1)}, acc0, 30, 0, []client.SignerAccount{ + _, err := c.SignAndPushInvocationTx([]byte{byte(opcode.PUSH1)}, acc0, 30, 0, []rpcclient.SignerAccount{ { Signer: transaction.Signer{ Account: priv0.GetScriptHash(), @@ -541,7 +541,7 @@ func TestSignAndPushInvocationTx(t *testing.T) { Parameters: []wallet.ContractParam{{Name: "parameter0", Type: smartcontract.SignatureType}}, }, } - _, err = c.SignAndPushInvocationTx([]byte{byte(opcode.PUSH1)}, acc0, 30, 0, []client.SignerAccount{ + _, err = c.SignAndPushInvocationTx([]byte{byte(opcode.PUSH1)}, acc0, 30, 0, []rpcclient.SignerAccount{ { Signer: transaction.Signer{ Account: priv0.GetScriptHash(), @@ -567,7 +567,7 @@ func TestSignAndPushP2PNotaryRequest(t *testing.T) { defer chain.Close() defer rpcSrv.Shutdown() - c, err := client.New(context.Background(), httpSrv.URL, client.Options{}) + c, err := rpcclient.New(context.Background(), httpSrv.URL, rpcclient.Options{}) require.NoError(t, err) acc, err := wallet.NewAccount() require.NoError(t, err) @@ -658,7 +658,7 @@ func TestCalculateNotaryFee(t *testing.T) { defer chain.Close() defer rpcSrv.Shutdown() - c, err := client.New(context.Background(), httpSrv.URL, client.Options{}) + c, err := rpcclient.New(context.Background(), httpSrv.URL, rpcclient.Options{}) require.NoError(t, err) t.Run("client not initialized", func(t *testing.T) { @@ -671,7 +671,7 @@ func TestPing(t *testing.T) { chain, rpcSrv, httpSrv := initServerWithInMemoryChain(t) defer chain.Close() - c, err := client.New(context.Background(), httpSrv.URL, client.Options{}) + c, err := rpcclient.New(context.Background(), httpSrv.URL, rpcclient.Options{}) require.NoError(t, err) require.NoError(t, c.Init()) @@ -686,7 +686,7 @@ func TestCreateTxFromScript(t *testing.T) { defer chain.Close() defer rpcSrv.Shutdown() - c, err := client.New(context.Background(), httpSrv.URL, client.Options{}) + c, err := rpcclient.New(context.Background(), httpSrv.URL, rpcclient.Options{}) require.NoError(t, err) require.NoError(t, c.Init()) @@ -715,7 +715,7 @@ func TestCreateNEP17TransferTx(t *testing.T) { defer chain.Close() defer rpcSrv.Shutdown() - c, err := client.New(context.Background(), httpSrv.URL, client.Options{}) + c, err := rpcclient.New(context.Background(), httpSrv.URL, rpcclient.Options{}) require.NoError(t, err) require.NoError(t, c.Init()) @@ -735,7 +735,7 @@ func TestCreateNEP17TransferTx(t *testing.T) { require.NoError(t, ic.VM.Run()) }) t.Run("none scope", func(t *testing.T) { - _, err := c.CreateNEP17TransferTx(acc, util.Uint160{}, gasContractHash, 1000, 0, nil, []client.SignerAccount{{ + _, err := c.CreateNEP17TransferTx(acc, util.Uint160{}, gasContractHash, 1000, 0, nil, []rpcclient.SignerAccount{{ Signer: transaction.Signer{ Account: priv.PublicKey().GetScriptHash(), Scopes: transaction.None, @@ -744,7 +744,7 @@ func TestCreateNEP17TransferTx(t *testing.T) { require.Error(t, err) }) t.Run("customcontracts scope", func(t *testing.T) { - tx, err := c.CreateNEP17TransferTx(acc, util.Uint160{}, gasContractHash, 1000, 0, nil, []client.SignerAccount{{ + tx, err := c.CreateNEP17TransferTx(acc, util.Uint160{}, gasContractHash, 1000, 0, nil, []rpcclient.SignerAccount{{ Signer: transaction.Signer{ Account: priv.PublicKey().GetScriptHash(), Scopes: transaction.CustomContracts, @@ -765,7 +765,7 @@ func TestInvokeVerify(t *testing.T) { defer chain.Close() defer rpcSrv.Shutdown() - c, err := client.New(context.Background(), httpSrv.URL, client.Options{}) + c, err := rpcclient.New(context.Background(), httpSrv.URL, rpcclient.Options{}) require.NoError(t, err) require.NoError(t, c.Init()) @@ -857,7 +857,7 @@ func TestClient_GetNativeContracts(t *testing.T) { defer chain.Close() defer rpcSrv.Shutdown() - c, err := client.New(context.Background(), httpSrv.URL, client.Options{}) + c, err := rpcclient.New(context.Background(), httpSrv.URL, rpcclient.Options{}) require.NoError(t, err) require.NoError(t, c.Init()) @@ -871,7 +871,7 @@ func TestClient_NEP11_ND(t *testing.T) { defer chain.Close() defer rpcSrv.Shutdown() - c, err := client.New(context.Background(), httpSrv.URL, client.Options{}) + c, err := rpcclient.New(context.Background(), httpSrv.URL, rpcclient.Options{}) require.NoError(t, err) require.NoError(t, c.Init()) @@ -937,7 +937,7 @@ func TestClient_NEP11_D(t *testing.T) { defer chain.Close() defer rpcSrv.Shutdown() - c, err := client.New(context.Background(), httpSrv.URL, client.Options{}) + c, err := rpcclient.New(context.Background(), httpSrv.URL, rpcclient.Options{}) require.NoError(t, err) require.NoError(t, c.Init()) @@ -1016,7 +1016,7 @@ func TestClient_NNS(t *testing.T) { defer chain.Close() defer rpcSrv.Shutdown() - c, err := client.New(context.Background(), httpSrv.URL, client.Options{}) + c, err := rpcclient.New(context.Background(), httpSrv.URL, rpcclient.Options{}) require.NoError(t, err) require.NoError(t, c.Init()) @@ -1088,7 +1088,7 @@ func TestClient_IteratorSessions(t *testing.T) { defer chain.Close() defer rpcSrv.Shutdown() - c, err := client.New(context.Background(), httpSrv.URL, client.Options{}) + c, err := rpcclient.New(context.Background(), httpSrv.URL, rpcclient.Options{}) require.NoError(t, err) require.NoError(t, c.Init()) @@ -1230,7 +1230,7 @@ func TestClient_GetNotaryServiceFeePerKey(t *testing.T) { defer chain.Close() defer rpcSrv.Shutdown() - c, err := client.New(context.Background(), httpSrv.URL, client.Options{}) + c, err := rpcclient.New(context.Background(), httpSrv.URL, rpcclient.Options{}) require.NoError(t, err) require.NoError(t, c.Init()) @@ -1245,7 +1245,7 @@ func TestClient_GetOraclePrice(t *testing.T) { defer chain.Close() defer rpcSrv.Shutdown() - c, err := client.New(context.Background(), httpSrv.URL, client.Options{}) + c, err := rpcclient.New(context.Background(), httpSrv.URL, rpcclient.Options{}) require.NoError(t, err) require.NoError(t, c.Init()) @@ -1260,7 +1260,7 @@ func TestClient_InvokeAndPackIteratorResults(t *testing.T) { defer chain.Close() defer rpcSrv.Shutdown() - c, err := client.New(context.Background(), httpSrv.URL, client.Options{}) + c, err := rpcclient.New(context.Background(), httpSrv.URL, rpcclient.Options{}) require.NoError(t, err) require.NoError(t, c.Init()) @@ -1319,7 +1319,7 @@ func TestClient_Iterator_SessionConfigVariations(t *testing.T) { // storageItemsCount is the amount of storage items stored in Storage contract, it's hard-coded in the contract code. const storageItemsCount = 255 - checkSessionEnabled := func(t *testing.T, c *client.Client) { + checkSessionEnabled := func(t *testing.T, c *rpcclient.Client) { // We expect Iterator with designated ID to be presented on stack. It should be possible to retrieve its values via `traverseiterator` call. res, err := c.InvokeFunction(storageHash, "iterateOverValues", []smartcontract.Parameter{}, nil) require.NoError(t, err) @@ -1347,7 +1347,7 @@ func TestClient_Iterator_SessionConfigVariations(t *testing.T) { require.NoError(t, chain.AddBlock(b)) } - c, err := client.New(context.Background(), httpSrv.URL, client.Options{}) + c, err := rpcclient.New(context.Background(), httpSrv.URL, rpcclient.Options{}) require.NoError(t, err) require.NoError(t, c.Init()) @@ -1386,7 +1386,7 @@ func TestClient_Iterator_SessionConfigVariations(t *testing.T) { require.NoError(t, chain.AddBlock(b)) } - c, err := client.New(context.Background(), httpSrv.URL, client.Options{}) + c, err := rpcclient.New(context.Background(), httpSrv.URL, rpcclient.Options{}) require.NoError(t, err) require.NoError(t, c.Init()) @@ -1400,7 +1400,7 @@ func TestClient_Iterator_SessionConfigVariations(t *testing.T) { require.NoError(t, chain.AddBlock(b)) } - c, err := client.New(context.Background(), httpSrv.URL, client.Options{}) + c, err := rpcclient.New(context.Background(), httpSrv.URL, rpcclient.Options{}) require.NoError(t, err) require.NoError(t, c.Init()) diff --git a/scripts/compare-states/compare-states.go b/scripts/compare-states/compare-states.go index 5a5497f51..7e0e6ad7a 100644 --- a/scripts/compare-states/compare-states.go +++ b/scripts/compare-states/compare-states.go @@ -7,7 +7,7 @@ import ( "os" "github.com/davecgh/go-spew/spew" - "github.com/nspcc-dev/neo-go/pkg/rpc/client" + "github.com/nspcc-dev/neo-go/pkg/rpcclient" "github.com/nspcc-dev/neo-go/pkg/util" "github.com/pmezard/go-difflib/difflib" "github.com/urfave/cli" @@ -15,8 +15,8 @@ import ( var errStateMatches = errors.New("state matches") -func initClient(addr string, name string) (*client.Client, uint32, error) { - c, err := client.New(context.Background(), addr, client.Options{}) +func initClient(addr string, name string) (*rpcclient.Client, uint32, error) { + c, err := rpcclient.New(context.Background(), addr, rpcclient.Options{}) if err != nil { return nil, 0, fmt.Errorf("RPC %s: %w", name, err) } @@ -31,7 +31,7 @@ func initClient(addr string, name string) (*client.Client, uint32, error) { return c, h, nil } -func getRoots(ca *client.Client, cb *client.Client, h uint32) (util.Uint256, util.Uint256, error) { +func getRoots(ca *rpcclient.Client, cb *rpcclient.Client, h uint32) (util.Uint256, util.Uint256, error) { ra, err := ca.GetStateRootByHeight(h) if err != nil { return util.Uint256{}, util.Uint256{}, fmt.Errorf("getstateroot from A for %d: %w", h, err) @@ -43,7 +43,7 @@ func getRoots(ca *client.Client, cb *client.Client, h uint32) (util.Uint256, uti return ra.Root, rb.Root, nil } -func bisectState(ca *client.Client, cb *client.Client, h uint32) (uint32, error) { +func bisectState(ca *rpcclient.Client, cb *rpcclient.Client, h uint32) (uint32, error) { ra, rb, err := getRoots(ca, cb, 0) if err != nil { return 0, err