Documentation ¶
Overview ¶
Package rpcclient implements NEO-specific JSON-RPC 2.0 client.
This package itself is designed to be a thin layer on top of the regular JSON-RPC interface provided by Neo implementations. Therefore the set of methods provided by clients is exactly the same as available from servers and they use data types that directly correspond to JSON data exchanged. While this is the most powerful and direct interface, it at the same time is not very convenient for many purposes, like the most popular one --- performing test invocations and creating/sending transactions that will do something to the chain. Please check subpackages for more convenient APIs.
Subpackages ¶
The overall structure can be seen as a number of layers built on top of rpcclient and on top of each other with each package and each layer solving different problems.
These layers are:
Basic RPC API, rpcclient package itself.
Generic invocation/transaction API represented by invoker, unwrap (auxiliary, but very convenient) and actor packages. These allow to perform test invocations with plain Go types, use historic states for these invocations, get the execution results from reader functions and create/send transactions that change something on-chain.
Standard-specific wrappers that are implemented in nep11 and nep17 packages (with common methods in neptoken). They implement the respective NEP-11 and NEP-17 APIs both for safe (read-only) and state-changing methods. Safe methods require an Invoker to be called, while Actor is used to create/send transactions.
Contract-specific wrappers for native contracts that include management, gas, neo, oracle, policy and rolemgmt packages for the respective native contracts. Complete contract functionality is exposed (reusing nep17 package for gas and neo).
Notary actor and contract, a bit special since it's a NeoGo protocol extension, but notary package provides both the notary native contract wrapper and a notary-specific actor implementation that allows to easily wrap any transaction into a notary request.
Non-native contract-specific wrappers, currently partially provided only for NNS contract (it's still in development), at the moment that's mostly an example of how contract-specific wrappers can be built for other dApps (reusing invoker/actor layers it's pretty easy).
Client ¶
After creating a client instance with or without a ClientConfig you can interact with the NEO blockchain by its exposed methods.
Supported methods
calculatenetworkfee findstates getapplicationlog getbestblockhash getblock getblockcount getblockhash getblockheader getblockheadercount getcommittee getconnectioncount getcontractstate getnativecontracts getnep11balances getnep11properties getnep11transfers getnep17balances getnep17transfers getpeers getrawmempool getrawtransaction getstate getstateheight getstateroot getstorage gettransactionheight getunclaimedgas getnextblockvalidators getversion invokefunction invokescript invokecontractverify sendrawtransaction submitblock submitoracleresponse terminatesession traverseiterator validateaddress
Extensions:
getblocksysfee submitnotaryrequest
Unsupported methods
claimgas dumpprivkey getbalance getmetricblocktimestamp getnewaddress getwalletheight importprivkey listaddress listplugins sendfrom sendmany sendtoaddress
Example ¶
package main import ( "context" "fmt" "os" "github.com/nspcc-dev/neo-go/pkg/encoding/address" "github.com/nspcc-dev/neo-go/pkg/rpcclient" ) func main() { endpoint := "http://seed5.bridgeprotocol.io:10332" opts := rpcclient.Options{} c, err := rpcclient.New(context.TODO(), endpoint, opts) if err != nil { fmt.Println(err) os.Exit(1) } err = c.Init() if err != nil { fmt.Println(err) os.Exit(1) } if err := c.Ping(); err != nil { fmt.Println(err) os.Exit(1) } addr, err := address.StringToUint160("ATySFJAbLW7QHsZGHScLhxq6EyNBxx3eFP") if err != nil { fmt.Println(err) os.Exit(1) } resp, err := c.GetNEP17Balances(addr) if err != nil { fmt.Println(err) os.Exit(1) } fmt.Println(resp.Address) fmt.Println(resp.Balances) }
Output:
Index ¶
- Variables
- type Client
- func (c *Client) AddNetworkFee(tx *transaction.Transaction, extraFee int64, accs ...*wallet.Account) errordeprecated
- func (c *Client) CalculateNetworkFee(tx *transaction.Transaction) (int64, error)
- func (c *Client) CalculateNotaryFee(nKeys uint8) (int64, error)deprecated
- func (c *Client) CalculateValidUntilBlock() (uint32, error)deprecated
- func (c *Client) Close()
- func (c *Client) Context() context.Context
- func (c *Client) CreateNEP11TransferTx(acc *wallet.Account, tokenHash util.Uint160, gas int64, ...) (*transaction.Transaction, error)deprecated
- func (c *Client) CreateNEP17MultiTransferTx(acc *wallet.Account, gas int64, recipients []TransferTarget, ...) (*transaction.Transaction, error)deprecated
- func (c *Client) CreateNEP17TransferTx(acc *wallet.Account, to util.Uint160, token util.Uint160, amount int64, ...) (*transaction.Transaction, error)deprecated
- func (c *Client) CreateTxFromScript(script []byte, acc *wallet.Account, sysFee, netFee int64, ...) (*transaction.Transaction, error)deprecated
- func (c *Client) Endpoint() string
- func (c *Client) FindStates(stateroot util.Uint256, historicalContractHash util.Uint160, ...) (result.FindStates, error)
- func (c *Client) GetApplicationLog(hash util.Uint256, trig *trigger.Type) (*result.ApplicationLog, error)
- func (c *Client) GetBestBlockHash() (util.Uint256, error)
- func (c *Client) GetBlockByHash(hash util.Uint256) (*block.Block, error)
- func (c *Client) GetBlockByHashVerbose(hash util.Uint256) (*result.Block, error)
- func (c *Client) GetBlockByIndex(index uint32) (*block.Block, error)
- func (c *Client) GetBlockByIndexVerbose(index uint32) (*result.Block, error)
- func (c *Client) GetBlockCount() (uint32, error)
- func (c *Client) GetBlockHash(index uint32) (util.Uint256, error)
- func (c *Client) GetBlockHeader(hash util.Uint256) (*block.Header, error)
- func (c *Client) GetBlockHeaderCount() (uint32, error)
- func (c *Client) GetBlockHeaderVerbose(hash util.Uint256) (*result.Header, error)
- func (c *Client) GetBlockSysFee(index uint32) (fixedn.Fixed8, error)
- func (c *Client) GetCandidateRegisterPrice() (int64, error)deprecated
- func (c *Client) GetCandidates() ([]result.Candidate, error)
- func (c *Client) GetCommittee() (keys.PublicKeys, error)
- func (c *Client) GetConnectionCount() (int, error)
- func (c *Client) GetContractStateByAddressOrName(addressOrName string) (*state.Contract, error)
- func (c *Client) GetContractStateByHash(hash util.Uint160) (*state.Contract, error)
- func (c *Client) GetContractStateByID(id int32) (*state.Contract, error)
- func (c *Client) GetDesignatedByRole(role noderoles.Role, index uint32) (keys.PublicKeys, error)deprecated
- func (c *Client) GetExecFeeFactor() (int64, error)deprecated
- func (c *Client) GetFeePerByte() (int64, error)deprecated
- func (c *Client) GetGasPerBlock() (int64, error)deprecated
- func (c *Client) GetMaxNotValidBeforeDelta() (int64, error)deprecated
- func (c *Client) GetNEP11Balances(address util.Uint160) (*result.NEP11Balances, error)
- func (c *Client) GetNEP11Properties(asset util.Uint160, token []byte) (map[string]interface{}, error)
- func (c *Client) GetNEP11Transfers(address util.Uint160, start, stop *uint64, limit, page *int) (*result.NEP11Transfers, error)
- func (c *Client) GetNEP17Balances(address util.Uint160) (*result.NEP17Balances, error)
- func (c *Client) GetNEP17Transfers(address util.Uint160, start, stop *uint64, limit, page *int) (*result.NEP17Transfers, error)
- func (c *Client) GetNNSPrice(nnsHash util.Uint160) (int64, error)deprecated
- func (c *Client) GetNativeContractHash(name string) (util.Uint160, error)deprecated
- func (c *Client) GetNativeContracts() ([]state.NativeContract, error)
- func (c *Client) GetNetwork() (netmode.Magic, error)deprecated
- func (c *Client) GetNextBlockValidators() ([]result.Validator, error)
- func (c *Client) GetNotaryServiceFeePerKey() (int64, error)deprecated
- func (c *Client) GetOraclePrice() (int64, error)deprecated
- func (c *Client) GetPeers() (*result.GetPeers, error)
- func (c *Client) GetRawMemPool() ([]util.Uint256, error)
- func (c *Client) GetRawTransaction(hash util.Uint256) (*transaction.Transaction, error)
- func (c *Client) GetRawTransactionVerbose(hash util.Uint256) (*result.TransactionOutputRaw, error)
- func (c *Client) GetState(stateroot util.Uint256, historicalContractHash util.Uint160, ...) ([]byte, error)
- func (c *Client) GetStateHeight() (*result.StateHeight, error)
- func (c *Client) GetStateRootByBlockHash(hash util.Uint256) (*state.MPTRoot, error)
- func (c *Client) GetStateRootByHeight(height uint32) (*state.MPTRoot, error)
- func (c *Client) GetStorageByHash(hash util.Uint160, key []byte) ([]byte, error)
- func (c *Client) GetStorageByID(id int32, key []byte) ([]byte, error)
- func (c *Client) GetStoragePrice() (int64, error)deprecated
- func (c *Client) GetTransactionHeight(hash util.Uint256) (uint32, error)
- func (c *Client) GetUnclaimedGas(address string) (result.UnclaimedGas, error)
- func (c *Client) GetVersion() (*result.Version, error)
- func (c *Client) Init() error
- func (c *Client) InvokeAndPackIteratorResults(contract util.Uint160, operation string, params []smartcontract.Parameter, ...) (*result.Invoke, error)deprecated
- func (c *Client) InvokeContractVerify(contract util.Uint160, params []smartcontract.Parameter, ...) (*result.Invoke, error)
- func (c *Client) InvokeContractVerifyAtHeight(height uint32, contract util.Uint160, params []smartcontract.Parameter, ...) (*result.Invoke, error)
- func (c *Client) InvokeContractVerifyWithState(stateOrBlock util.Uint256, contract util.Uint160, ...) (*result.Invoke, error)
- func (c *Client) InvokeFunction(contract util.Uint160, operation string, params []smartcontract.Parameter, ...) (*result.Invoke, error)
- func (c *Client) InvokeFunctionAtHeight(height uint32, contract util.Uint160, operation string, ...) (*result.Invoke, error)
- func (c *Client) InvokeFunctionWithState(stateOrBlock util.Uint256, contract util.Uint160, operation string, ...) (*result.Invoke, error)
- func (c *Client) InvokeScript(script []byte, signers []transaction.Signer) (*result.Invoke, error)
- func (c *Client) InvokeScriptAtHeight(height uint32, script []byte, signers []transaction.Signer) (*result.Invoke, error)
- func (c *Client) InvokeScriptWithState(stateOrBlock util.Uint256, script []byte, signers []transaction.Signer) (*result.Invoke, error)
- func (c *Client) IsBlocked(hash util.Uint160) (bool, error)deprecated
- func (c *Client) MultiTransferNEP17(acc *wallet.Account, gas int64, recipients []TransferTarget, ...) (util.Uint256, error)deprecated
- func (c *Client) NEP11BalanceOf(tokenHash, owner util.Uint160) (int64, error)deprecated
- func (c *Client) NEP11DBalanceOf(tokenHash, owner util.Uint160, tokenID []byte) (int64, error)deprecated
- func (c *Client) NEP11DOwnerOf(tokenHash util.Uint160, tokenID []byte) (uuid.UUID, result.Iterator, error)deprecated
- func (c *Client) NEP11DUnpackedOwnerOf(tokenHash util.Uint160, tokenID []byte) ([]util.Uint160, error)deprecated
- func (c *Client) NEP11Decimals(tokenHash util.Uint160) (int64, error)deprecated
- func (c *Client) NEP11NDOwnerOf(tokenHash util.Uint160, tokenID []byte) (util.Uint160, error)deprecated
- func (c *Client) NEP11Properties(tokenHash util.Uint160, tokenID []byte) (*stackitem.Map, error)deprecated
- func (c *Client) NEP11Symbol(tokenHash util.Uint160) (string, error)deprecated
- func (c *Client) NEP11TokenInfo(tokenHash util.Uint160) (*wallet.Token, error)deprecated
- func (c *Client) NEP11Tokens(tokenHash util.Uint160) (uuid.UUID, result.Iterator, error)deprecated
- func (c *Client) NEP11TokensOf(tokenHash util.Uint160, owner util.Uint160) (uuid.UUID, result.Iterator, error)deprecated
- func (c *Client) NEP11TotalSupply(tokenHash util.Uint160) (int64, error)deprecated
- func (c *Client) NEP11UnpackedTokens(tokenHash util.Uint160) ([][]byte, error)deprecated
- func (c *Client) NEP11UnpackedTokensOf(tokenHash util.Uint160, owner util.Uint160) ([][]byte, error)deprecated
- func (c *Client) NEP17BalanceOf(tokenHash, acc util.Uint160) (int64, error)deprecated
- func (c *Client) NEP17Decimals(tokenHash util.Uint160) (int64, error)deprecated
- func (c *Client) NEP17Symbol(tokenHash util.Uint160) (string, error)deprecated
- func (c *Client) NEP17TokenInfo(tokenHash util.Uint160) (*wallet.Token, error)deprecated
- func (c *Client) NEP17TotalSupply(tokenHash util.Uint160) (int64, error)deprecated
- func (c *Client) NNSGetAllRecords(nnsHash util.Uint160, name string) (uuid.UUID, result.Iterator, error)deprecated
- func (c *Client) NNSIsAvailable(nnsHash util.Uint160, name string) (bool, error)deprecated
- func (c *Client) NNSResolve(nnsHash util.Uint160, name string, typ nns.RecordType) (string, error)deprecated
- func (c *Client) NNSUnpackedGetAllRecords(nnsHash util.Uint160, name string) ([]nns.RecordState, error)deprecated
- func (c *Client) Ping() error
- func (c *Client) SendRawTransaction(rawTX *transaction.Transaction) (util.Uint256, error)
- func (c *Client) SignAndPushInvocationTx(script []byte, acc *wallet.Account, sysfee int64, netfee fixedn.Fixed8, ...) (util.Uint256, error)deprecated
- func (c *Client) SignAndPushP2PNotaryRequest(mainTx *transaction.Transaction, fallbackScript []byte, fallbackSysFee int64, ...) (*payload.P2PNotaryRequest, error)deprecated
- func (c *Client) SignAndPushTx(tx *transaction.Transaction, acc *wallet.Account, cosigners []SignerAccount) (util.Uint256, error)deprecated
- func (c *Client) StateRootInHeader() (bool, error)deprecated
- func (c *Client) SubmitBlock(b block.Block) (util.Uint256, error)
- func (c *Client) SubmitP2PNotaryRequest(req *payload.P2PNotaryRequest) (util.Uint256, error)
- func (c *Client) SubmitRawOracleResponse(ps []interface{}) error
- func (c *Client) TerminateSession(sessionID uuid.UUID) (bool, error)
- func (c *Client) TransferNEP11(acc *wallet.Account, to util.Uint160, tokenHash util.Uint160, tokenID string, ...) (util.Uint256, error)deprecated
- func (c *Client) TransferNEP11D(acc *wallet.Account, to util.Uint160, tokenHash util.Uint160, amount int64, ...) (util.Uint256, error)deprecated
- func (c *Client) TransferNEP17(acc *wallet.Account, to util.Uint160, token util.Uint160, amount int64, ...) (util.Uint256, error)deprecated
- func (c *Client) TraverseIterator(sessionID, iteratorID uuid.UUID, maxItemsCount int) ([]stackitem.Item, error)
- func (c *Client) ValidateAddress(address string) error
- type Internal
- type InternalHook
- type Notification
- type Options
- type SignerAccount
- type TransferTarget
- type WSClient
- func (c *WSClient) Close()
- func (c *WSClient) Context() context.Context
- func (c *WSClient) GetError() error
- func (c *WSClient) ReceiveBlocks(flt *neorpc.BlockFilter, rcvr chan<- *block.Block) (string, error)
- func (c *WSClient) ReceiveExecutionNotifications(flt *neorpc.NotificationFilter, rcvr chan<- *state.ContainedNotificationEvent) (string, error)
- func (c *WSClient) ReceiveExecutions(flt *neorpc.ExecutionFilter, rcvr chan<- *state.AppExecResult) (string, error)
- func (c *WSClient) ReceiveNotaryRequests(flt *neorpc.TxFilter, rcvr chan<- *result.NotaryRequestEvent) (string, error)
- func (c *WSClient) ReceiveTransactions(flt *neorpc.TxFilter, rcvr chan<- *transaction.Transaction) (string, error)
- func (c *WSClient) SubscribeForExecutionNotifications(contract *util.Uint160, name *string) (string, error)deprecated
- func (c *WSClient) SubscribeForNewBlocks(primary *int) (string, error)deprecated
- func (c *WSClient) SubscribeForNewTransactions(sender *util.Uint160, signer *util.Uint160) (string, error)deprecated
- func (c *WSClient) SubscribeForNotaryRequests(sender *util.Uint160, mainSigner *util.Uint160) (string, error)deprecated
- func (c *WSClient) SubscribeForTransactionExecutions(state *string) (string, error)deprecated
- func (c *WSClient) Unsubscribe(id string) error
- func (c *WSClient) UnsubscribeAll() error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNilNotificationReceiver = errors.New("nil notification receiver")
ErrNilNotificationReceiver is returned when notification receiver channel is nil.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents the middleman for executing JSON RPC calls to remote NEO RPC nodes. Client is thread-safe and can be used from multiple goroutines.
func New ¶
New returns a new Client ready to use. You should call Init method to initialize stateroot setting for the network the client is operating on if you plan using GetBlock*.
func (*Client) AddNetworkFee
deprecated
func (c *Client) AddNetworkFee(tx *transaction.Transaction, extraFee int64, accs ...*wallet.Account) error
AddNetworkFee adds network fee for each witness script and optional extra network fee to transaction. `accs` is an array signer's accounts.
Deprecated: please use CalculateNetworkFee or actor.Actor. This method will be removed in future versions.
func (*Client) CalculateNetworkFee ¶
func (c *Client) CalculateNetworkFee(tx *transaction.Transaction) (int64, error)
CalculateNetworkFee calculates network fee for the transaction. The transaction may have empty witnesses for contract signers and may have only verification scripts filled for standard sig/multisig signers.
func (*Client) CalculateNotaryFee
deprecated
CalculateNotaryFee calculates network fee for one dummy Notary witness and NotaryAssisted attribute with NKeys specified. The result should be added to the transaction's net fee for successful verification.
Deprecated: NeoGo calculatenetworkfee method handles notary fees as well since 0.99.3, so this method is just no longer needed and will be removed in future versions.
func (*Client) CalculateValidUntilBlock
deprecated
CalculateValidUntilBlock calculates ValidUntilBlock field for tx as current blockchain height + number of validators. Number of validators is the length of blockchain validators list got from GetNextBlockValidators() method. Validators count is being cached and updated every 100 blocks.
Deprecated: please use (*Actor).CalculateValidUntilBlock. This method will be removed in future versions.
func (*Client) Close ¶
func (c *Client) Close()
Close closes unused underlying networks connections.
func (*Client) CreateNEP11TransferTx
deprecated
func (c *Client) CreateNEP11TransferTx(acc *wallet.Account, tokenHash util.Uint160, gas int64, cosigners []SignerAccount, args ...interface{}) (*transaction.Transaction, error)
CreateNEP11TransferTx creates an invocation transaction for the 'transfer' method of the given contract (token) to move the whole (or the specified amount of) NEP-11 token with the specified token ID to the given account and returns it. The returned transaction is not signed. CreateNEP11TransferTx is also a helper for TransferNEP11 and TransferNEP11D. `args` for TransferNEP11: to util.Uint160, tokenID string, data interface{}; `args` for TransferNEP11D: from, to util.Uint160, amount int64, tokenID string, data interface{}.
Deprecated: please use nep11 package, this method will be removed in future versions.
func (*Client) CreateNEP17MultiTransferTx
deprecated
func (c *Client) CreateNEP17MultiTransferTx(acc *wallet.Account, gas int64, recipients []TransferTarget, cosigners []SignerAccount) (*transaction.Transaction, error)
CreateNEP17MultiTransferTx creates an invocation transaction for performing NEP-17 transfers from a single sender to multiple recipients with the given data and cosigners. The transaction sender is included with the CalledByEntry scope by default.
Deprecated: please use nep17 package (when transferring the same token) or smartcontract.Builder (when transferring multiple tokens), this method will be removed in future versions.
func (*Client) CreateNEP17TransferTx
deprecated
func (c *Client) CreateNEP17TransferTx(acc *wallet.Account, to util.Uint160, token util.Uint160, amount int64, gas int64, data interface{}, cosigners []SignerAccount) (*transaction.Transaction, error)
CreateNEP17TransferTx creates an invocation transaction for the 'transfer' method of the given contract (token) to move the specified amount of NEP-17 assets (in FixedN format using contract's number of decimals) to the given account and returns it. The returned transaction is not signed.
Deprecated: please use nep17 package, this method will be removed in future versions.
func (*Client) CreateTxFromScript
deprecated
func (c *Client) CreateTxFromScript(script []byte, acc *wallet.Account, sysFee, netFee int64, cosigners []SignerAccount) (*transaction.Transaction, error)
CreateTxFromScript creates transaction and properly sets cosigners and NetworkFee. If sysFee <= 0, it is determined via result of `invokescript` RPC. You should initialize network magic with Init before calling CreateTxFromScript.
Deprecated: please use actor.Actor API, this method will be removed in future versions.
func (*Client) FindStates ¶
func (c *Client) FindStates(stateroot util.Uint256, historicalContractHash util.Uint160, historicalPrefix []byte, start []byte, maxCount *int) (result.FindStates, error)
FindStates returns historical contract storage item states by the given stateroot, historical contract hash and historical prefix. If `start` path is specified, items starting from `start` path are being returned (excluding item located at the start path). If `maxCount` specified, the maximum number of items to be returned equals to `maxCount`.
func (*Client) GetApplicationLog ¶
func (c *Client) GetApplicationLog(hash util.Uint256, trig *trigger.Type) (*result.ApplicationLog, error)
GetApplicationLog returns a contract log based on the specified txid.
func (*Client) GetBestBlockHash ¶
GetBestBlockHash returns the hash of the tallest block in the blockchain.
func (*Client) GetBlockByHash ¶
GetBlockByHash returns a block by its hash. In-header stateroot option must be initialized with Init before calling this method.
func (*Client) GetBlockByHashVerbose ¶
GetBlockByHashVerbose returns a block wrapper with additional metadata by its hash. In-header stateroot option must be initialized with Init before calling this method.
func (*Client) GetBlockByIndex ¶
GetBlockByIndex returns a block by its height. In-header stateroot option must be initialized with Init before calling this method.
func (*Client) GetBlockByIndexVerbose ¶
GetBlockByIndexVerbose returns a block wrapper with additional metadata by its height. In-header stateroot option must be initialized with Init before calling this method. NOTE: to get transaction.ID and transaction.Size, use t.Hash() and io.GetVarSize(t) respectively.
func (*Client) GetBlockCount ¶
GetBlockCount returns the number of blocks in the blockchain.
func (*Client) GetBlockHash ¶
GetBlockHash returns the hash value of the corresponding block based on the specified index.
func (*Client) GetBlockHeader ¶
GetBlockHeader returns the corresponding block header information from a serialized hex string according to the specified script hash. In-header stateroot option must be initialized with Init before calling this method.
func (*Client) GetBlockHeaderCount ¶
GetBlockHeaderCount returns the number of headers in the main chain.
func (*Client) GetBlockHeaderVerbose ¶
GetBlockHeaderVerbose returns the corresponding block header information from a Json format string according to the specified script hash. In-header stateroot option must be initialized with Init before calling this method.
func (*Client) GetBlockSysFee ¶
GetBlockSysFee returns the system fees of the block based on the specified index. This method is only supported by NeoGo servers.
func (*Client) GetCandidateRegisterPrice
deprecated
func (*Client) GetCandidates ¶
GetCandidates returns the current list of NEO candidate node with voting data and validator status.
func (*Client) GetCommittee ¶
func (c *Client) GetCommittee() (keys.PublicKeys, error)
GetCommittee returns the current public keys of NEO nodes in the committee.
func (*Client) GetConnectionCount ¶
GetConnectionCount returns the current number of the connections for the node.
func (*Client) GetContractStateByAddressOrName ¶
GetContractStateByAddressOrName queries contract information using the contract address or name. Notice that name-based queries work only for native contracts, non-native ones can't be requested this way.
func (*Client) GetContractStateByHash ¶
GetContractStateByHash queries contract information according to the contract script hash.
func (*Client) GetContractStateByID ¶
GetContractStateByID queries contract information according to the contract ID. Notice that this is supported by all servers only for native contracts, non-native ones can be requested only from NeoGo servers.
func (*Client) GetDesignatedByRole
deprecated
func (*Client) GetExecFeeFactor
deprecated
func (*Client) GetFeePerByte
deprecated
func (*Client) GetGasPerBlock
deprecated
func (*Client) GetMaxNotValidBeforeDelta
deprecated
func (*Client) GetNEP11Balances ¶
GetNEP11Balances is a wrapper for getnep11balances RPC.
func (*Client) GetNEP11Properties ¶
func (c *Client) GetNEP11Properties(asset util.Uint160, token []byte) (map[string]interface{}, error)
GetNEP11Properties is a wrapper for getnep11properties RPC. We recommend using nep11 package and Properties method there to receive proper VM types and work with them. 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 (*Client) GetNEP11Transfers ¶
func (c *Client) GetNEP11Transfers(address util.Uint160, start, stop *uint64, limit, page *int) (*result.NEP11Transfers, error)
GetNEP11Transfers is a wrapper for getnep11transfers RPC. Address parameter is mandatory, while all others are optional. Limit and page parameters are only supported by NeoGo servers and can only be specified with start and stop.
func (*Client) GetNEP17Balances ¶
GetNEP17Balances is a wrapper for getnep17balances RPC.
func (*Client) GetNEP17Transfers ¶
func (c *Client) GetNEP17Transfers(address util.Uint160, start, stop *uint64, limit, page *int) (*result.NEP17Transfers, error)
GetNEP17Transfers is a wrapper for getnep17transfers RPC. Address parameter is mandatory while all the others are optional. Start and stop parameters are supported since neo-go 0.77.0 and limit and page since neo-go 0.78.0. These parameters are positional in the JSON-RPC call. For example, you can't specify the limit without specifying start/stop first.
func (*Client) GetNativeContractHash
deprecated
GetNativeContractHash returns native contract hash by its name.
Deprecated: please use native contract subpackages that have hashes directly (gas, management, neo, notary, oracle, policy, rolemgmt) or GetContractStateByAddressOrName method that will return hash along with other data.
func (*Client) GetNativeContracts ¶
func (c *Client) GetNativeContracts() ([]state.NativeContract, error)
GetNativeContracts queries information about native contracts.
func (*Client) GetNetwork
deprecated
GetNetwork returns the network magic of the RPC node the client connected to. It requires Init to be done first, otherwise an error is returned.
Deprecated: please use GetVersion (it has the same data in the Protocol section) or actor subpackage. This method will be removed in future versions.
func (*Client) GetNextBlockValidators ¶
GetNextBlockValidators returns the current NEO consensus nodes information and voting data.
func (*Client) GetNotaryServiceFeePerKey
deprecated
GetNotaryServiceFeePerKey returns a reward per notary request key for the designated notary nodes. It doesn't cache the result.
Deprecated: please use the Notary contract wrapper from the notary subpackage. This method will be removed in future versions.
func (*Client) GetOraclePrice
deprecated
func (*Client) GetPeers ¶
GetPeers returns a list of the nodes that the node is currently connected to/disconnected from.
func (*Client) GetRawMemPool ¶
GetRawMemPool returns a list of unconfirmed transactions in the memory.
func (*Client) GetRawTransaction ¶
func (c *Client) GetRawTransaction(hash util.Uint256) (*transaction.Transaction, error)
GetRawTransaction returns a transaction by hash.
func (*Client) GetRawTransactionVerbose ¶
GetRawTransactionVerbose returns a transaction wrapper with additional metadata by transaction's hash. NOTE: to get transaction.ID and transaction.Size, use t.Hash() and io.GetVarSize(t) respectively.
func (*Client) GetState ¶
func (c *Client) GetState(stateroot util.Uint256, historicalContractHash util.Uint160, historicalKey []byte) ([]byte, error)
GetState returns historical contract storage item state by the given stateroot, historical contract hash and historical item key.
func (*Client) GetStateHeight ¶
func (c *Client) GetStateHeight() (*result.StateHeight, error)
GetStateHeight returns the current validated and local node state height.
func (*Client) GetStateRootByBlockHash ¶
GetStateRootByBlockHash returns the state root for the block with the specified hash.
func (*Client) GetStateRootByHeight ¶
GetStateRootByHeight returns the state root for the specified height.
func (*Client) GetStorageByHash ¶
GetStorageByHash returns the stored value according to the contract script hash and the stored key.
func (*Client) GetStorageByID ¶
GetStorageByID returns the stored value according to the contract ID and the stored key.
func (*Client) GetStoragePrice
deprecated
func (*Client) GetTransactionHeight ¶
GetTransactionHeight returns the block index where the transaction is found.
func (*Client) GetUnclaimedGas ¶
func (c *Client) GetUnclaimedGas(address string) (result.UnclaimedGas, error)
GetUnclaimedGas returns the unclaimed GAS amount for the specified address.
func (*Client) GetVersion ¶
GetVersion returns the version information about the queried node.
func (*Client) Init ¶
Init sets magic of the network client connected to, stateRootInHeader option and native NEO, GAS and Policy contracts scripthashes. This method should be called before any header- or block-related requests in order to deserialize responses properly.
func (*Client) InvokeAndPackIteratorResults
deprecated
func (c *Client) InvokeAndPackIteratorResults(contract util.Uint160, operation string, params []smartcontract.Parameter, signers []transaction.Signer, maxIteratorResultItems ...int) (*result.Invoke, error)
InvokeAndPackIteratorResults creates a script containing System.Contract.Call of the specified contract with the specified arguments. It assumes that the specified operation will return iterator. The script traverses the resulting iterator, packs all its values into array and pushes the resulting array on stack. Constructed script is invoked via `invokescript` JSON-RPC API using the provided signers. The result of the script invocation contains single array stackitem on stack if invocation HALTed. InvokeAndPackIteratorResults can be used to interact with JSON-RPC server where iterator sessions are disabled to retrieve iterator values via single `invokescript` JSON-RPC call. It returns maxIteratorResultItems items at max which is set to config.DefaultMaxIteratorResultItems by default.
Deprecated: please use more convenient and powerful invoker.Invoker interface with CallAndExpandIterator method. This method will be removed in future versions.
func (*Client) InvokeContractVerify ¶
func (c *Client) InvokeContractVerify(contract util.Uint160, params []smartcontract.Parameter, signers []transaction.Signer, witnesses ...transaction.Witness) (*result.Invoke, error)
InvokeContractVerify returns the results after calling `verify` method of the smart contract with the given parameters under verification trigger type. NOTE: this is test invoke and will not affect the blockchain.
func (*Client) InvokeContractVerifyAtHeight ¶
func (c *Client) InvokeContractVerifyAtHeight(height uint32, contract util.Uint160, params []smartcontract.Parameter, signers []transaction.Signer, witnesses ...transaction.Witness) (*result.Invoke, error)
InvokeContractVerifyAtHeight returns the results after calling `verify` method of the smart contract with the given parameters under verification trigger type at the blockchain state specified by the blockchain height. NOTE: this is test invoke and will not affect the blockchain.
func (*Client) InvokeContractVerifyWithState ¶
func (c *Client) InvokeContractVerifyWithState(stateOrBlock util.Uint256, contract util.Uint160, params []smartcontract.Parameter, signers []transaction.Signer, witnesses ...transaction.Witness) (*result.Invoke, error)
InvokeContractVerifyWithState returns the results after calling `verify` method of the smart contract with the given parameters under verification trigger type at the blockchain state specified by the state root or block hash. NOTE: this is test invoke and will not affect the blockchain.
func (*Client) InvokeFunction ¶
func (c *Client) InvokeFunction(contract util.Uint160, operation string, params []smartcontract.Parameter, signers []transaction.Signer) (*result.Invoke, error)
InvokeFunction returns the results after calling the smart contract scripthash with the given operation and parameters. NOTE: this is test invoke and will not affect the blockchain.
func (*Client) InvokeFunctionAtHeight ¶
func (c *Client) InvokeFunctionAtHeight(height uint32, contract util.Uint160, operation string, params []smartcontract.Parameter, signers []transaction.Signer) (*result.Invoke, error)
InvokeFunctionAtHeight returns the results after calling the smart contract with the given operation and parameters at the given blockchain state specified by the blockchain height. NOTE: this is test invoke and will not affect the blockchain.
func (*Client) InvokeFunctionWithState ¶
func (c *Client) InvokeFunctionWithState(stateOrBlock util.Uint256, contract util.Uint160, operation string, params []smartcontract.Parameter, signers []transaction.Signer) (*result.Invoke, error)
InvokeFunctionWithState returns the results after calling the smart contract with the given operation and parameters at the given blockchain state defined by the specified state root or block hash. NOTE: this is test invoke and will not affect the blockchain.
func (*Client) InvokeScript ¶
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 (*Client) InvokeScriptAtHeight ¶
func (c *Client) InvokeScriptAtHeight(height uint32, script []byte, signers []transaction.Signer) (*result.Invoke, error)
InvokeScriptAtHeight returns the result of the given script after running it true the VM using the provided chain state retrieved from the specified chain height. NOTE: This is a test invoke and will not affect the blockchain.
func (*Client) InvokeScriptWithState ¶
func (c *Client) InvokeScriptWithState(stateOrBlock util.Uint256, script []byte, signers []transaction.Signer) (*result.Invoke, error)
InvokeScriptWithState returns the result of the given script after running it true the VM using the provided chain state retrieved from the specified state root or block hash. NOTE: This is a test invoke and will not affect the blockchain.
func (*Client) MultiTransferNEP17
deprecated
func (c *Client) MultiTransferNEP17(acc *wallet.Account, gas int64, recipients []TransferTarget, cosigners []SignerAccount) (util.Uint256, error)
MultiTransferNEP17 is similar to TransferNEP17, buf allows to have multiple recipients.
Deprecated: please use nep17 package (when transferring the same token) or smartcontract.Builder (when transferring multiple tokens), this method will be removed in future versions.
func (*Client) NEP11DBalanceOf
deprecated
func (*Client) NEP11DOwnerOf
deprecated
func (c *Client) NEP11DOwnerOf(tokenHash util.Uint160, tokenID []byte) (uuid.UUID, result.Iterator, error)
NEP11DOwnerOf returns iterator over the specified NEP-11 divisible token owners. First return value is the session ID, the second one is Iterator itself, the third one is an error. Use TraverseIterator method to traverse iterator values or TerminateSession to terminate opened iterator session. See TraverseIterator and TerminateSession documentation for more details.
Deprecated: please use nep11 package, this method will be removed in future versions.
func (*Client) NEP11DUnpackedOwnerOf
deprecated
func (c *Client) NEP11DUnpackedOwnerOf(tokenHash util.Uint160, tokenID []byte) ([]util.Uint160, error)
NEP11DUnpackedOwnerOf returns list of the specified NEP-11 divisible token owners (config.DefaultMaxIteratorResultItems at max). It differs from NEP11DOwnerOf in that no iterator session is used to retrieve values from iterator. Instead, unpacking VM script is created and invoked via `invokescript` JSON-RPC call.
Deprecated: please use nep11 package, this method will be removed in future versions.
func (*Client) NEP11NDOwnerOf
deprecated
func (*Client) NEP11Properties
deprecated
func (*Client) NEP11Tokens
deprecated
NEP11Tokens returns iterator over the tokens minted by the contract. First return value is the session ID, the second one is Iterator itself, the third one is an error. Use TraverseIterator method to traverse iterator values or TerminateSession to terminate opened iterator session. See TraverseIterator and TerminateSession documentation for more details.
Deprecated: please use nep11 package, this method will be removed in future versions.
func (*Client) NEP11TokensOf
deprecated
func (c *Client) NEP11TokensOf(tokenHash util.Uint160, owner util.Uint160) (uuid.UUID, result.Iterator, error)
NEP11TokensOf returns iterator over token IDs for the specified owner of the specified NFT token. First return value is the session ID, the second one is Iterator itself, the third one is an error. Use TraverseIterator method to traverse iterator values or TerminateSession to terminate opened iterator session. See TraverseIterator and TerminateSession documentation for more details.
Deprecated: please use nep11 package, this method will be removed in future versions.
func (*Client) NEP11UnpackedTokens
deprecated
NEP11UnpackedTokens returns list of the tokens minted by the contract (config.DefaultMaxIteratorResultItems at max). It differs from NEP11Tokens in that no iterator session is used to retrieve values from iterator. Instead, unpacking VM script is created and invoked via `invokescript` JSON-RPC call.
Deprecated: please use nep11 package, this method will be removed in future versions.
func (*Client) NEP11UnpackedTokensOf
deprecated
func (c *Client) NEP11UnpackedTokensOf(tokenHash util.Uint160, owner util.Uint160) ([][]byte, error)
NEP11UnpackedTokensOf returns an array of token IDs for the specified owner of the specified NFT token (config.DefaultMaxIteratorResultItems at max). It differs from NEP11TokensOf in that no iterator session is used to retrieve values from iterator. Instead, unpacking VM script is created and invoked via `invokescript` JSON-RPC call.
Deprecated: please use nep11 package, this method will be removed in future versions.
func (*Client) NEP17BalanceOf
deprecated
NEP17BalanceOf invokes `balanceOf` NEP-17 method on the specified contract.
Deprecated: please use nep17 package, this method will be removed in future versions. This method is also wrong since tokens can return values overflowing int64.
func (*Client) NEP17TotalSupply
deprecated
NEP17TotalSupply invokes `totalSupply` NEP-17 method on the specified contract.
Deprecated: please use nep17 package, this method will be removed in future versions. This method is also wrong since tokens can return values overflowing int64.
func (*Client) NNSGetAllRecords
deprecated
func (c *Client) NNSGetAllRecords(nnsHash util.Uint160, name string) (uuid.UUID, result.Iterator, error)
NNSGetAllRecords returns iterator over records for a given name from NNS service. First return value is the session ID, the second one is Iterator itself, the third one is an error. Use TraverseIterator method to traverse iterator values or TerminateSession to terminate opened iterator session. See TraverseIterator and TerminateSession documentation for more details.
Deprecated: please use nns subpackage. This method will be removed in future versions.
func (*Client) NNSIsAvailable
deprecated
func (*Client) NNSResolve
deprecated
func (*Client) NNSUnpackedGetAllRecords
deprecated
func (c *Client) NNSUnpackedGetAllRecords(nnsHash util.Uint160, name string) ([]nns.RecordState, error)
NNSUnpackedGetAllRecords returns a set of records for a given name from NNS service (config.DefaultMaxIteratorResultItems at max). It differs from NNSGetAllRecords in that no iterator session is used to retrieve values from iterator. Instead, unpacking VM script is created and invoked via `invokescript` JSON-RPC call.
Deprecated: please use nns subpackage. This method will be removed in future versions.
func (*Client) Ping ¶
Ping attempts to create a connection to the endpoint and returns an error if there is any.
func (*Client) SendRawTransaction ¶
func (c *Client) SendRawTransaction(rawTX *transaction.Transaction) (util.Uint256, error)
SendRawTransaction broadcasts the given transaction to the Neo network. It always returns transaction hash, when successful (no error) this is the hash returned from server, when not it's a locally calculated rawTX hash.
func (*Client) SignAndPushInvocationTx
deprecated
func (c *Client) SignAndPushInvocationTx(script []byte, acc *wallet.Account, sysfee int64, netfee fixedn.Fixed8, cosigners []SignerAccount) (util.Uint256, error)
SignAndPushInvocationTx signs and pushes the given script as an invocation transaction using the given wif to sign it and the given cosigners to cosign it if possible. It spends the amount of gas specified. It returns a hash of the invocation transaction and an error. If one of the cosigners accounts is neither contract-based nor unlocked, an error is returned.
Deprecated: please use actor.Actor API, this method will be removed in future versions.
func (*Client) SignAndPushP2PNotaryRequest
deprecated
func (c *Client) SignAndPushP2PNotaryRequest(mainTx *transaction.Transaction, fallbackScript []byte, fallbackSysFee int64, fallbackNetFee int64, fallbackValidFor uint32, acc *wallet.Account) (*payload.P2PNotaryRequest, error)
SignAndPushP2PNotaryRequest creates and pushes a P2PNotary request constructed from the main and fallback transactions using the given wif to sign it. It returns the request and an error. Fallback transaction is constructed from the given script using the amount of gas specified. For successful fallback transaction validation at least 2*transaction.NotaryServiceFeePerKey GAS should be deposited to the Notary contract. Main transaction should be constructed by the user. Several rules should be met for successful main transaction acceptance:
- Native Notary contract should be a signer of the main transaction.
- Notary signer should have None scope.
- Main transaction should have dummy contract witness for Notary signer.
- Main transaction should have NotaryAssisted attribute with NKeys specified.
- NotaryAssisted attribute and dummy Notary witness (as long as the other incomplete witnesses) should be paid for. Use CalculateNotaryWitness to calculate the amount of network fee to pay for the attribute and Notary witness.
- Main transaction either shouldn't have all witnesses attached (in this case none of them can be multisignature), or it only should have a partial multisignature.
Note: client should be initialized before SignAndPushP2PNotaryRequest call.
Deprecated: please use Actor from the notary subpackage. This method will be deleted in future versions.
func (*Client) SignAndPushTx
deprecated
func (c *Client) SignAndPushTx(tx *transaction.Transaction, acc *wallet.Account, cosigners []SignerAccount) (util.Uint256, error)
SignAndPushTx signs the given transaction using the given wif and cosigners and pushes it to the chain. It returns a hash of the transaction and an error. If one of the cosigners accounts is neither contract-based nor unlocked, an error is returned.
Deprecated: please use actor.Actor API, this method will be removed in future versions.
func (*Client) StateRootInHeader
deprecated
StateRootInHeader returns true if the state root is contained in the block header. You should initialize Client cache with Init() before calling StateRootInHeader.
Deprecated: please use GetVersion (it has the same data in the Protocol section). This method will be removed in future versions.
func (*Client) SubmitBlock ¶
SubmitBlock broadcasts a raw block over the NEO network.
func (*Client) SubmitP2PNotaryRequest ¶
SubmitP2PNotaryRequest submits given P2PNotaryRequest payload to the RPC node.
func (*Client) SubmitRawOracleResponse ¶
SubmitRawOracleResponse submits a raw oracle response to the oracle node. Raw params are used to avoid excessive marshalling.
func (*Client) TerminateSession ¶
TerminateSession tries to terminate the specified session and returns `true` iff the specified session was found on server.
func (*Client) TransferNEP11
deprecated
func (c *Client) TransferNEP11(acc *wallet.Account, to util.Uint160, tokenHash util.Uint160, tokenID string, data interface{}, gas int64, cosigners []SignerAccount) (util.Uint256, error)
TransferNEP11 creates an invocation transaction that invokes 'transfer' method on the given token to move the whole NEP-11 token with the specified token ID to the given account and sends it to the network returning just a hash of it.
Deprecated: please use nep11 package, this method will be removed in future versions.
func (*Client) TransferNEP11D
deprecated
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)
TransferNEP11D creates an invocation transaction that invokes 'transfer' method on the given token to move the specified amount of divisible NEP-11 assets (in FixedN format using contract's number of decimals) to the given account and sends it to the network returning just a hash of it.
Deprecated: please use nep11 package, this method will be removed in future versions.
func (*Client) TransferNEP17
deprecated
func (c *Client) TransferNEP17(acc *wallet.Account, to util.Uint160, token util.Uint160, amount int64, gas int64, data interface{}, cosigners []SignerAccount) (util.Uint256, error)
TransferNEP17 creates an invocation transaction that invokes 'transfer' method on the given token to move the specified amount of NEP-17 assets (in FixedN format using contract's number of decimals) to the given account with the data specified and sends it to the network returning just a hash of it. Cosigners argument specifies a set of the transaction cosigners (may be nil or may include sender) with a proper scope and the accounts to cosign the transaction. If cosigning is impossible (e.g. due to locked cosigner's account) an error is returned.
Deprecated: please use nep17 package, this method will be removed in future versions.
func (*Client) TraverseIterator ¶
func (c *Client) TraverseIterator(sessionID, iteratorID uuid.UUID, maxItemsCount int) ([]stackitem.Item, error)
TraverseIterator returns a set of iterator values (maxItemsCount at max) for the specified iterator and session. If result contains no elements, then either Iterator has no elements or session was expired and terminated by the server. If maxItemsCount is non-positive, then config.DefaultMaxIteratorResultItems iterator values will be returned using single `traverseiterator` call. Note that iterator session lifetime is restricted by the RPC-server configuration and is being reset each time iterator is accessed. If session won't be accessed within session expiration time, then it will be terminated by the RPC-server automatically.
type Internal ¶ added in v0.101.1
type Internal struct { WSClient // contains filtered or unexported fields }
Internal is an experimental "local" client that does not connect to RPC via network. It's made for deeply integrated applications like NeoFS that have blockchain running in the same process, so use it only if you know what you're doing. It provides the same interface WSClient does.
func NewInternal ¶ added in v0.101.1
func NewInternal(ctx context.Context, register InternalHook) (*Internal, error)
NewInternal creates an instance of internal client. It accepts a method provided by RPC server.
type InternalHook ¶ added in v0.101.1
type InternalHook func(context.Context, chan<- neorpc.Notification) func(*neorpc.Request) (*neorpc.Response, error)
InternalHook is a function signature that is required to create a local client (see NewInternal). It performs registration of local client's event channel and returns a request handler function.
type Notification ¶
Notification represents a server-generated notification for client subscriptions. Value can be one of *block.Block, *state.AppExecResult, *state.ContainedNotificationEvent *transaction.Transaction or *subscriptions.NotaryRequestEvent based on Type.
func (Notification) EventID ¶ added in v0.99.5
func (n Notification) EventID() neorpc.EventID
EventID implements Container interface and returns notification ID.
func (Notification) EventPayload ¶ added in v0.99.5
func (n Notification) EventPayload() interface{}
EventPayload implements Container interface and returns notification object.
type Options ¶
type Options struct { // Cert is a client-side certificate, it doesn't work at the moment along // with the other two options below. Cert string Key string CACert string DialTimeout time.Duration RequestTimeout time.Duration // Limit total number of connections per host. No limit by default. MaxConnsPerHost int }
Options defines options for the RPC client. All values are optional. If any duration is not specified, a default of 4 seconds will be used.
type SignerAccount ¶
type SignerAccount struct { Signer transaction.Signer Account *wallet.Account }
SignerAccount represents combination of the transaction.Signer and the corresponding wallet.Account.
type TransferTarget ¶
type TransferTarget struct { Token util.Uint160 Address util.Uint160 Amount int64 Data interface{} }
TransferTarget represents target address, token amount and data for transfer.
type WSClient ¶
type WSClient struct { Client // Notifications is a channel that is used to send events received from // the server. Client's code is supposed to be reading from this channel if // it wants to use subscription mechanism. Failing to do so will cause // WSClient to block even regular requests. This channel is not buffered. // In case of protocol error or upon connection closure, this channel will // be closed, so make sure to handle this. Make sure you're not changing the // received notifications, as it may affect the functionality of other // notification receivers. // // Deprecated: please, use custom channels with ReceiveBlocks, ReceiveTransactions, // ReceiveExecutionNotifications, ReceiveExecutions, ReceiveNotaryRequests // methods to subscribe for notifications. This field will be removed in future // versions. Notifications chan Notification // contains filtered or unexported fields }
WSClient is a websocket-enabled RPC client that can be used with appropriate servers. It's supposed to be faster than Client because it has persistent connection to the server and at the same time it exposes some functionality that is only provided via websockets (like event subscription mechanism). WSClient is thread-safe and can be used from multiple goroutines to perform RPC requests.
It exposes a set of Receive* methods with the same behaviour pattern that is caused by the fact that the client itself receives every message from the server via a single channel. This includes any subscriptions and any replies to ordinary requests at the same. The client then routes these messages to channels provided on subscription (passed to Receive*) or to the respective receivers (API callers) if it's an ordinary JSON-RPC reply. While synchronous API users are blocked during their calls and wake up on reply, subscription channels must be read from to avoid blocking the client. Failure to do so will make WSClient wait for the channel reader to get the event and while it waits every other messages (subscription-related or request replies) will be blocked. This also means that subscription channel must be properly drained after unsubscription.
Any received subscription items (blocks/transactions/nofitications) are passed via pointers for efficiency, but the actual structures MUST NOT be changed, as it may affect the functionality of other notification receivers. If multiple subscriptions share the same receiver channel, then matching notification is only sent once per channel. The receiver channel will be closed by the WSClient immediately after MissedEvent is received from the server; no unsubscription is performed in this case, so it's the user responsibility to unsubscribe.
func NewWS ¶
NewWS returns a new WSClient ready to use (with established websocket connection). You need to use websocket URL for it like `ws://1.2.3.4/ws`. You should call Init method to initialize the network magic the client is operating on.
func (*WSClient) Close ¶
func (c *WSClient) Close()
Close closes connection to the remote side rendering this client instance unusable.
func (*WSClient) Context ¶ added in v0.99.5
Context returns WSClient Cancel context that will be terminated on Client shutdown.
func (*WSClient) GetError ¶
GetError returns the reason of WS connection closing. It returns nil in case if connection was closed by the use via Close() method calling.
func (*WSClient) ReceiveBlocks ¶ added in v0.99.5
ReceiveBlocks registers provided channel as a receiver for the new block events. Events can be filtered by the given BlockFilter, nil value doesn't add any filter. See WSClient comments for generic Receive* behaviour details.
func (*WSClient) ReceiveExecutionNotifications ¶ added in v0.99.5
func (c *WSClient) ReceiveExecutionNotifications(flt *neorpc.NotificationFilter, rcvr chan<- *state.ContainedNotificationEvent) (string, error)
ReceiveExecutionNotifications registers provided channel as a receiver for execution events. Events can be filtered by the given NotificationFilter, nil value doesn't add any filter. See WSClient comments for generic Receive* behaviour details.
func (*WSClient) ReceiveExecutions ¶ added in v0.99.5
func (c *WSClient) ReceiveExecutions(flt *neorpc.ExecutionFilter, rcvr chan<- *state.AppExecResult) (string, error)
ReceiveExecutions registers provided channel as a receiver for application execution result events generated during transaction execution. Events can be filtered by the given ExecutionFilter, nil value doesn't add any filter. See WSClient comments for generic Receive* behaviour details.
func (*WSClient) ReceiveNotaryRequests ¶ added in v0.99.5
func (c *WSClient) ReceiveNotaryRequests(flt *neorpc.TxFilter, rcvr chan<- *result.NotaryRequestEvent) (string, error)
ReceiveNotaryRequests registers provided channel as a receiver for notary request payload addition or removal events. Events can be filtered by the given TxFilter where sender corresponds to notary request sender (the second fallback transaction signer) and signer corresponds to main transaction signers. nil value doesn't add any filter. See WSClient comments for generic Receive* behaviour details.
func (*WSClient) ReceiveTransactions ¶ added in v0.99.5
func (c *WSClient) ReceiveTransactions(flt *neorpc.TxFilter, rcvr chan<- *transaction.Transaction) (string, error)
ReceiveTransactions registers provided channel as a receiver for new transaction events. Events can be filtered by the given TxFilter, nil value doesn't add any filter. See WSClient comments for generic Receive* behaviour details.
func (*WSClient) SubscribeForExecutionNotifications
deprecated
func (c *WSClient) SubscribeForExecutionNotifications(contract *util.Uint160, name *string) (string, error)
SubscribeForExecutionNotifications adds subscription for notifications generated during transaction execution to this instance of the client. It can be filtered by the contract's hash (that emits notifications), nil value puts no such restrictions.
Deprecated: please, use ReceiveExecutionNotifications. This method will be removed in future versions.
func (*WSClient) SubscribeForNewBlocks
deprecated
SubscribeForNewBlocks adds subscription for new block events to this instance of the client. It can be filtered by primary consensus node index, nil value doesn't add any filters.
Deprecated: please, use ReceiveBlocks. This method will be removed in future versions.
func (*WSClient) SubscribeForNewTransactions
deprecated
func (c *WSClient) SubscribeForNewTransactions(sender *util.Uint160, signer *util.Uint160) (string, error)
SubscribeForNewTransactions adds subscription for new transaction events to this instance of the client. It can be filtered by the sender and/or the signer, nil value is treated as missing filter.
Deprecated: please, use ReceiveTransactions. This method will be removed in future versions.
func (*WSClient) SubscribeForNotaryRequests
deprecated
func (c *WSClient) SubscribeForNotaryRequests(sender *util.Uint160, mainSigner *util.Uint160) (string, error)
SubscribeForNotaryRequests adds subscription for notary request payloads addition or removal events to this instance of client. It can be filtered by request sender's hash, or main tx signer's hash, nil value puts no such restrictions.
Deprecated: please, use ReceiveNotaryRequests. This method will be removed in future versions.
func (*WSClient) SubscribeForTransactionExecutions
deprecated
SubscribeForTransactionExecutions adds subscription for application execution results generated during transaction execution to this instance of the client. It can be filtered by state (HALT/FAULT) to check for successful or failing transactions, nil value means no filtering.
Deprecated: please, use ReceiveExecutions. This method will be removed in future versions.
func (*WSClient) Unsubscribe ¶
Unsubscribe removes subscription for the given event stream. It will return an error in case if there's no subscription with the provided ID. Call to Unsubscribe doesn't block notifications receive process for given subscriber, thus, ensure that subscriber channel is properly drained while unsubscription is being performed. Failing to do so will cause WSClient to block even regular requests. You may probably need to run unsubscription process in a separate routine (in parallel with notification receiver routine) to avoid Client's notification dispatcher blocking.
func (*WSClient) UnsubscribeAll ¶
UnsubscribeAll removes all active subscriptions of the current client. It copies the list of subscribers in order not to hold the lock for the whole execution time and tries to unsubscribe from us many feeds as possible returning the chunk of unsubscription errors afterwards. Call to UnsubscribeAll doesn't block notifications receive process for given subscribers, thus, ensure that subscribers channels are properly drained while unsubscription is being performed. Failing to do so will cause WSClient to block even regular requests. You may probably need to run unsubscription process in a separate routine (in parallel with notification receiver routines) to avoid Client's notification dispatcher blocking.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package actor provides a way to change chain state via RPC client.
|
Package actor provides a way to change chain state via RPC client. |
Package gas provides a convenience wrapper for GAS contract to use it via RPC.
|
Package gas provides a convenience wrapper for GAS contract to use it via RPC. |
Package invoker provides a convenient wrapper to perform test calls via RPC client.
|
Package invoker provides a convenient wrapper to perform test calls via RPC client. |
Package management provides an RPC wrapper for the native ContractManagement contract.
|
Package management provides an RPC wrapper for the native ContractManagement contract. |
Package neo provides an RPC-based wrapper for the NEOToken contract.
|
Package neo provides an RPC-based wrapper for the NEOToken contract. |
Package nep11 contains RPC wrappers for NEP-11 contracts.
|
Package nep11 contains RPC wrappers for NEP-11 contracts. |
Package nep17 contains RPC wrappers to work with NEP-17 contracts.
|
Package nep17 contains RPC wrappers to work with NEP-17 contracts. |
Package neptoken contains RPC wrapper for common NEP-11 and NEP-17 methods.
|
Package neptoken contains RPC wrapper for common NEP-11 and NEP-17 methods. |
Package nns provide some RPC wrappers for the non-native NNS contract.
|
Package nns provide some RPC wrappers for the non-native NNS contract. |
Package notary provides an RPC-based wrapper for the Notary subsystem.
|
Package notary provides an RPC-based wrapper for the Notary subsystem. |
Package oracle allows to work with the native OracleContract contract via RPC.
|
Package oracle allows to work with the native OracleContract contract via RPC. |
Package policy allows to work with the native PolicyContract contract via RPC.
|
Package policy allows to work with the native PolicyContract contract via RPC. |
Package rolemgmt allows to work with the native RoleManagement contract via RPC.
|
Package rolemgmt allows to work with the native RoleManagement contract via RPC. |
Package unwrap provides a set of proxy methods to process invocation results.
|
Package unwrap provides a set of proxy methods to process invocation results. |