Documentation ¶
Overview ¶
Package client implements a websocket-enabled kaspa JSON-RPC client.
Overview ¶
This client provides a robust and easy to use client for interfacing with a kaspa RPC server that uses a kaspa compatible kaspa JSON-RPC API.
In addition to the compatible standard HTTP POST JSON-RPC API, kaspad provides a websocket interface that is more efficient than the standard HTTP POST method of accessing RPC. The section below discusses the differences between HTTP POST and websockets.
By default, this client assumes the RPC server supports websockets and has TLS enabled.
Websockets vs HTTP POST ¶
In HTTP POST-based JSON-RPC, every request creates a new HTTP connection, issues the call, waits for the response, and closes the connection. This adds quite a bit of overhead to every call and lacks flexibility for features such as notifications.
In contrast, the websocket-based JSON-RPC interface provided by kaspad only uses a single connection that remains open and allows asynchronous bi-directional communication.
The websocket interface supports all of the same commands as HTTP POST, but they can be invoked without having to go through a connect/disconnect cycle for every call. In addition, the websocket interface provides other nice features such as the ability to register for asynchronous notifications of various events.
Synchronous vs Asynchronous API ¶
The client provides both a synchronous (blocking) and asynchronous API.
The synchronous (blocking) API is typically sufficient for most use cases. It works by issuing the RPC and blocking until the response is received. This allows straightforward code where you have the response as soon as the function returns.
The asynchronous API works on the concept of futures. When you invoke the async version of a command, it will quickly return an instance of a type that promises to provide the result of the RPC at some future time. In the background, the RPC call is issued and the result is stored in the returned instance. Invoking the Receive method on the returned instance will either return the result immediately if it has already arrived, or block until it has. This is useful since it provides the caller with greater control over concurrency.
Notifications ¶
The first important part of notifications is to realize that they will only work when connected via websockets. This should intuitively make sense because HTTP POST mode does not keep a connection open!
All notifications provided by kaspad require registration to opt-in. For example, if you want to be notified when blocks are added to the DAG, you register the via the NotifyBlocks (or NotifyBlocksAsync) function.
Notification Handlers ¶
Notifications are exposed by the client through the use of callback handlers which are setup via a NotificationHandlers instance that is specified by the caller when creating the client.
It is important that these notification handlers complete quickly since they are intentionally in the main read loop and will block further reads until they complete. This provides the caller with the flexibility to decide what to do when notifications are coming in faster than they are being handled.
In particular this means issuing a blocking RPC call from a callback handler will cause a deadlock as more server responses won't be read until the callback returns, but the callback would be waiting for a response. Thus, any additional RPCs must be issued an a completely decoupled manner.
Automatic Reconnection ¶
By default, when running in websockets mode, this client will automatically keep trying to reconnect to the RPC server should the connection be lost. There is a back-off in between each connection attempt until it reaches one try per minute. Once a connection is re-established, all previously registered notifications are automatically re-registered and any in-flight commands are re-issued. This means from the caller's perspective, the request simply takes longer to complete.
The caller may invoke the Shutdown method on the client to force the client to cease reconnect attempts and return ErrClientShutdown for all outstanding commands.
The automatic reconnection can be disabled by setting the DisableAutoReconnect flag to true in the connection config when creating the client.
Errors ¶
There are 3 categories of errors that will be returned throughout this package:
- Errors related to the client connection such as authentication, endpoint, disconnect, and shutdown
- Errors that occur before communicating with the remote RPC server such as command creation and marshaling errors or issues talking to the remote server
- Errors returned from the remote RPC server like unimplemented commands, nonexistent requested blocks and transactions, malformed data, and incorrect networks
The first category of errors are typically one of ErrInvalidAuth, ErrInvalidEndpoint, ErrClientDisconnect, or ErrClientShutdown.
NOTE: The ErrClientDisconnect will not be returned unless the DisableAutoReconnect flag is set since the client automatically handles reconnect by default as previously described.
The second category of errors typically indicates a programmer error and as such the type can vary, but usually will be best handled by simply showing/logging it.
The third category of errors, that is errors returned by the server, can be detected by type asserting the error in a *model.RPCError. For example, to detect if a command is unimplemented by the remote RPC server:
netTotals, err := client.GetNetTotals() if err != nil { var jErr *model.RPCError if errors.As(err, jErr) { switch jErr.Code { case model.ErrRPCUnimplemented: // Handle not implemented error // Handle other specific errors you care about } } // Log or otherwise handle the error knowing it was not one returned // from the remote RPC server. }
Example Usage ¶
The following full-blown client examples are in the examples directory:
- httppost Connects to a kaspa RPC server using HTTP POST mode with TLS disabled and gets the current block count
- websockets Connects to a kaspad RPC server using TLS-secured websockets, registers for block added notifications, and gets the current block count
Index ¶
- Variables
- func ConvertGetBlockTemplateResultToBlock(template *model.GetBlockTemplateResult) (*util.Block, error)
- func DisableLog()
- func UseLogger(backend *logger.Backend, level logger.Level)
- type AcceptedBlock
- type ChainBlock
- type Client
- func (c *Client) Connect(tries int) error
- func (c *Client) ConnectNode(host string) error
- func (c *Client) ConnectNodeAsync(host string) FutureAddNodeResult
- func (c *Client) DebugLevel(levelSpec string) (string, error)
- func (c *Client) DebugLevelAsync(levelSpec string) FutureDebugLevelResult
- func (c *Client) Disconnect()
- func (c *Client) Disconnected() bool
- func (c *Client) GetBlock(blockHash *daghash.Hash, subnetworkID *string) (*appmessage.MsgBlock, error)
- func (c *Client) GetBlockAsync(blockHash *daghash.Hash, subnetworkID *string) FutureGetBlockResult
- func (c *Client) GetBlockCount() (int64, error)
- func (c *Client) GetBlockCountAsync() FutureGetBlockCountResult
- func (c *Client) GetBlockDAGInfo() (*model.GetBlockDAGInfoResult, error)
- func (c *Client) GetBlockDAGInfoAsync() FutureGetBlockDAGInfoResult
- func (c *Client) GetBlockHeader(blockHash *daghash.Hash) (*appmessage.BlockHeader, error)
- func (c *Client) GetBlockHeaderAsync(blockHash *daghash.Hash) FutureGetBlockHeaderResult
- func (c *Client) GetBlockHeaderVerbose(blockHash *daghash.Hash) (*model.GetBlockHeaderVerboseResult, error)
- func (c *Client) GetBlockHeaderVerboseAsync(blockHash *daghash.Hash) FutureGetBlockHeaderVerboseResult
- func (c *Client) GetBlockTemplate(payAddress string, longPollID string) (*model.GetBlockTemplateResult, error)
- func (c *Client) GetBlockTemplateAsync(payAddress string, longPollID string) FutureGetBlockTemplateResult
- func (c *Client) GetBlockVerbose(blockHash *daghash.Hash, subnetworkID *string) (*model.GetBlockVerboseResult, error)
- func (c *Client) GetBlockVerboseAsync(blockHash *daghash.Hash, subnetworkID *string) FutureGetBlockVerboseResult
- func (c *Client) GetBlockVerboseTx(blockHash *daghash.Hash, subnetworkID *string) (*model.GetBlockVerboseResult, error)
- func (c *Client) GetBlockVerboseTxAsync(blockHash *daghash.Hash, subnetworkID *string) FutureGetBlockVerboseResult
- func (c *Client) GetBlocks(includeRawBlockData bool, includeVerboseBlockData bool, lowHash *string) (*model.GetBlocksResult, error)
- func (c *Client) GetBlocksAsync(includeRawBlockData bool, IncludeVerboseBlockData bool, lowHash *string) FutureGetBlocksResult
- func (c *Client) GetChainFromBlock(includeBlocks bool, startHash *string) (*model.GetChainFromBlockResult, error)
- func (c *Client) GetChainFromBlockAsync(includeBlocks bool, startHash *string) FutureGetChainFromBlockResult
- func (c *Client) GetConnectedPeerInfo() ([]model.GetConnectedPeerInfoResult, error)
- func (c *Client) GetConnectedPeerInfoAsync() FutureGetConnectedPeerInfo
- func (c *Client) GetConnectionCount() (int64, error)
- func (c *Client) GetConnectionCountAsync() FutureGetConnectionCountResult
- func (c *Client) GetCurrentNet() (appmessage.KaspaNet, error)
- func (c *Client) GetCurrentNetAsync() FutureGetCurrentNetResult
- func (c *Client) GetDifficulty() (float64, error)
- func (c *Client) GetDifficultyAsync() FutureGetDifficultyResult
- func (c *Client) GetHeaders(lowHash, highHash *daghash.Hash) ([]appmessage.BlockHeader, error)
- func (c *Client) GetHeadersAsync(lowHash, highHash *daghash.Hash) FutureGetHeadersResult
- func (c *Client) GetMempoolEntry(txHash string) (*model.GetMempoolEntryResult, error)
- func (c *Client) GetMempoolEntryAsync(txHash string) FutureGetMempoolEntryResult
- func (c *Client) GetNetTotals() (*model.GetNetTotalsResult, error)
- func (c *Client) GetNetTotalsAsync() FutureGetNetTotalsResult
- func (c *Client) GetPeerAddresses() (*model.GetPeerAddressesResult, error)
- func (c *Client) GetPeerAddressesAsync() FutureGetPeerAddresses
- func (c *Client) GetRawMempool() ([]*daghash.Hash, error)
- func (c *Client) GetRawMempoolAsync() FutureGetRawMempoolResult
- func (c *Client) GetRawMempoolVerbose() (map[string]model.GetRawMempoolVerboseResult, error)
- func (c *Client) GetRawMempoolVerboseAsync() FutureGetRawMempoolVerboseResult
- func (c *Client) GetSelectedTip() (*model.GetBlockVerboseResult, error)
- func (c *Client) GetSelectedTipAsync() FutureGetSelectedTipResult
- func (c *Client) GetSelectedTipHash() (*daghash.Hash, error)
- func (c *Client) GetSelectedTipHashAsync() FutureGetSelectedTipHashResult
- func (c *Client) GetSelectedTipVerboseAsync() FutureGetSelectedTipVerboseResult
- func (c *Client) GetSubnetwork(subnetworkID string) (*model.GetSubnetworkResult, error)
- func (c *Client) GetSubnetworkAsync(subnetworkID string) FutureGetSubnetworkResult
- func (c *Client) GetTopHeaders(highHash *daghash.Hash) ([]appmessage.BlockHeader, error)
- func (c *Client) GetTopHeadersAsync(highHash *daghash.Hash) FutureGetHeadersResult
- func (c *Client) GetTxOut(txHash *daghash.Hash, index uint32, mempool bool) (*model.GetTxOutResult, error)
- func (c *Client) GetTxOutAsync(txHash *daghash.Hash, index uint32, mempool bool) FutureGetTxOutResult
- func (c *Client) Host() string
- func (c *Client) LoadTxFilter(reload bool, addresses []util.Address, outpoints []appmessage.Outpoint) error
- func (c *Client) LoadTxFilterAsync(reload bool, addresses []util.Address, outpoints []appmessage.Outpoint) FutureLoadTxFilterResult
- func (c *Client) NextID() uint64
- func (c *Client) NotifyBlocks() error
- func (c *Client) NotifyBlocksAsync() FutureNotifyBlocksResult
- func (c *Client) NotifyChainChanges() error
- func (c *Client) NotifyChainChangesAsync() FutureNotifyBlocksResult
- func (c *Client) NotifyNewTransactions(verbose bool, subnetworkID *string) error
- func (c *Client) NotifyNewTransactionsAsync(verbose bool, subnetworkID *string) FutureNotifyNewTransactionsResult
- func (c *Client) Ping() error
- func (c *Client) PingAsync() FuturePingResult
- func (c *Client) RawRequest(method string, params []json.RawMessage) (json.RawMessage, error)
- func (c *Client) RawRequestAsync(method string, params []json.RawMessage) FutureRawResult
- func (c *Client) RescanBlocks(blockHashes []*daghash.Hash) ([]model.RescannedBlock, error)
- func (c *Client) RescanBlocksAsync(blockHashes []*daghash.Hash) FutureRescanBlocksResult
- func (c *Client) SendRawTransaction(tx *appmessage.MsgTx, allowHighFees bool) (*daghash.TxID, error)
- func (c *Client) SendRawTransactionAsync(tx *appmessage.MsgTx, allowHighFees bool) FutureSendRawTransactionResult
- func (c *Client) Session() (*model.SessionResult, error)
- func (c *Client) SessionAsync() FutureSessionResult
- func (c *Client) Shutdown()
- func (c *Client) SubmitBlock(block *util.Block, options *model.SubmitBlockOptions) error
- func (c *Client) SubmitBlockAsync(block *util.Block, options *model.SubmitBlockOptions) FutureSubmitBlockResult
- func (c *Client) Version() (map[string]model.VersionResult, error)
- func (c *Client) VersionAsync() FutureVersionResult
- func (c *Client) WaitForShutdown()
- type ConnConfig
- type FutureAddNodeResult
- type FutureDebugLevelResult
- type FutureGetBlockCountResult
- type FutureGetBlockDAGInfoResult
- type FutureGetBlockHashResult
- type FutureGetBlockHeaderResult
- type FutureGetBlockHeaderVerboseResult
- type FutureGetBlockResult
- type FutureGetBlockTemplateResult
- type FutureGetBlockVerboseResult
- type FutureGetBlocksResult
- type FutureGetChainFromBlockResult
- type FutureGetConnectedPeerInfo
- type FutureGetConnectionCountResult
- type FutureGetCurrentNetResult
- type FutureGetDifficultyResult
- type FutureGetHeadersResult
- type FutureGetMempoolEntryResult
- type FutureGetNetTotalsResult
- type FutureGetPeerAddresses
- type FutureGetRawMempoolResult
- type FutureGetRawMempoolVerboseResult
- type FutureGetSelectedTipHashResult
- type FutureGetSelectedTipResult
- type FutureGetSelectedTipVerboseResult
- type FutureGetSubnetworkResult
- type FutureGetTxOutResult
- type FutureLoadTxFilterResult
- type FutureNotifyBlocksResult
- type FutureNotifyChainChangesResult
- type FutureNotifyNewTransactionsResult
- type FuturePingResult
- type FutureRawResult
- type FutureRescanBlocksResult
- type FutureSendRawTransactionResult
- type FutureSessionResult
- type FutureSubmitBlockResult
- type FutureVersionResult
- type NotificationHandlers
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidAuth is an error to describe the condition where the client // is either unable to authenticate or the specified endpoint is // incorrect. ErrInvalidAuth = errors.New("authentication failure") // ErrInvalidEndpoint is an error to describe the condition where the // websocket handshake failed with the specified endpoint. ErrInvalidEndpoint = errors.New("the endpoint either does not support " + "websockets or does not exist") // ErrClientNotConnected is an error to describe the condition where a // websocket client has been created, but the connection was never // established. This condition differs from ErrClientDisconnect, which // represents an established connection that was lost. ErrClientNotConnected = errors.New("the client was never connected") // ErrClientDisconnect is an error to describe the condition where the // client has been disconnected from the RPC server. When the // DisableAutoReconnect option is not set, any outstanding futures // when a client disconnect occurs will return this error as will // any new requests. ErrClientDisconnect = errors.New("the client has been disconnected") // ErrClientShutdown is an error to describe the condition where the // client is either already shutdown, or in the process of shutting // down. Any outstanding futures when a client shutdown occurs will // return this error as will any new requests. ErrClientShutdown = errors.New("the client has been shutdown") // ErrNotWebsocketClient is an error to describe the condition of // calling a Client method intended for a websocket client when the // client has been configured to run in HTTP POST mode instead. ErrNotWebsocketClient = errors.New("client is not configured for " + "websockets") // ErrClientAlreadyConnected is an error to describe the condition where // a new client connection cannot be established due to a websocket // client having already connected to the RPC server. ErrClientAlreadyConnected = errors.New("websocket client has already " + "connected") // ErrResponseTimedOut is an error to describe the condition where // a response hasn't arrived before the expected timeout. ErrResponseTimedOut = errors.New("no response was receieved until the timeout") )
var ( // ErrWebsocketsRequired is an error to describe the condition where the // caller is trying to use a websocket-only feature, such as requesting // notifications or other websocket requests when the client is // configured to run in HTTP POST mode. ErrWebsocketsRequired = errors.New("a websocket connection is required " + "to use this feature") )
Functions ¶
func ConvertGetBlockTemplateResultToBlock ¶
func ConvertGetBlockTemplateResultToBlock(template *model.GetBlockTemplateResult) (*util.Block, error)
ConvertGetBlockTemplateResultToBlock Accepts a GetBlockTemplateResult and parses it into a Block
func DisableLog ¶
func DisableLog()
DisableLog disables all library log output. Logging output is disabled by default until UseLogger is called.
Types ¶
type AcceptedBlock ¶
AcceptedBlock models a block that is included in the blues of a selected chain block.
type ChainBlock ¶
type ChainBlock struct { Hash *daghash.Hash AcceptedBlocks []*AcceptedBlock }
ChainBlock models a block that is part of the selected parent chain.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents a kaspa RPC client which allows easy access to the various RPC methods available on a kaspa RPC server. Each of the wrapper functions handle the details of converting the passed and return types to and from the underlying JSON types which are required for the JSON-RPC invocations
The client provides each RPC in both synchronous (blocking) and asynchronous (non-blocking) forms. The asynchronous forms are based on the concept of futures where they return an instance of a type that promises to deliver the result of the invocation at some future time. Invoking the Receive method on the returned future will block until the result is available if it's not already.
func New ¶
func New(config *ConnConfig, ntfnHandlers *NotificationHandlers) (*Client, error)
New creates a new RPC client based on the provided connection configuration details. The notification handlers parameter may be nil if you are not interested in receiving notifications and will be ignored if the configuration is set to run in HTTP POST mode.
func (*Client) Connect ¶
Connect establishes the initial websocket connection. This is necessary when a client was created after setting the DisableConnectOnNew field of the Config struct.
Up to tries number of connections (each after an increasing backoff) will be tried if the connection can not be established. The special value of 0 indicates an unlimited number of connection attempts.
This method will error if the client is not configured for websockets, if the connection has already been established, or if none of the connection attempts were successful.
func (*Client) ConnectNode ¶
ConnectNode attempts to perform the passed command on the passed persistent peer. For example, it can be used to add or a remove a persistent peer, or to do a one time connection to a peer.
It may not be used to remove non-persistent peers.
func (*Client) ConnectNodeAsync ¶
func (c *Client) ConnectNodeAsync(host string) FutureAddNodeResult
ConnectNodeAsync returns an instance of a type that can be used to get the result of the RPC at some future time by invoking the Receive function on the returned instance.
See Connect for the blocking version and more details.
func (*Client) DebugLevel ¶
DebugLevel dynamically sets the debug logging level to the passed level specification.
The levelspec can be either a debug level or of the form:
<subsystem>=<level>,<subsystem2>=<level2>,...
Additionally, the special keyword 'show' can be used to get a list of the available subsystems.
func (*Client) DebugLevelAsync ¶
func (c *Client) DebugLevelAsync(levelSpec string) FutureDebugLevelResult
DebugLevelAsync returns an instance of a type that can be used to get the result of the RPC at some future time by invoking the Receive function on the returned instance.
See DebugLevel for the blocking version and more details.
func (*Client) Disconnect ¶
func (c *Client) Disconnect()
Disconnect disconnects the current websocket associated with the client. The connection will automatically be re-established unless the client was created with the DisableAutoReconnect flag.
This function has no effect when the client is running in HTTP POST mode.
func (*Client) Disconnected ¶
Disconnected returns whether or not the server is disconnected. If a websocket client was created but never connected, this also returns false.
func (*Client) GetBlock ¶
func (c *Client) GetBlock(blockHash *daghash.Hash, subnetworkID *string) (*appmessage.MsgBlock, error)
GetBlock returns a raw block from the server given its hash.
See GetBlockVerbose to retrieve a data structure with information about the block instead.
func (*Client) GetBlockAsync ¶
func (c *Client) GetBlockAsync(blockHash *daghash.Hash, subnetworkID *string) FutureGetBlockResult
GetBlockAsync returns an instance of a type that can be used to get the result of the RPC at some future time by invoking the Receive function on the returned instance.
See GetBlock for the blocking version and more details.
func (*Client) GetBlockCount ¶
GetBlockCount returns the number of blocks in the longest block dag.
func (*Client) GetBlockCountAsync ¶
func (c *Client) GetBlockCountAsync() FutureGetBlockCountResult
GetBlockCountAsync returns an instance of a type that can be used to get the result of the RPC at some future time by invoking the Receive function on the returned instance.
See GetBlockCount for the blocking version and more details.
func (*Client) GetBlockDAGInfo ¶
func (c *Client) GetBlockDAGInfo() (*model.GetBlockDAGInfoResult, error)
GetBlockDAGInfo returns information related to the processing state of various dag-specific details such as the current difficulty from the tip of the main dag.
func (*Client) GetBlockDAGInfoAsync ¶
func (c *Client) GetBlockDAGInfoAsync() FutureGetBlockDAGInfoResult
GetBlockDAGInfoAsync returns an instance of a type that can be used to get the result of the RPC at some future time by invoking the Receive function on the returned instance.
See GetBlockDAGInfo for the blocking version and more details.
func (*Client) GetBlockHeader ¶
func (c *Client) GetBlockHeader(blockHash *daghash.Hash) (*appmessage.BlockHeader, error)
GetBlockHeader returns the blockheader from the server given its hash.
See GetBlockHeaderVerbose to retrieve a data structure with information about the block instead.
func (*Client) GetBlockHeaderAsync ¶
func (c *Client) GetBlockHeaderAsync(blockHash *daghash.Hash) FutureGetBlockHeaderResult
GetBlockHeaderAsync returns an instance of a type that can be used to get the result of the RPC at some future time by invoking the Receive function on the returned instance.
See GetBlockHeader for the blocking version and more details.
func (*Client) GetBlockHeaderVerbose ¶
func (c *Client) GetBlockHeaderVerbose(blockHash *daghash.Hash) (*model.GetBlockHeaderVerboseResult, error)
GetBlockHeaderVerbose returns a data structure with information about the blockheader from the server given its hash.
See GetBlockHeader to retrieve a blockheader instead.
func (*Client) GetBlockHeaderVerboseAsync ¶
func (c *Client) GetBlockHeaderVerboseAsync(blockHash *daghash.Hash) FutureGetBlockHeaderVerboseResult
GetBlockHeaderVerboseAsync returns an instance of a type that can be used to get the result of the RPC at some future time by invoking the Receive function on the returned instance.
See GetBlockHeader for the blocking version and more details.
func (*Client) GetBlockTemplate ¶
func (c *Client) GetBlockTemplate(payAddress string, longPollID string) (*model.GetBlockTemplateResult, error)
GetBlockTemplate request a block template from the server, to mine upon
func (*Client) GetBlockTemplateAsync ¶
func (c *Client) GetBlockTemplateAsync(payAddress string, longPollID string) FutureGetBlockTemplateResult
GetBlockTemplateAsync returns an instance of a type that can be used to get the result of the RPC at some future time by invoking the Receive function on the returned instance.
See GetBlockTemplate for the blocking version and more details
func (*Client) GetBlockVerbose ¶
func (c *Client) GetBlockVerbose(blockHash *daghash.Hash, subnetworkID *string) (*model.GetBlockVerboseResult, error)
GetBlockVerbose returns a data structure from the server with information about a block given its hash.
See GetBlockVerboseTx to retrieve transaction data structures as well. See GetBlock to retrieve a raw block instead.
func (*Client) GetBlockVerboseAsync ¶
func (c *Client) GetBlockVerboseAsync(blockHash *daghash.Hash, subnetworkID *string) FutureGetBlockVerboseResult
GetBlockVerboseAsync returns an instance of a type that can be used to get the result of the RPC at some future time by invoking the Receive function on the returned instance.
See GetBlockVerbose for the blocking version and more details.
func (*Client) GetBlockVerboseTx ¶
func (c *Client) GetBlockVerboseTx(blockHash *daghash.Hash, subnetworkID *string) (*model.GetBlockVerboseResult, error)
GetBlockVerboseTx returns a data structure from the server with information about a block and its transactions given its hash.
See GetBlockVerbose if only transaction hashes are preferred. See GetBlock to retrieve a raw block instead.
func (*Client) GetBlockVerboseTxAsync ¶
func (c *Client) GetBlockVerboseTxAsync(blockHash *daghash.Hash, subnetworkID *string) FutureGetBlockVerboseResult
GetBlockVerboseTxAsync returns an instance of a type that can be used to get the result of the RPC at some future time by invoking the Receive function on the returned instance.
See GetBlockVerboseTx or the blocking version and more details.
func (*Client) GetBlocks ¶
func (c *Client) GetBlocks(includeRawBlockData bool, includeVerboseBlockData bool, lowHash *string) (*model.GetBlocksResult, error)
GetBlocks returns the blocks starting from lowHash up to the virtual ordered by blue score.
func (*Client) GetBlocksAsync ¶
func (c *Client) GetBlocksAsync(includeRawBlockData bool, IncludeVerboseBlockData bool, lowHash *string) FutureGetBlocksResult
GetBlocksAsync returns an instance of a type that can be used to get the result of the RPC at some future time by invoking the Receive function on the returned instance.
See GetBlocks for the blocking version and more details.
func (*Client) GetChainFromBlock ¶
func (c *Client) GetChainFromBlock(includeBlocks bool, startHash *string) (*model.GetChainFromBlockResult, error)
GetChainFromBlock returns the selected parent chain starting from startHash up to the virtual. If startHash is not in the selected parent chain, it goes down the DAG until it does reach a hash in the selected parent chain while collecting hashes into RemovedChainBlockHashes.
func (*Client) GetChainFromBlockAsync ¶
func (c *Client) GetChainFromBlockAsync(includeBlocks bool, startHash *string) FutureGetChainFromBlockResult
GetChainFromBlockAsync returns an instance of a type that can be used to get the result of the RPC at some future time by invoking the Receive function on the returned instance.
See GetChainFromBlock for the blocking version and more details.
func (*Client) GetConnectedPeerInfo ¶
func (c *Client) GetConnectedPeerInfo() ([]model.GetConnectedPeerInfoResult, error)
GetConnectedPeerInfo returns data about each connected network peer.
func (*Client) GetConnectedPeerInfoAsync ¶
func (c *Client) GetConnectedPeerInfoAsync() FutureGetConnectedPeerInfo
GetConnectedPeerInfoAsync returns an instance of a type that can be used to get the result of the RPC at some future time by invoking the Receive function on the returned instance.
See GetConnectedPeerInfo for the blocking version and more details.
func (*Client) GetConnectionCount ¶
GetConnectionCount returns the number of active connections to other peers.
func (*Client) GetConnectionCountAsync ¶
func (c *Client) GetConnectionCountAsync() FutureGetConnectionCountResult
GetConnectionCountAsync returns an instance of a type that can be used to get the result of the RPC at some future time by invoking the Receive function on the returned instance.
See GetConnectionCount for the blocking version and more details.
func (*Client) GetCurrentNet ¶
func (c *Client) GetCurrentNet() (appmessage.KaspaNet, error)
GetCurrentNet returns the network the server is running on.
func (*Client) GetCurrentNetAsync ¶
func (c *Client) GetCurrentNetAsync() FutureGetCurrentNetResult
GetCurrentNetAsync returns an instance of a type that can be used to get the result of the RPC at some future time by invoking the Receive function on the returned instance.
See GetCurrentNet for the blocking version and more details.
func (*Client) GetDifficulty ¶
GetDifficulty returns the proof-of-work difficulty as a multiple of the minimum difficulty.
func (*Client) GetDifficultyAsync ¶
func (c *Client) GetDifficultyAsync() FutureGetDifficultyResult
GetDifficultyAsync returns an instance of a type that can be used to get the result of the RPC at some future time by invoking the Receive function on the returned instance.
See GetDifficulty for the blocking version and more details.
func (*Client) GetHeaders ¶
func (c *Client) GetHeaders(lowHash, highHash *daghash.Hash) ([]appmessage.BlockHeader, error)
GetHeaders mimics the appmessage protocol getheaders and headers messages by returning all headers in the DAG after the first known block in the locators, up until a block hash matches highHash.
func (*Client) GetHeadersAsync ¶
func (c *Client) GetHeadersAsync(lowHash, highHash *daghash.Hash) FutureGetHeadersResult
GetHeadersAsync returns an instance of a type that can be used to get the result of the RPC at some future time by invoking the Receive function on the returned instance.
See GetHeaders for the blocking version and more details.
func (*Client) GetMempoolEntry ¶
func (c *Client) GetMempoolEntry(txHash string) (*model.GetMempoolEntryResult, error)
GetMempoolEntry returns a data structure with information about the transaction in the memory pool given its hash.
func (*Client) GetMempoolEntryAsync ¶
func (c *Client) GetMempoolEntryAsync(txHash string) FutureGetMempoolEntryResult
GetMempoolEntryAsync returns an instance of a type that can be used to get the result of the RPC at some future time by invoking the Receive function on the returned instance.
See GetMempoolEntry for the blocking version and more details.
func (*Client) GetNetTotals ¶
func (c *Client) GetNetTotals() (*model.GetNetTotalsResult, error)
GetNetTotals returns network traffic statistics.
func (*Client) GetNetTotalsAsync ¶
func (c *Client) GetNetTotalsAsync() FutureGetNetTotalsResult
GetNetTotalsAsync returns an instance of a type that can be used to get the result of the RPC at some future time by invoking the Receive function on the returned instance.
See GetNetTotals for the blocking version and more details.
func (*Client) GetPeerAddresses ¶
func (c *Client) GetPeerAddresses() (*model.GetPeerAddressesResult, error)
GetPeerAddresses returns data about each connected network peer.
func (*Client) GetPeerAddressesAsync ¶
func (c *Client) GetPeerAddressesAsync() FutureGetPeerAddresses
GetPeerAddressesAsync returns an instance of a type that can be used to get the result of the RPC at some future time by invoking the Receive function on the returned instance.
See GetPeerAddresses for the blocking version and more details.
func (*Client) GetRawMempool ¶
GetRawMempool returns the hashes of all transactions in the memory pool.
See GetRawMempoolVerbose to retrieve data structures with information about the transactions instead.
func (*Client) GetRawMempoolAsync ¶
func (c *Client) GetRawMempoolAsync() FutureGetRawMempoolResult
GetRawMempoolAsync returns an instance of a type that can be used to get the result of the RPC at some future time by invoking the Receive function on the returned instance.
See GetRawMempool for the blocking version and more details.
func (*Client) GetRawMempoolVerbose ¶
func (c *Client) GetRawMempoolVerbose() (map[string]model.GetRawMempoolVerboseResult, error)
GetRawMempoolVerbose returns a map of transaction hashes to an associated data structure with information about the transaction for all transactions in the memory pool.
See GetRawMempool to retrieve only the transaction hashes instead.
func (*Client) GetRawMempoolVerboseAsync ¶
func (c *Client) GetRawMempoolVerboseAsync() FutureGetRawMempoolVerboseResult
GetRawMempoolVerboseAsync returns an instance of a type that can be used to get the result of the RPC at some future time by invoking the Receive function on the returned instance.
See GetRawMempoolVerbose for the blocking version and more details.
func (*Client) GetSelectedTip ¶
func (c *Client) GetSelectedTip() (*model.GetBlockVerboseResult, error)
GetSelectedTip returns the block of the selected DAG tip
func (*Client) GetSelectedTipAsync ¶
func (c *Client) GetSelectedTipAsync() FutureGetSelectedTipResult
GetSelectedTipAsync returns an instance of a type that can be used to get the result of the RPC at some future time by invoking the Receive function on the returned instance.
See GetSelectedTip for the blocking version and more details.
func (*Client) GetSelectedTipHash ¶
GetSelectedTipHash returns the hash of the selected tip of the Block DAG.
func (*Client) GetSelectedTipHashAsync ¶
func (c *Client) GetSelectedTipHashAsync() FutureGetSelectedTipHashResult
GetSelectedTipHashAsync returns an instance of a type that can be used to get the result of the RPC at some future time by invoking the Receive function on the returned instance.
See GetSelectedTipHash for the blocking version and more details.
func (*Client) GetSelectedTipVerboseAsync ¶
func (c *Client) GetSelectedTipVerboseAsync() FutureGetSelectedTipVerboseResult
GetSelectedTipVerboseAsync returns an instance of a type that can be used to get the result of the RPC at some future time by invoking the Receive function on the returned instance.
See GeSelectedTipBlockVerbose for the blocking version and more details.
func (*Client) GetSubnetwork ¶
func (c *Client) GetSubnetwork(subnetworkID string) (*model.GetSubnetworkResult, error)
GetSubnetwork provides information about a subnetwork given its ID.
func (*Client) GetSubnetworkAsync ¶
func (c *Client) GetSubnetworkAsync(subnetworkID string) FutureGetSubnetworkResult
GetSubnetworkAsync returns an instance of a type that can be used to get the result of the RPC at some future time by invoking the Receive function on the returned instance.
See GetSubnetwork for the blocking version and more details.
func (*Client) GetTopHeaders ¶
func (c *Client) GetTopHeaders(highHash *daghash.Hash) ([]appmessage.BlockHeader, error)
GetTopHeaders sends a getTopHeaders rpc command to the server.
func (*Client) GetTopHeadersAsync ¶
func (c *Client) GetTopHeadersAsync(highHash *daghash.Hash) FutureGetHeadersResult
GetTopHeadersAsync returns an instance of a type that can be used to get the result of the RPC at some future time by invoking the Receive function on the returned instance.
See GetTopHeaders for the blocking version and more details.
func (*Client) GetTxOut ¶
func (c *Client) GetTxOut(txHash *daghash.Hash, index uint32, mempool bool) (*model.GetTxOutResult, error)
GetTxOut returns the transaction output info if it's unspent and nil, otherwise.
func (*Client) GetTxOutAsync ¶
func (c *Client) GetTxOutAsync(txHash *daghash.Hash, index uint32, mempool bool) FutureGetTxOutResult
GetTxOutAsync returns an instance of a type that can be used to get the result of the RPC at some future time by invoking the Receive function on the returned instance.
See GetTxOut for the blocking version and more details.
func (*Client) LoadTxFilter ¶
func (c *Client) LoadTxFilter(reload bool, addresses []util.Address, outpoints []appmessage.Outpoint) error
LoadTxFilter loads, reloads, or adds data to a websocket client's transaction filter. The filter is consistently updated based on inspected transactions during mempool acceptance, block acceptance, and for all rescanned blocks.
func (*Client) LoadTxFilterAsync ¶
func (c *Client) LoadTxFilterAsync(reload bool, addresses []util.Address, outpoints []appmessage.Outpoint) FutureLoadTxFilterResult
LoadTxFilterAsync returns an instance of a type that can be used to get the result of the RPC at some future time by invoking the Receive function on the returned instance.
See LoadTxFilter for the blocking version and more details.
func (*Client) NextID ¶
NextID returns the next id to be used when sending a JSON-RPC message. This ID allows responses to be associated with particular requests per the JSON-RPC specification. Typically the consumer of the client does not need to call this function, however, if a custom request is being created and used this function should be used to ensure the ID is unique amongst all requests being made.
func (*Client) NotifyBlocks ¶
NotifyBlocks registers the client to receive notifications when blocks are connected to the DAG. The notifications are delivered to the notification handlers associated with the client. Calling this function has no effect if there are no notification handlers and will result in an error if the client is configured to run in HTTP POST mode.
The notifications delivered as a result of this call will be via OnBlockAdded
func (*Client) NotifyBlocksAsync ¶
func (c *Client) NotifyBlocksAsync() FutureNotifyBlocksResult
NotifyBlocksAsync returns an instance of a type that can be used to get the result of the RPC at some future time by invoking the Receive function on the returned instance.
See NotifyBlocks for the blocking version and more details.
func (*Client) NotifyChainChanges ¶
NotifyChainChanges registers the client to receive notifications when the selected parent chain changes. The notifications are delivered to the notification handlers associated with the client. Calling this function has no effect if there are no notification handlers and will result in an error if the client is configured to run in HTTP POST mode.
The notifications delivered as a result of this call will be via OnBlockAdded
func (*Client) NotifyChainChangesAsync ¶
func (c *Client) NotifyChainChangesAsync() FutureNotifyBlocksResult
NotifyChainChangesAsync returns an instance of a type that can be used to get the result of the RPC at some future time by invoking the Receive function on the returned instance.
See NotifyChainChanges for the blocking version and more details.
func (*Client) NotifyNewTransactions ¶
NotifyNewTransactions registers the client to receive notifications every time a new transaction is accepted to the memory pool. The notifications are delivered to the notification handlers associated with the client. Calling this function has no effect if there are no notification handlers and will result in an error if the client is configured to run in HTTP POST mode.
The notifications delivered as a result of this call will be via one of OnTxAccepted (when verbose is false) or OnTxAcceptedVerbose (when verbose is true).
func (*Client) NotifyNewTransactionsAsync ¶
func (c *Client) NotifyNewTransactionsAsync(verbose bool, subnetworkID *string) FutureNotifyNewTransactionsResult
NotifyNewTransactionsAsync returns an instance of a type that can be used to get the result of the RPC at some future time by invoking the Receive function on the returned instance.
See NotifyNewTransactionsAsync for the blocking version and more details.
func (*Client) Ping ¶
Ping queues a ping to be sent to each connected peer.
Use the GetConnectedPeerInfo function and examine the PingTime and PingWait fields to access the ping times.
func (*Client) PingAsync ¶
func (c *Client) PingAsync() FuturePingResult
PingAsync returns an instance of a type that can be used to get the result of the RPC at some future time by invoking the Receive function on the returned instance.
See Ping for the blocking version and more details.
func (*Client) RawRequest ¶
func (c *Client) RawRequest(method string, params []json.RawMessage) (json.RawMessage, error)
RawRequest allows the caller to send a raw or custom request to the server. This method may be used to send and receive requests and responses for requests that are not handled by this client package, or to proxy partially unmarshaled requests to another JSON-RPC server if a request cannot be handled directly.
func (*Client) RawRequestAsync ¶
func (c *Client) RawRequestAsync(method string, params []json.RawMessage) FutureRawResult
RawRequestAsync returns an instance of a type that can be used to get the result of a custom RPC request at some future time by invoking the Receive function on the returned instance.
See RawRequest for the blocking version and more details.
func (*Client) RescanBlocks ¶
RescanBlocks rescans the blocks identified by blockHashes, in order, using the client's loaded transaction filter. The blocks do not need to be on the main dag, but they do need to be adjacent to each other.
func (*Client) RescanBlocksAsync ¶
func (c *Client) RescanBlocksAsync(blockHashes []*daghash.Hash) FutureRescanBlocksResult
RescanBlocksAsync returns an instance of a type that can be used to get the result of the RPC at some future time by invoking the Receive function on the returned instance.
See RescanBlocks for the blocking version and more details.
func (*Client) SendRawTransaction ¶
func (c *Client) SendRawTransaction(tx *appmessage.MsgTx, allowHighFees bool) (*daghash.TxID, error)
SendRawTransaction submits the encoded transaction to the server which will then relay it to the network.
func (*Client) SendRawTransactionAsync ¶
func (c *Client) SendRawTransactionAsync(tx *appmessage.MsgTx, allowHighFees bool) FutureSendRawTransactionResult
SendRawTransactionAsync returns an instance of a type that can be used to get the result of the RPC at some future time by invoking the Receive function on the returned instance.
See SendRawTransaction for the blocking version and more details.
func (*Client) Session ¶
func (c *Client) Session() (*model.SessionResult, error)
Session returns details regarding a websocket client's current connection.
This RPC requires the client to be running in websocket mode.
func (*Client) SessionAsync ¶
func (c *Client) SessionAsync() FutureSessionResult
SessionAsync returns an instance of a type that can be used to get the result of the RPC at some future time by invoking the Receive function on the returned instance.
See Session for the blocking version and more details.
func (*Client) Shutdown ¶
func (c *Client) Shutdown()
Shutdown shuts down the client by disconnecting any connections associated with the client and, when automatic reconnect is enabled, preventing future attempts to reconnect. It also stops all goroutines.
func (*Client) SubmitBlock ¶
SubmitBlock attempts to submit a new block into the kaspa network.
func (*Client) SubmitBlockAsync ¶
func (c *Client) SubmitBlockAsync(block *util.Block, options *model.SubmitBlockOptions) FutureSubmitBlockResult
SubmitBlockAsync returns an instance of a type that can be used to get the result of the RPC at some future time by invoking the Receive function on the returned instance.
See SubmitBlock for the blocking version and more details.
func (*Client) Version ¶
func (c *Client) Version() (map[string]model.VersionResult, error)
Version returns information about the server's JSON-RPC API versions.
func (*Client) VersionAsync ¶
func (c *Client) VersionAsync() FutureVersionResult
VersionAsync returns an instance of a type that can be used to get the result of the RPC at some future time by invoking the Receive function on the returned instance.
See Version for the blocking version and more details.
func (*Client) WaitForShutdown ¶
func (c *Client) WaitForShutdown()
WaitForShutdown blocks until the client goroutines are stopped and the connection is closed.
type ConnConfig ¶
type ConnConfig struct { // Host is the IP address and port of the RPC server you want to connect // to. Host string // Endpoint is the websocket endpoint on the RPC server. This is // typically "ws". Endpoint string // User is the username to use to authenticate to the RPC server. User string // Pass is the passphrase to use to authenticate to the RPC server. Pass string // DisableTLS specifies whether transport layer security should be // disabled. It is recommended to always use TLS if the RPC server // supports it as otherwise your username and password is sent across // the appmessage in cleartext. DisableTLS bool // Certificates are the bytes for a PEM-encoded certificate chain used // for the TLS connection. It has no effect if the DisableTLS parameter // is true. Certificates []byte // Proxy specifies to connect through a SOCKS 5 proxy server. It may // be an empty string if a proxy is not required. Proxy string // ProxyUser is an optional username to use for the proxy server if it // requires authentication. It has no effect if the Proxy parameter // is not set. ProxyUser string // ProxyPass is an optional password to use for the proxy server if it // requires authentication. It has no effect if the Proxy parameter // is not set. ProxyPass string // DisableAutoReconnect specifies the client should not automatically // try to reconnect to the server when it has been disconnected. DisableAutoReconnect bool // DisableConnectOnNew specifies that a websocket client connection // should not be tried when creating the client with New. Instead, the // client is created and returned unconnected, and Connect must be // called manually. DisableConnectOnNew bool // HTTPPostMode instructs the client to run using multiple independent // connections issuing HTTP POST requests instead of using the default // of websockets. Websockets are generally preferred as some of the // features of the client such notifications only work with websockets, // however, not all servers support the websocket extensions, so this // flag can be set to true to use basic HTTP POST requests instead. HTTPPostMode bool // RequestTimeout is the time it'll take for a request to timeout if // it doesn't get a response. RequestTimeout time.Duration // ConnectionTimeout is the time it'll take for to try to connect // to the RPC server before the connection times out. ConnectionTimeout time.Duration }
ConnConfig describes the connection configuration parameters for the client. This
type FutureAddNodeResult ¶
type FutureAddNodeResult chan *response
FutureAddNodeResult is a future promise to deliver the result of an AddNodeAsync RPC invocation (or an applicable error).
func (FutureAddNodeResult) Receive ¶
func (r FutureAddNodeResult) Receive() error
Receive waits for the response promised by the future and returns an error if any occurred when performing the specified command.
type FutureDebugLevelResult ¶
type FutureDebugLevelResult chan *response
FutureDebugLevelResult is a future promise to deliver the result of a DebugLevelAsync RPC invocation (or an applicable error).
func (FutureDebugLevelResult) Receive ¶
func (r FutureDebugLevelResult) Receive() (string, error)
Receive waits for the response promised by the future and returns the result of setting the debug logging level to the passed level specification or the list of of the available subsystems for the special keyword 'show'.
type FutureGetBlockCountResult ¶
type FutureGetBlockCountResult chan *response
FutureGetBlockCountResult is a future promise to deliver the result of a GetBlockCountAsync RPC invocation (or an applicable error).
func (FutureGetBlockCountResult) Receive ¶
func (r FutureGetBlockCountResult) Receive() (int64, error)
Receive waits for the response promised by the future and returns the number of blocks in the longest block dag.
type FutureGetBlockDAGInfoResult ¶
type FutureGetBlockDAGInfoResult chan *response
FutureGetBlockDAGInfoResult is a promise to deliver the result of a GetBlockDAGInfoAsync RPC invocation (or an applicable error).
func (FutureGetBlockDAGInfoResult) Receive ¶
func (r FutureGetBlockDAGInfoResult) Receive() (*model.GetBlockDAGInfoResult, error)
Receive waits for the response promised by the future and returns dag info result provided by the server.
type FutureGetBlockHashResult ¶
type FutureGetBlockHashResult chan *response
FutureGetBlockHashResult is a future promise to deliver the result of a GetBlockHashAsync RPC invocation (or an applicable error).
type FutureGetBlockHeaderResult ¶
type FutureGetBlockHeaderResult chan *response
FutureGetBlockHeaderResult is a future promise to deliver the result of a GetBlockHeaderAsync RPC invocation (or an applicable error).
func (FutureGetBlockHeaderResult) Receive ¶
func (r FutureGetBlockHeaderResult) Receive() (*appmessage.BlockHeader, error)
Receive waits for the response promised by the future and returns the blockheader requested from the server given its hash.
type FutureGetBlockHeaderVerboseResult ¶
type FutureGetBlockHeaderVerboseResult chan *response
FutureGetBlockHeaderVerboseResult is a future promise to deliver the result of a GetBlockAsync RPC invocation (or an applicable error).
func (FutureGetBlockHeaderVerboseResult) Receive ¶
func (r FutureGetBlockHeaderVerboseResult) Receive() (*model.GetBlockHeaderVerboseResult, error)
Receive waits for the response promised by the future and returns the data structure of the blockheader requested from the server given its hash.
type FutureGetBlockResult ¶
type FutureGetBlockResult chan *response
FutureGetBlockResult is a future promise to deliver the result of a GetBlockAsync RPC invocation (or an applicable error).
func (FutureGetBlockResult) Receive ¶
func (r FutureGetBlockResult) Receive() (*appmessage.MsgBlock, error)
Receive waits for the response promised by the future and returns the raw block requested from the server given its hash.
type FutureGetBlockTemplateResult ¶
type FutureGetBlockTemplateResult chan *response
FutureGetBlockTemplateResult is a future promise to deliver the result of a GetBlockTemplate RPC invocation (or an applicable error).
func (FutureGetBlockTemplateResult) Receive ¶
func (r FutureGetBlockTemplateResult) Receive() (*model.GetBlockTemplateResult, error)
Receive waits for the response promised by the future and returns an error if any occurred when submitting the block.
type FutureGetBlockVerboseResult ¶
type FutureGetBlockVerboseResult chan *response
FutureGetBlockVerboseResult is a future promise to deliver the result of a GetBlockVerboseAsync RPC invocation (or an applicable error).
func (FutureGetBlockVerboseResult) Receive ¶
func (r FutureGetBlockVerboseResult) Receive() (*model.GetBlockVerboseResult, error)
Receive waits for the response promised by the future and returns the data structure from the server with information about the requested block.
type FutureGetBlocksResult ¶
type FutureGetBlocksResult chan *response
FutureGetBlocksResult is a future promise to deliver the result of a GetBlocksAsync RPC invocation (or an applicable error).
func (FutureGetBlocksResult) Receive ¶
func (r FutureGetBlocksResult) Receive() (*model.GetBlocksResult, error)
Receive waits for the response promised by the future and returns the blocks starting from lowHash up to the virtual ordered by blue score.
type FutureGetChainFromBlockResult ¶
type FutureGetChainFromBlockResult chan *response
FutureGetChainFromBlockResult is a future promise to deliver the result of a GetChainFromBlockAsync RPC invocation (or an applicable error).
func (FutureGetChainFromBlockResult) Receive ¶
func (r FutureGetChainFromBlockResult) Receive() (*model.GetChainFromBlockResult, error)
Receive waits for the response promised by the future and returns the selected parent chain starting from startHash up to the virtual. If startHash is not in the selected parent chain, it goes down the DAG until it does reach a hash in the selected parent chain while collecting hashes into RemovedChainBlockHashes.
type FutureGetConnectedPeerInfo ¶
type FutureGetConnectedPeerInfo chan *response
FutureGetConnectedPeerInfo is a future promise to deliver the result of a GetConnectedPeerInfoAsync RPC invocation (or an applicable error).
func (FutureGetConnectedPeerInfo) Receive ¶
func (r FutureGetConnectedPeerInfo) Receive() ([]model.GetConnectedPeerInfoResult, error)
Receive waits for the response promised by the future and returns data about each connected network peer.
type FutureGetConnectionCountResult ¶
type FutureGetConnectionCountResult chan *response
FutureGetConnectionCountResult is a future promise to deliver the result of a GetConnectionCountAsync RPC invocation (or an applicable error).
func (FutureGetConnectionCountResult) Receive ¶
func (r FutureGetConnectionCountResult) Receive() (int64, error)
Receive waits for the response promised by the future and returns the number of active connections to other peers.
type FutureGetCurrentNetResult ¶
type FutureGetCurrentNetResult chan *response
FutureGetCurrentNetResult is a future promise to deliver the result of a GetCurrentNetAsync RPC invocation (or an applicable error).
func (FutureGetCurrentNetResult) Receive ¶
func (r FutureGetCurrentNetResult) Receive() (appmessage.KaspaNet, error)
Receive waits for the response promised by the future and returns the network the server is running on.
type FutureGetDifficultyResult ¶
type FutureGetDifficultyResult chan *response
FutureGetDifficultyResult is a future promise to deliver the result of a GetDifficultyAsync RPC invocation (or an applicable error).
func (FutureGetDifficultyResult) Receive ¶
func (r FutureGetDifficultyResult) Receive() (float64, error)
Receive waits for the response promised by the future and returns the proof-of-work difficulty as a multiple of the minimum difficulty.
type FutureGetHeadersResult ¶
type FutureGetHeadersResult chan *response
FutureGetHeadersResult is a future promise to deliver the result of a getheaders RPC invocation (or an applicable error).
func (FutureGetHeadersResult) Receive ¶
func (r FutureGetHeadersResult) Receive() ([]appmessage.BlockHeader, error)
Receive waits for the response promised by the future and returns the getheaders result.
type FutureGetMempoolEntryResult ¶
type FutureGetMempoolEntryResult chan *response
FutureGetMempoolEntryResult is a future promise to deliver the result of a GetMempoolEntryAsync RPC invocation (or an applicable error).
func (FutureGetMempoolEntryResult) Receive ¶
func (r FutureGetMempoolEntryResult) Receive() (*model.GetMempoolEntryResult, error)
Receive waits for the response promised by the future and returns a data structure with information about the transaction in the memory pool given its hash.
type FutureGetNetTotalsResult ¶
type FutureGetNetTotalsResult chan *response
FutureGetNetTotalsResult is a future promise to deliver the result of a GetNetTotalsAsync RPC invocation (or an applicable error).
func (FutureGetNetTotalsResult) Receive ¶
func (r FutureGetNetTotalsResult) Receive() (*model.GetNetTotalsResult, error)
Receive waits for the response promised by the future and returns network traffic statistics.
type FutureGetPeerAddresses ¶
type FutureGetPeerAddresses chan *response
FutureGetPeerAddresses is a future promise to deliver the result of a GetPeerAddresses RPC invocation (or an applicable error).
func (FutureGetPeerAddresses) Receive ¶
func (r FutureGetPeerAddresses) Receive() (*model.GetPeerAddressesResult, error)
Receive waits for the response promised by the future and returns data about peer addresses.
type FutureGetRawMempoolResult ¶
type FutureGetRawMempoolResult chan *response
FutureGetRawMempoolResult is a future promise to deliver the result of a GetRawMempoolAsync RPC invocation (or an applicable error).
type FutureGetRawMempoolVerboseResult ¶
type FutureGetRawMempoolVerboseResult chan *response
FutureGetRawMempoolVerboseResult is a future promise to deliver the result of a GetRawMempoolVerboseAsync RPC invocation (or an applicable error).
func (FutureGetRawMempoolVerboseResult) Receive ¶
func (r FutureGetRawMempoolVerboseResult) Receive() (map[string]model.GetRawMempoolVerboseResult, error)
Receive waits for the response promised by the future and returns a map of transaction hashes to an associated data structure with information about the transaction for all transactions in the memory pool.
type FutureGetSelectedTipHashResult ¶
type FutureGetSelectedTipHashResult chan *response
FutureGetSelectedTipHashResult is a future promise to deliver the result of a GetSelectedTipAsync RPC invocation (or an applicable error).
type FutureGetSelectedTipResult ¶
type FutureGetSelectedTipResult chan *response
FutureGetSelectedTipResult is a future promise to deliver the result of a GetSelectedTipAsync RPC invocation (or an applicable error).
func (FutureGetSelectedTipResult) Receive ¶
func (r FutureGetSelectedTipResult) Receive() (*appmessage.MsgBlock, error)
Receive waits for the response promised by the future and returns the selected tip block.
type FutureGetSelectedTipVerboseResult ¶
type FutureGetSelectedTipVerboseResult chan *response
FutureGetSelectedTipVerboseResult is a future promise to deliver the result of a GetSelectedTipVerboseAsync RPC invocation (or an applicable error).
func (FutureGetSelectedTipVerboseResult) Receive ¶
func (r FutureGetSelectedTipVerboseResult) Receive() (*model.GetBlockVerboseResult, error)
Receive waits for the response promised by the future and returns the data structure from the server with information about the requested block.
type FutureGetSubnetworkResult ¶
type FutureGetSubnetworkResult chan *response
FutureGetSubnetworkResult is a future promise to deliver the result of a GetSubnetworkAsync RPC invocation (or an applicable error).
func (FutureGetSubnetworkResult) Receive ¶
func (r FutureGetSubnetworkResult) Receive() (*model.GetSubnetworkResult, error)
Receive waits for the response promised by the future and returns information regarding the requested subnetwork
type FutureGetTxOutResult ¶
type FutureGetTxOutResult chan *response
FutureGetTxOutResult is a future promise to deliver the result of a GetTxOutAsync RPC invocation (or an applicable error).
func (FutureGetTxOutResult) Receive ¶
func (r FutureGetTxOutResult) Receive() (*model.GetTxOutResult, error)
Receive waits for the response promised by the future and returns a transaction given its hash.
type FutureLoadTxFilterResult ¶
type FutureLoadTxFilterResult chan *response
FutureLoadTxFilterResult is a future promise to deliver the result of a LoadTxFilterAsync RPC invocation (or an applicable error).
func (FutureLoadTxFilterResult) Receive ¶
func (r FutureLoadTxFilterResult) Receive() error
Receive waits for the response promised by the future and returns an error if the registration was not successful.
type FutureNotifyBlocksResult ¶
type FutureNotifyBlocksResult chan *response
FutureNotifyBlocksResult is a future promise to deliver the result of a NotifyBlocksAsync RPC invocation (or an applicable error).
func (FutureNotifyBlocksResult) Receive ¶
func (r FutureNotifyBlocksResult) Receive() error
Receive waits for the response promised by the future and returns an error if the registration was not successful.
type FutureNotifyChainChangesResult ¶
type FutureNotifyChainChangesResult chan *response
FutureNotifyChainChangesResult is a future promise to deliver the result of a NotifyChainChangesAsync RPC invocation (or an applicable error).
func (FutureNotifyChainChangesResult) Receive ¶
func (r FutureNotifyChainChangesResult) Receive() error
Receive waits for the response promised by the future and returns an error if the registration was not successful.
type FutureNotifyNewTransactionsResult ¶
type FutureNotifyNewTransactionsResult chan *response
FutureNotifyNewTransactionsResult is a future promise to deliver the result of a NotifyNewTransactionsAsync RPC invocation (or an applicable error).
func (FutureNotifyNewTransactionsResult) Receive ¶
func (r FutureNotifyNewTransactionsResult) Receive() error
Receive waits for the response promised by the future and returns an error if the registration was not successful.
type FuturePingResult ¶
type FuturePingResult chan *response
FuturePingResult is a future promise to deliver the result of a PingAsync RPC invocation (or an applicable error).
func (FuturePingResult) Receive ¶
func (r FuturePingResult) Receive() error
Receive waits for the response promised by the future and returns the result of queueing a ping to be sent to each connected peer.
type FutureRawResult ¶
type FutureRawResult chan *response
FutureRawResult is a future promise to deliver the result of a RawRequest RPC invocation (or an applicable error).
func (FutureRawResult) Receive ¶
func (r FutureRawResult) Receive() (json.RawMessage, error)
Receive waits for the response promised by the future and returns the raw response, or an error if the request was unsuccessful.
type FutureRescanBlocksResult ¶
type FutureRescanBlocksResult chan *response
FutureRescanBlocksResult is a future promise to deliver the result of a RescanBlocksAsync RPC invocation (or an applicable error).
func (FutureRescanBlocksResult) Receive ¶
func (r FutureRescanBlocksResult) Receive() ([]model.RescannedBlock, error)
Receive waits for the response promised by the future and returns the discovered rescanblocks data.
type FutureSendRawTransactionResult ¶
type FutureSendRawTransactionResult chan *response
FutureSendRawTransactionResult is a future promise to deliver the result of a SendRawTransactionAsync RPC invocation (or an applicable error).
type FutureSessionResult ¶
type FutureSessionResult chan *response
FutureSessionResult is a future promise to deliver the result of a SessionAsync RPC invocation (or an applicable error).
func (FutureSessionResult) Receive ¶
func (r FutureSessionResult) Receive() (*model.SessionResult, error)
Receive waits for the response promised by the future and returns the session result.
type FutureSubmitBlockResult ¶
type FutureSubmitBlockResult chan *response
FutureSubmitBlockResult is a future promise to deliver the result of a SubmitBlockAsync RPC invocation (or an applicable error).
func (FutureSubmitBlockResult) Receive ¶
func (r FutureSubmitBlockResult) Receive() error
Receive waits for the response promised by the future and returns an error if any occurred when submitting the block.
type FutureVersionResult ¶
type FutureVersionResult chan *response
FutureVersionResult is a future promise to deliver the result of a version RPC invocation (or an applicable error).
func (FutureVersionResult) Receive ¶
func (r FutureVersionResult) Receive() (map[string]model.VersionResult, error)
Receive waits for the response promised by the future and returns the version result.
type NotificationHandlers ¶
type NotificationHandlers struct { // OnClientConnected is invoked when the client connects or reconnects // to the RPC server. This callback is run async with the rest of the // notification handlers, and is safe for blocking client requests. OnClientConnected func() // OnBlockAdded is invoked when a block is connected to the DAG. // It will only be invoked if a preceding call to NotifyBlocks has been made // to register for the notification and the function is non-nil. // // NOTE: Deprecated. Use OnFilteredBlockAdded instead. OnBlockAdded func(hash *daghash.Hash, height int32, t mstime.Time) // OnFilteredBlockAdded is invoked when a block is connected to the // bloackDAG. It will only be invoked if a preceding call to // NotifyBlocks has been made to register for the notification and the // function is non-nil. Its parameters differ from OnBlockAdded: it // receives the block's blueScore, header, and relevant transactions. OnFilteredBlockAdded func(blueScore uint64, header *appmessage.BlockHeader, txs []*util.Tx) // OnChainChanged is invoked when the selected parent chain of the // DAG had changed. It will only be invoked if a preceding call to // NotifyChainChanges has been made to register for the notification and the // function is non-nil. OnChainChanged func(removedChainBlockHashes []*daghash.Hash, addedChainBlocks []*ChainBlock) // OnRelevantTxAccepted is invoked when an unmined transaction passes // the client's transaction filter. OnRelevantTxAccepted func(transaction []byte) // OnTxAccepted is invoked when a transaction is accepted into the // memory pool. It will only be invoked if a preceding call to // NotifyNewTransactions with the verbose flag set to false has been // made to register for the notification and the function is non-nil. OnTxAccepted func(hash *daghash.Hash, amount util.Amount) // OnTxAccepted is invoked when a transaction is accepted into the // memory pool. It will only be invoked if a preceding call to // NotifyNewTransactions with the verbose flag set to true has been // made to register for the notification and the function is non-nil. OnTxAcceptedVerbose func(txDetails *model.TxRawResult) // OnUnknownNotification is invoked when an unrecognized notification // is received. This typically means the notification handling code // for this package needs to be updated for a new notification type or // the caller is using a custom notification this package does not know // about. OnUnknownNotification func(method string, params []json.RawMessage) }
NotificationHandlers defines callback function pointers to invoke with notifications. Since all of the functions are nil by default, all notifications are effectively ignored until their handlers are set to a concrete callback.