Documentation ¶
Overview ¶
Package rpcclient implements a websocket-enabled Bitcoin JSON-RPC client.
Overview ¶
This client provides a robust and easy to use client for interfacing with a Bitcoin RPC server that uses a pktd/bitcoin core compatible Bitcoin JSON-RPC API. This client has been tested with pktd (https://github.com/pkt-cash/pktd), pktwallet (https://github.com/pkt-cash/pktwallet), and bitcoin core (https://github.com/bitcoin).
In addition to the compatible standard HTTP POST JSON-RPC API, pktd and pktwallet provide 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. In practice, this currently means it assumes you are talking to pktd or pktwallet by default. However, configuration options are provided to fall back to HTTP POST and disable TLS to support talking with inferior bitcoin core style RPC servers.
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 pktd and pktwallet 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 pktd require registration to opt-in. For example, if you want to be notified when funds are received by a set of addresses, you register the addresses via the NotifyReceived (or NotifyReceivedAsync) 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.
Minor RPC Server Differences and Chain/Wallet Separation
Some of the commands are extensions specific to a particular RPC server. For example, the DebugLevel call is an extension only provided by pktd (and pktwallet passthrough). Therefore if you call one of these commands against an RPC server that doesn't provide them, you will get an unimplemented error from the server. An effort has been made to call out which commmands are extensions in their documentation.
Also, it is important to realize that pktd intentionally separates the wallet functionality into a separate process named pktwallet. This means if you are connected to the pktd RPC server directly, only the RPCs which are related to chain services will be available. Depending on your application, you might only need chain-related RPCs. In contrast, pktwallet provides pass through treatment for chain-related RPCs, so it supports them in addition to wallet-related RPCs.
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 *btcjson.RPCError. For example, to detect if a command is unimplemented by the remote RPC server:
amount, err := client.GetBalance("") if err != nil { if jerr, ok := err.(*btcjson.RPCError); ok { switch jerr.Code { case btcjson.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:
- bitcoincorehttp Connects to a bitcoin core RPC server using HTTP POST mode with TLS disabled and gets the current block count
- pktdwebsockets Connects to a pktd RPC server using TLS-secured websockets, registers for block connected and block disconnected notifications, and gets the current block count
- pktwalletwebsockets Connects to a pktwallet RPC server using TLS-secured websockets, registers for notifications about changes to account balances, and gets a list of unspent transaction outputs (utxos) the wallet can sign
Index ¶
- Variables
- type AddNodeCommand
- type Client
- func (c *Client) AddNode(host string, command AddNodeCommand) er.R
- func (c *Client) AddNodeAsync(host string, command AddNodeCommand) FutureAddNodeResult
- func (c *Client) Connect(tries int) er.R
- func (c *Client) Disconnect()
- func (c *Client) Disconnected() bool
- func (c *Client) EstimateFee(numBlocks int64) (float64, er.R)
- func (c *Client) EstimateFeeAsync(numBlocks int64) FutureEstimateFeeResult
- func (c *Client) Generate(numBlocks uint32) ([]*chainhash.Hash, er.R)
- func (c *Client) GenerateAsync(numBlocks uint32) FutureGenerateResult
- func (c *Client) GetBestBlock() (*chainhash.Hash, int32, er.R)
- func (c *Client) GetBestBlockAsync() FutureGetBestBlockResult
- func (c *Client) GetBlock(blockHash *chainhash.Hash) (*wire.MsgBlock, er.R)
- func (c *Client) GetBlockAsync(blockHash *chainhash.Hash) FutureGetBlockResult
- func (c *Client) GetBlockHash(blockHeight int64) (*chainhash.Hash, er.R)
- func (c *Client) GetBlockHashAsync(blockHeight int64) FutureGetBlockHashResult
- func (c *Client) GetBlockHeader(blockHash *chainhash.Hash) (*wire.BlockHeader, er.R)
- func (c *Client) GetBlockHeaderAsync(blockHash *chainhash.Hash) FutureGetBlockHeaderResult
- func (c *Client) GetBlockHeaderVerbose(blockHash *chainhash.Hash) (*btcjson.GetBlockHeaderVerboseResult, er.R)
- func (c *Client) GetBlockHeaderVerboseAsync(blockHash *chainhash.Hash) FutureGetBlockHeaderVerboseResult
- func (c *Client) GetBlockVerbose(blockHash *chainhash.Hash) (*btcjson.GetBlockVerboseResult, er.R)
- func (c *Client) GetBlockVerboseAsync(blockHash *chainhash.Hash) FutureGetBlockVerboseResult
- func (c *Client) GetBlockVerboseTx(blockHash *chainhash.Hash) (*btcjson.GetBlockVerboseResult, er.R)
- func (c *Client) GetBlockVerboseTxAsync(blockHash *chainhash.Hash) FutureGetBlockVerboseResult
- func (c *Client) GetCFilter(blockHash *chainhash.Hash, filterType wire.FilterType) (*wire.MsgCFilter, er.R)
- func (c *Client) GetCFilterAsync(blockHash *chainhash.Hash, filterType wire.FilterType) FutureGetCFilterResult
- func (c *Client) GetCFilterHeader(blockHash *chainhash.Hash, filterType wire.FilterType) (*wire.MsgCFHeaders, er.R)
- func (c *Client) GetCFilterHeaderAsync(blockHash *chainhash.Hash, filterType wire.FilterType) FutureGetCFilterHeaderResult
- func (c *Client) GetCurrentNet() (protocol.BitcoinNet, er.R)
- func (c *Client) GetCurrentNetAsync() FutureGetCurrentNetResult
- func (c *Client) GetInfo() (*btcjson.InfoWalletResult, er.R)
- func (c *Client) GetInfoAsync() FutureGetInfoResult
- func (c *Client) GetPeerInfo() ([]btcjson.GetPeerInfoResult, er.R)
- func (c *Client) GetPeerInfoAsync() FutureGetPeerInfoResult
- func (c *Client) GetRawMempool() ([]*chainhash.Hash, er.R)
- func (c *Client) GetRawMempoolAsync() FutureGetRawMempoolResult
- func (c *Client) GetRawTransaction(txHash *chainhash.Hash) (*btcutil.Tx, er.R)
- func (c *Client) GetRawTransactionAsync(txHash *chainhash.Hash) FutureGetRawTransactionResult
- func (c *Client) GetRawTransactionVerbose(txHash *chainhash.Hash) (*btcjson.TxRawResult, er.R)
- func (c *Client) GetRawTransactionVerboseAsync(txHash *chainhash.Hash) FutureGetRawTransactionVerboseResult
- func (c *Client) GetTxOut(txHash *chainhash.Hash, index uint32, mempool bool) (*btcjson.GetTxOutResult, er.R)
- func (c *Client) GetTxOutAsync(txHash *chainhash.Hash, index uint32, mempool bool) FutureGetTxOutResult
- func (c *Client) LoadTxFilter(reload bool, addresses []btcutil.Address, outPoints []wire.OutPoint) er.R
- func (c *Client) LoadTxFilterAsync(reload bool, addresses []btcutil.Address, outPoints []wire.OutPoint) FutureLoadTxFilterResult
- func (c *Client) NextID() uint64
- func (c *Client) Node(command btcjson.NodeSubCmd, host string, connectSubCmd *string) er.R
- func (c *Client) NodeAsync(command btcjson.NodeSubCmd, host string, connectSubCmd *string) FutureNodeResult
- func (c *Client) NotifyBlocks() er.R
- func (c *Client) NotifyBlocksAsync() FutureNotifyBlocksResult
- func (c *Client) NotifyNewTransactions(verbose bool) er.R
- func (c *Client) NotifyNewTransactionsAsync(verbose bool) FutureNotifyNewTransactionsResult
- func (c *Client) NotifyReceived(addresses []btcutil.Address) er.R
- func (c *Client) NotifyReceivedAsync(addresses []btcutil.Address) FutureNotifyReceivedResult
- func (c *Client) NotifySpent(outpoints []*wire.OutPoint) er.Rdeprecated
- func (c *Client) NotifySpentAsync(outpoints []*wire.OutPoint) FutureNotifySpentResultdeprecated
- func (c *Client) RawRequest(method string, params []jsoniter.RawMessage) (jsoniter.RawMessage, er.R)
- func (c *Client) RawRequestAsync(method string, params []jsoniter.RawMessage) FutureRawResult
- func (c *Client) Rescan(startBlock *chainhash.Hash, addresses []btcutil.Address, ...) er.R
- func (c *Client) RescanAsync(startBlock *chainhash.Hash, addresses []btcutil.Address, ...) FutureRescanResult
- func (c *Client) RescanBlocks(blockHashes []chainhash.Hash) ([]btcjson.RescannedBlock, er.R)
- func (c *Client) RescanBlocksAsync(blockHashes []chainhash.Hash) FutureRescanBlocksResult
- func (c *Client) SendRawTransaction(tx *wire.MsgTx, allowHighFees bool) (*chainhash.Hash, er.R)
- func (c *Client) SendRawTransactionAsync(tx *wire.MsgTx, allowHighFees bool) FutureSendRawTransactionResult
- func (c *Client) Shutdown()
- func (c *Client) SubmitBlock(block *btcutil.Block, options *btcjson.SubmitBlockOptions) er.R
- func (c *Client) SubmitBlockAsync(block *btcutil.Block, options *btcjson.SubmitBlockOptions) FutureSubmitBlockResult
- func (c *Client) WaitForShutdown()
- type ConnConfig
- type FutureAddNodeResult
- type FutureEstimateFeeResult
- type FutureGenerateResult
- type FutureGetBestBlockResult
- type FutureGetBlockHashResult
- type FutureGetBlockHeaderResult
- type FutureGetBlockHeaderVerboseResult
- type FutureGetBlockResult
- type FutureGetBlockVerboseResult
- type FutureGetCFilterHeaderResult
- type FutureGetCFilterResult
- type FutureGetCurrentNetResult
- type FutureGetInfoResult
- type FutureGetPeerInfoResult
- type FutureGetRawMempoolResult
- type FutureGetRawTransactionResult
- type FutureGetRawTransactionVerboseResult
- type FutureGetTxOutResult
- type FutureLoadTxFilterResult
- type FutureNodeResult
- type FutureNotifyBlocksResult
- type FutureNotifyNewTransactionsResult
- type FutureNotifyReceivedResult
- type FutureNotifySpentResult
- type FutureRawResult
- type FutureRescanBlocksResult
- type FutureRescanResult
- type FutureSendRawTransactionResult
- type FutureSubmitBlockResult
- 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 = Err.CodeWithDetail("ErrInvalidAuth", "authentication failure") // ErrInvalidEndpoint is an error to describe the condition where the // websocket handshake failed with the specified endpoint. ErrInvalidEndpoint = Err.CodeWithDetail("ErrInvalidEndpoint", "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 = Err.CodeWithDetail("ErrClientNotConnected", "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 = Err.CodeWithDetail("ErrClientDisconnect", "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 = Err.CodeWithDetail("ErrClientShutdown", "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 = Err.CodeWithDetail("ErrNotWebsocketClient", "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 = Err.CodeWithDetail("ErrClientAlreadyConnected", "websocket client has already connected") // 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 = Err.CodeWithDetail("ErrWebsocketsRequired", "a websocket connection is required to use this feature") )
var Err er.ErrorType = er.NewErrorType("rpcclient.Err")
Functions ¶
This section is empty.
Types ¶
type AddNodeCommand ¶
type AddNodeCommand string
AddNodeCommand enumerates the available commands that the AddNode function accepts.
const ( // ANAdd indicates the specified host should be added as a persistent // peer. ANAdd AddNodeCommand = "add" ANRemove AddNodeCommand = "remove" )
Constants used to indicate the command for the AddNode function.
func (AddNodeCommand) String ¶
func (cmd AddNodeCommand) String() string
String returns the AddNodeCommand in human-readable form.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents a Bitcoin RPC client which allows easy access to the various RPC methods available on a Bitcoin 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, er.R)
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) AddNode ¶
func (c *Client) AddNode(host string, command AddNodeCommand) er.R
AddNode 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) AddNodeAsync ¶
func (c *Client) AddNodeAsync(host string, command AddNodeCommand) FutureAddNodeResult
AddNodeAsync 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 AddNode for the blocking version and more details.
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) 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) EstimateFee ¶
EstimateFee provides an estimated fee in bitcoins per kilobyte.
func (*Client) EstimateFeeAsync ¶
func (c *Client) EstimateFeeAsync(numBlocks int64) FutureEstimateFeeResult
EstimateFeeAsync 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 EstimateFee for the blocking version and more details.
func (*Client) GenerateAsync ¶
func (c *Client) GenerateAsync(numBlocks uint32) FutureGenerateResult
GenerateAsync 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 Generate for the blocking version and more details.
func (*Client) GetBestBlock ¶
GetBestBlock returns the hash and height of the block in the longest (best) chain.
NOTE: This is a pktd extension.
func (*Client) GetBestBlockAsync ¶
func (c *Client) GetBestBlockAsync() FutureGetBestBlockResult
GetBestBlockAsync 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 GetBestBlock for the blocking version and more details.
NOTE: This is a pktd extension.
func (*Client) GetBlock ¶
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 *chainhash.Hash) 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) GetBlockHash ¶
GetBlockHash returns the hash of the block in the best block chain at the given height.
func (*Client) GetBlockHashAsync ¶
func (c *Client) GetBlockHashAsync(blockHeight int64) FutureGetBlockHashResult
GetBlockHashAsync 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 GetBlockHash for the blocking version and more details.
func (*Client) GetBlockHeader ¶
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 *chainhash.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 *chainhash.Hash) (*btcjson.GetBlockHeaderVerboseResult, er.R)
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 *chainhash.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) GetBlockVerbose ¶
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 *chainhash.Hash) 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 *chainhash.Hash) (*btcjson.GetBlockVerboseResult, er.R)
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 *chainhash.Hash) 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) GetCFilter ¶
func (c *Client) GetCFilter(blockHash *chainhash.Hash, filterType wire.FilterType) (*wire.MsgCFilter, er.R)
GetCFilter returns a raw filter from the server given its block hash.
func (*Client) GetCFilterAsync ¶
func (c *Client) GetCFilterAsync(blockHash *chainhash.Hash, filterType wire.FilterType) FutureGetCFilterResult
GetCFilterAsync 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 GetCFilter for the blocking version and more details.
func (*Client) GetCFilterHeader ¶
func (c *Client) GetCFilterHeader(blockHash *chainhash.Hash, filterType wire.FilterType) (*wire.MsgCFHeaders, er.R)
GetCFilterHeader returns a raw filter header from the server given its block hash.
func (*Client) GetCFilterHeaderAsync ¶
func (c *Client) GetCFilterHeaderAsync(blockHash *chainhash.Hash, filterType wire.FilterType) FutureGetCFilterHeaderResult
GetCFilterHeaderAsync 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 GetCFilterHeader for the blocking version and more details.
func (*Client) GetCurrentNet ¶
func (c *Client) GetCurrentNet() (protocol.BitcoinNet, er.R)
GetCurrentNet returns the network the server is running on.
NOTE: This is a pktd extension.
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.
NOTE: This is a pktd extension.
func (*Client) GetInfo ¶
func (c *Client) GetInfo() (*btcjson.InfoWalletResult, er.R)
GetInfo returns miscellaneous info regarding the RPC server. The returned info object may be void of wallet information if the remote server does not include wallet functionality.
func (*Client) GetInfoAsync ¶
func (c *Client) GetInfoAsync() FutureGetInfoResult
GetInfoAsync 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 GetInfo for the blocking version and more details.
func (*Client) GetPeerInfo ¶
func (c *Client) GetPeerInfo() ([]btcjson.GetPeerInfoResult, er.R)
GetPeerInfo returns data about each connected network peer.
func (*Client) GetPeerInfoAsync ¶
func (c *Client) GetPeerInfoAsync() FutureGetPeerInfoResult
GetPeerInfoAsync 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 GetPeerInfo 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) GetRawTransaction ¶
GetRawTransaction returns a transaction given its hash.
See GetRawTransactionVerbose to obtain additional information about the transaction.
func (*Client) GetRawTransactionAsync ¶
func (c *Client) GetRawTransactionAsync(txHash *chainhash.Hash) FutureGetRawTransactionResult
GetRawTransactionAsync 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 GetRawTransaction for the blocking version and more details.
func (*Client) GetRawTransactionVerbose ¶
GetRawTransactionVerbose returns information about a transaction given its hash.
See GetRawTransaction to obtain only the transaction already deserialized.
func (*Client) GetRawTransactionVerboseAsync ¶
func (c *Client) GetRawTransactionVerboseAsync(txHash *chainhash.Hash) FutureGetRawTransactionVerboseResult
GetRawTransactionVerboseAsync 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 GetRawTransactionVerbose for the blocking version and more details.
func (*Client) GetTxOut ¶
func (c *Client) GetTxOut(txHash *chainhash.Hash, index uint32, mempool bool) (*btcjson.GetTxOutResult, er.R)
GetTxOut returns the transaction output info if it's unspent and nil, otherwise.
func (*Client) GetTxOutAsync ¶
func (c *Client) GetTxOutAsync(txHash *chainhash.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 []btcutil.Address, outPoints []wire.OutPoint) er.R
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.
NOTE: This is a pktd extension ported from github.com/decred/dcrrpcclient and requires a websocket connection.
func (*Client) LoadTxFilterAsync ¶
func (c *Client) LoadTxFilterAsync(reload bool, addresses []btcutil.Address, outPoints []wire.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.
NOTE: This is a pktd extension ported from github.com/decred/dcrrpcclient and requires a websocket connection.
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) Node ¶
Node attempts to perform the passed node command on the host. For example, it can be used to add or a remove a persistent peer, or to do connect or diconnect a non-persistent one.
The connectSubCmd should be set either "perm" or "temp", depending on whether we are targetting a persistent or non-persistent peer. Passing nil will cause the default value to be used, which currently is "temp".
func (*Client) NodeAsync ¶
func (c *Client) NodeAsync(command btcjson.NodeSubCmd, host string, connectSubCmd *string) FutureNodeResult
NodeAsync 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 Node for the blocking version and more details.
func (*Client) NotifyBlocks ¶
NotifyBlocks registers the client to receive notifications when blocks are connected and disconnected from the main chain. 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 OnBlockConnected or OnBlockDisconnected.
NOTE: This is a pktd extension and requires a websocket connection.
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.
NOTE: This is a pktd extension and requires a websocket connection.
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).
NOTE: This is a pktd extension and requires a websocket connection.
func (*Client) NotifyNewTransactionsAsync ¶
func (c *Client) NotifyNewTransactionsAsync(verbose bool) 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.
NOTE: This is a pktd extension and requires a websocket connection.
func (*Client) NotifyReceived ¶
NotifyReceived registers the client to receive notifications every time a new transaction which pays to one of the passed addresses is accepted to memory pool or in a block connected to the block chain. In addition, when one of these transactions is detected, the client is also automatically registered for notifications when the new transaction outpoints the address now has available are spent (See NotifySpent). 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 *OnRecvTx (for transactions that receive funds to one of the passed addresses) or OnRedeemingTx (for transactions which spend from one of the outpoints which are automatically registered upon receipt of funds to the address).
NOTE: This is a pktd extension and requires a websocket connection.
NOTE: Deprecated. Use LoadTxFilter instead.
func (*Client) NotifyReceivedAsync ¶
func (c *Client) NotifyReceivedAsync(addresses []btcutil.Address) FutureNotifyReceivedResult
NotifyReceivedAsync 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 NotifyReceived for the blocking version and more details.
NOTE: This is a pktd extension and requires a websocket connection.
NOTE: Deprecated. Use LoadTxFilterAsync instead.
func (*Client) NotifySpent
deprecated
NotifySpent registers the client to receive notifications when the passed transaction outputs are spent. 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 OnRedeemingTx.
NOTE: This is a btcd extension and requires a websocket connection.
Deprecated: Use LoadTxFilter instead.
func (*Client) NotifySpentAsync
deprecated
func (c *Client) NotifySpentAsync(outpoints []*wire.OutPoint) FutureNotifySpentResult
NotifySpentAsync 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 NotifySpent for the blocking version and more details.
NOTE: This is a btcd extension and requires a websocket connection.
Deprecated: Use LoadTxFilterAsync instead.
func (*Client) RawRequest ¶
func (c *Client) RawRequest(method string, params []jsoniter.RawMessage) (jsoniter.RawMessage, er.R)
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 []jsoniter.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) Rescan ¶
func (c *Client) Rescan(startBlock *chainhash.Hash, addresses []btcutil.Address, outpoints []*wire.OutPoint) er.R
Rescan rescans the block chain starting from the provided starting block to the end of the longest chain for transactions that pay to the passed addresses and transactions which spend the passed outpoints.
The notifications of found transactions are delivered to the notification handlers associated with client and this call will not return until the rescan has completed. 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 OnRedeemingTx (for transactions which spend from the one of the passed outpoints), OnRecvTx (for transactions that receive funds to one of the passed addresses), and OnRescanProgress (for rescan progress updates).
See RescanEndBlock to also specify an ending block to finish the rescan without continuing through the best block on the main chain.
NOTE: Rescan requests are not issued on client reconnect and must be performed manually (ideally with a new start height based on the last rescan progress notification). See the OnClientConnected notification callback for a good callsite to reissue rescan requests on connect and reconnect.
NOTE: This is a pktd extension and requires a websocket connection.
NOTE: Deprecated. Use RescanBlocks instead.
func (*Client) RescanAsync ¶
func (c *Client) RescanAsync(startBlock *chainhash.Hash, addresses []btcutil.Address, outpoints []*wire.OutPoint) FutureRescanResult
RescanAsync 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 Rescan for the blocking version and more details.
NOTE: Rescan requests are not issued on client reconnect and must be performed manually (ideally with a new start height based on the last rescan progress notification). See the OnClientConnected notification callback for a good callsite to reissue rescan requests on connect and reconnect.
NOTE: This is a pktd extension and requires a websocket connection.
NOTE: Deprecated. Use RescanBlocksAsync instead.
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 chain, but they do need to be adjacent to each other.
NOTE: This is a btcsuite extension ported from github.com/decred/dcrrpcclient.
func (*Client) RescanBlocksAsync ¶
func (c *Client) RescanBlocksAsync(blockHashes []chainhash.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.
NOTE: This is a btcsuite extension ported from github.com/decred/dcrrpcclient.
func (*Client) SendRawTransaction ¶
SendRawTransaction submits the encoded transaction to the server which will then relay it to the network.
func (*Client) SendRawTransactionAsync ¶
func (c *Client) SendRawTransactionAsync(tx *wire.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) 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 bitcoin network.
func (*Client) SubmitBlockAsync ¶
func (c *Client) SubmitBlockAsync(block *btcutil.Block, options *btcjson.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) 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 wire 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 // 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 }
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() er.R
Receive waits for the response promised by the future and returns an error if any occurred when performing the specified command.
type FutureEstimateFeeResult ¶
type FutureEstimateFeeResult chan *response
FutureEstimateFeeResult is a future promise to deliver the result of a EstimateFeeAsync RPC invocation (or an applicable error).
type FutureGenerateResult ¶
type FutureGenerateResult chan *response
FutureGenerateResult is a future promise to deliver the result of a GenerateAsync RPC invocation (or an applicable error).
type FutureGetBestBlockResult ¶
type FutureGetBestBlockResult chan *response
FutureGetBestBlockResult is a future promise to deliver the result of a GetBestBlockAsync RPC invocation (or an applicable error).
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() (*wire.BlockHeader, er.R)
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() (*btcjson.GetBlockHeaderVerboseResult, er.R)
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).
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() (*btcjson.GetBlockVerboseResult, er.R)
Receive waits for the response promised by the future and returns the data structure from the server with information about the requested block.
type FutureGetCFilterHeaderResult ¶
type FutureGetCFilterHeaderResult chan *response
FutureGetCFilterHeaderResult is a future promise to deliver the result of a GetCFilterHeaderAsync RPC invocation (or an applicable error).
func (FutureGetCFilterHeaderResult) Receive ¶
func (r FutureGetCFilterHeaderResult) Receive() (*wire.MsgCFHeaders, er.R)
Receive waits for the response promised by the future and returns the raw filter header requested from the server given its block hash.
type FutureGetCFilterResult ¶
type FutureGetCFilterResult chan *response
FutureGetCFilterResult is a future promise to deliver the result of a GetCFilterAsync RPC invocation (or an applicable error).
func (FutureGetCFilterResult) Receive ¶
func (r FutureGetCFilterResult) Receive() (*wire.MsgCFilter, er.R)
Receive waits for the response promised by the future and returns the raw filter requested from the server given its block hash.
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() (protocol.BitcoinNet, er.R)
Receive waits for the response promised by the future and returns the network the server is running on.
type FutureGetInfoResult ¶
type FutureGetInfoResult chan *response
FutureGetInfoResult is a future promise to deliver the result of a GetInfoAsync RPC invocation (or an applicable error).
func (FutureGetInfoResult) Receive ¶
func (r FutureGetInfoResult) Receive() (*btcjson.InfoWalletResult, er.R)
Receive waits for the response promised by the future and returns the info provided by the server.
type FutureGetPeerInfoResult ¶
type FutureGetPeerInfoResult chan *response
FutureGetPeerInfoResult is a future promise to deliver the result of a GetPeerInfoAsync RPC invocation (or an applicable error).
func (FutureGetPeerInfoResult) Receive ¶
func (r FutureGetPeerInfoResult) Receive() ([]btcjson.GetPeerInfoResult, er.R)
Receive waits for the response promised by the future and returns data about each connected network peer.
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 FutureGetRawTransactionResult ¶
type FutureGetRawTransactionResult chan *response
FutureGetRawTransactionResult is a future promise to deliver the result of a GetRawTransactionAsync RPC invocation (or an applicable error).
type FutureGetRawTransactionVerboseResult ¶
type FutureGetRawTransactionVerboseResult chan *response
FutureGetRawTransactionVerboseResult is a future promise to deliver the result of a GetRawTransactionVerboseAsync RPC invocation (or an applicable error).
func (FutureGetRawTransactionVerboseResult) Receive ¶
func (r FutureGetRawTransactionVerboseResult) Receive() (*btcjson.TxRawResult, er.R)
Receive waits for the response promised by the future and returns information about a transaction given its hash.
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() (*btcjson.GetTxOutResult, er.R)
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).
NOTE: This is a pktd extension ported from github.com/decred/dcrrpcclient and requires a websocket connection.
func (FutureLoadTxFilterResult) Receive ¶
func (r FutureLoadTxFilterResult) Receive() er.R
Receive waits for the response promised by the future and returns an error if the registration was not successful.
NOTE: This is a pktd extension ported from github.com/decred/dcrrpcclient and requires a websocket connection.
type FutureNodeResult ¶
type FutureNodeResult chan *response
FutureNodeResult is a future promise to deliver the result of a NodeAsync RPC invocation (or an applicable error).
func (FutureNodeResult) Receive ¶
func (r FutureNodeResult) Receive() er.R
Receive waits for the response promised by the future and returns an error if any occurred when performing the specified command.
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() er.R
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() er.R
Receive waits for the response promised by the future and returns an error if the registration was not successful.
type FutureNotifyReceivedResult ¶
type FutureNotifyReceivedResult chan *response
FutureNotifyReceivedResult is a future promise to deliver the result of a NotifyReceivedAsync RPC invocation (or an applicable error).
NOTE: Deprecated. Use FutureLoadTxFilterResult instead.
func (FutureNotifyReceivedResult) Receive ¶
func (r FutureNotifyReceivedResult) Receive() er.R
Receive waits for the response promised by the future and returns an error if the registration was not successful.
type FutureNotifySpentResult ¶
type FutureNotifySpentResult chan *response
FutureNotifySpentResult is a future promise to deliver the result of a NotifySpentAsync RPC invocation (or an applicable error).
NOTE: Deprecated. Use FutureLoadTxFilterResult instead.
func (FutureNotifySpentResult) Receive ¶
func (r FutureNotifySpentResult) Receive() er.R
Receive waits for the response promised by the future and returns an error if the registration was not successful.
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() (jsoniter.RawMessage, er.R)
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).
NOTE: This is a btcsuite extension ported from github.com/decred/dcrrpcclient.
func (FutureRescanBlocksResult) Receive ¶
func (r FutureRescanBlocksResult) Receive() ([]btcjson.RescannedBlock, er.R)
Receive waits for the response promised by the future and returns the discovered rescanblocks data.
NOTE: This is a btcsuite extension ported from github.com/decred/dcrrpcclient.
type FutureRescanResult ¶
type FutureRescanResult chan *response
FutureRescanResult is a future promise to deliver the result of a RescanAsync or RescanEndHeightAsync RPC invocation (or an applicable error).
NOTE: Deprecated. Use FutureRescanBlocksResult instead.
func (FutureRescanResult) Receive ¶
func (r FutureRescanResult) Receive() er.R
Receive waits for the response promised by the future and returns an error if the rescan was not successful.
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 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() er.R
Receive waits for the response promised by the future and returns an error if any occurred when submitting the block.
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() // OnBlockConnected is invoked when a block is connected to the longest // (best) chain. 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 OnFilteredBlockConnected instead. OnBlockConnected func(hash *chainhash.Hash, height int32, t time.Time) // OnFilteredBlockConnected is invoked when a block is connected to the // longest (best) chain. 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 OnBlockConnected: it // receives the block's height, header, and relevant transactions. OnFilteredBlockConnected func(height int32, header *wire.BlockHeader, txs []*btcutil.Tx) // OnBlockDisconnected is invoked when a block is disconnected from the // longest (best) chain. 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 OnFilteredBlockDisconnected instead. OnBlockDisconnected func(hash *chainhash.Hash, height int32, t time.Time) // OnFilteredBlockDisconnected is invoked when a block is disconnected // from the longest (best) chain. It will only be invoked if a // preceding NotifyBlocks has been made to register for the notification // and the call to function is non-nil. Its parameters differ from // OnBlockDisconnected: it receives the block's height and header. OnFilteredBlockDisconnected func(height int32, header *wire.BlockHeader) // OnRecvTx is invoked when a transaction that receives funds to a // registered address is received into the memory pool and also // connected to the longest (best) chain. It will only be invoked if a // preceding call to NotifyReceived, Rescan, or RescanEndHeight has been // made to register for the notification and the function is non-nil. // // NOTE: Deprecated. Use OnRelevantTxAccepted instead. OnRecvTx func(transaction *btcutil.Tx, details *btcjson.BlockDetails) // OnRedeemingTx is invoked when a transaction that spends a registered // outpoint is received into the memory pool and also connected to the // longest (best) chain. It will only be invoked if a preceding call to // NotifySpent, Rescan, or RescanEndHeight has been made to register for // the notification and the function is non-nil. // // NOTE: The NotifyReceived will automatically register notifications // for the outpoints that are now "owned" as a result of receiving // funds to the registered addresses. This means it is possible for // this to invoked indirectly as the result of a NotifyReceived call. // // NOTE: Deprecated. Use OnRelevantTxAccepted instead. OnRedeemingTx func(transaction *btcutil.Tx, details *btcjson.BlockDetails) // OnRelevantTxAccepted is invoked when an unmined transaction passes // the client's transaction filter. // // NOTE: This is a btcsuite extension ported from // github.com/decred/dcrrpcclient. OnRelevantTxAccepted func(transaction []byte) // OnRescanFinished is invoked after a rescan finishes due to a previous // call to Rescan or RescanEndHeight. Finished rescans should be // signaled on this notification, rather than relying on the return // result of a rescan request, due to how pktd may send various rescan // notifications after the rescan request has already returned. // // NOTE: Deprecated. Not used with RescanBlocks. OnRescanFinished func(hash *chainhash.Hash, height int32, blkTime time.Time) // OnRescanProgress is invoked periodically when a rescan is underway. // It will only be invoked if a preceding call to Rescan or // RescanEndHeight has been made and the function is non-nil. // // NOTE: Deprecated. Not used with RescanBlocks. OnRescanProgress func(hash *chainhash.Hash, height int32, blkTime time.Time) // 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 *chainhash.Hash, amount btcutil.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 *btcjson.TxRawResult) // OnBtcdConnected is invoked when a wallet connects or disconnects from // pktd. // // This will only be available when client is connected to a wallet // server such as pktwallet. OnBtcdConnected func(connected bool) // OnAccountBalance is invoked with account balance updates. // // This will only be available when speaking to a wallet server // such as pktwallet. OnAccountBalance func(account string, balance btcutil.Amount, confirmed bool) // OnWalletLockState is invoked when a wallet is locked or unlocked. // // This will only be available when client is connected to a wallet // server such as pktwallet. OnWalletLockState func(locked bool) // 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 []jsoniter.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.
NOTE: Unless otherwise documented, these handlers must NOT directly call any blocking calls on the client instance since the input reader goroutine blocks until the callback has completed. Doing so will result in a deadlock situation.