rpcclient

package
v0.0.0-...-4f0ab6e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 29, 2021 License: MIT Imports: 23 Imported by: 0

README

rpcclient

Build Status ISC License GoDoc

rpcclient implements a Websocket-enabled Bitcoin JSON-RPC client package written in Go. It provides a robust and easy to use client for interfacing with a Bitcoin RPC server that uses a btcd/bitcoin core compatible Bitcoin JSON-RPC API.

Status

This package is currently under active development. It is already stable and the infrastructure is complete. However, there are still several RPCs left to implement and the API is not stable yet.

Documentation

  • API Reference
  • btcd Websockets Example Connects to a btcd RPC server using TLS-secured websockets, registers for block connected and block disconnected notifications, and gets the current block count
  • btcwallet Websockets Example Connects to a btcwallet 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
  • Bitcoin Core HTTP POST Example Connects to a bitcoin core RPC server using HTTP POST mode with TLS disabled and gets the current block count

Major Features

  • Supports Websockets (btcd/btcwallet) and HTTP POST mode (bitcoin core)
  • Provides callback and registration functions for btcd/btcwallet notifications
  • Supports btcd extensions
  • Translates to and from higher-level and easier to use Go types
  • Offers a synchronous (blocking) and asynchronous API
  • When running in Websockets mode (the default):
    • Automatic reconnect handling (can be disabled)
    • Outstanding commands are automatically reissued
    • Registered notifications are automatically reregistered
    • Back-off support on reconnect attempts

Installation

$ go get -u github.com/multivactech/MultiVAC/rpcclient

License

Package rpcclient is licensed under the copyfree ISC License.

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 btcd/bitcoin core compatible Bitcoin JSON-RPC API. This client has been tested with btcd (https://github.com/multivactech/MultiVAC), btcwallet (https://github.com/multivactech/MultiVAC/btcwallet), and bitcoin core (https://github.com/bitcoin).

In addition to the compatible standard HTTP POST JSON-RPC API, btcd and btcwallet 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 btcd or btcwallet 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 btcd and btcwallet 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 btcd 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 btcd (and btcwallet 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 btcd intentionally separates the wallet functionality into a separate process named btcwallet. This means if you are connected to the btcd 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, btcwallet 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
  • btcdwebsockets Connects to a btcd RPC server using TLS-secured websockets, registers for block connected and block disconnected notifications, and gets the current block count
  • btcwalletwebsockets Connects to a btcwallet 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

Constants

This section is empty.

Variables

View Source
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")
)
View Source
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 DisableLog

func DisableLog()

DisableLog disables all library log output. Logging output is disabled by default until UseLogger is called.

func UseLogger

func UseLogger(logger btclog.Logger)

UseLogger uses a specified Logger to output package logging info.

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 indicates the specified peer should be removed.
	ANRemove AddNodeCommand = "remove"

	// ANOneTry indicates the specified host should try to connect once,
	// but it should not be made persistent.
	ANOneTry AddNodeCommand = "onetry"
)

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, 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) AddNode

func (c *Client) AddNode(host string, command AddNodeCommand) error

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

func (c *Client) Connect(tries int) error

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

func (c *Client) Disconnected() bool

Disconnected returns whether or not the server is disconnected. If a websocket client was created but never connected, this also returns false.

func (*Client) GetAddedNodeInfo

func (c *Client) GetAddedNodeInfo(peer string) ([]btcjson.GetAddedNodeInfoResult, error)

GetAddedNodeInfo returns information about manually added (persistent) peers.

See GetAddedNodeInfoNoDNS to retrieve only a list of the added (persistent) peers.

func (*Client) GetAddedNodeInfoAsync

func (c *Client) GetAddedNodeInfoAsync(peer string) FutureGetAddedNodeInfoResult

GetAddedNodeInfoAsync 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 GetAddedNodeInfo for the blocking version and more details.

func (*Client) GetAddedNodeInfoNoDNS

func (c *Client) GetAddedNodeInfoNoDNS(peer string) ([]string, error)

GetAddedNodeInfoNoDNS returns a list of manually added (persistent) peers. This works by setting the dns flag to false in the underlying RPC.

See GetAddedNodeInfo to obtain more information about each added (persistent) peer.

func (*Client) GetAddedNodeInfoNoDNSAsync

func (c *Client) GetAddedNodeInfoNoDNSAsync(peer string) FutureGetAddedNodeInfoNoDNSResult

GetAddedNodeInfoNoDNSAsync 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 GetAddedNodeInfoNoDNS for the blocking version and more details.

func (*Client) GetConnectionCount

func (c *Client) GetConnectionCount() (int64, error)

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) GetNetTotals

func (c *Client) GetNetTotals() (*btcjson.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) GetPeerInfo

func (c *Client) GetPeerInfo() ([]btcjson.GetPeerInfoResult, error)

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) GetTxOut

func (c *Client) GetTxOut(hexOutPoint string) (byte, error)

GetTxOut returns the given outPoint's value and state.

func (*Client) GetTxOutAsync

func (c *Client) GetTxOutAsync(hexOutPoint string) FutureGetTxOut

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) NextID

func (c *Client) NextID() uint64

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) Ping

func (c *Client) Ping() error

Ping queues a ping to be sent to each connected peer.

Use the GetPeerInfo 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) QueryBlockInfo

func (c *Client) QueryBlockInfo(startHeight int64, shardID string) (*btcjson.BlockInfo, error)

QueryBlockInfo returns a list of block from start height in the given shard.

func (*Client) QueryBlockInfoAsync

func (c *Client) QueryBlockInfoAsync(startHeight int64, shardID string) FutureBlockInfoResult

QueryBlockInfoAsync 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 QueryBlockInfo for the blocking version and more details.

func (*Client) QueryBlockSliceInfo

func (c *Client) QueryBlockSliceInfo(startHeight int64, endHeight int64, shardID string) (*btcjson.BlockInfo, error)

QueryBlockSliceInfo queries blocks from start height to end height in given shard.

func (*Client) QueryBlockSliceInfoAsync

func (c *Client) QueryBlockSliceInfoAsync(startHeight int64, endHeight int64, shardID string) FutureBlockInfoResult

QueryBlockSliceInfoAsync 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 QueryBlockSliceInfo for the blocking version and more details.

func (*Client) QueryShardInfo

func (c *Client) QueryShardInfo() (*btcjson.ShardsInfo, error)

QueryShardInfo returns a list of shards and their state and count.

func (*Client) QueryShardInfoAsync

func (c *Client) QueryShardInfoAsync() FutureShardInfoResult

QueryShardInfoAsync 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 QueryShardInfo for the blocking version and more details.

func (*Client) QuerySmartContractInfo

func (c *Client) QuerySmartContractInfo(contractAddress multivacaddress.Address, shardIdx shard.Index) (*btcjson.BlockInfo, error)

QuerySmartContractInfo returns information of smartContractInfo given contractAddress and shardIndex.

func (*Client) QuerySmartContractInfoAsync

func (c *Client) QuerySmartContractInfoAsync(contractAddress multivacaddress.Address, shardIdx shard.Index) FutureBlockInfoResult

QuerySmartContractInfoAsync 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 QuerySmartContractInfo 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) SendPrepareForStop

func (c *Client) SendPrepareForStop()

SendPrepareForStop ... TODO: see whether it will be used.

func (*Client) SendRawTransaction

func (c *Client) SendRawTransaction(HexTx string) error

SendRawTransaction sends a Tx to the storage node in it's shard.

func (*Client) SendRawTransactionAsync

func (c *Client) SendRawTransactionAsync(HexTx string) FutureSendRawTransaction

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) SendTest

func (c *Client) SendTest() error

SendTest generates some test Txs on storage node and returns error message. TODO: test whether this method can still be used at version 3.0.

func (*Client) SendTestTx

func (c *Client) SendTestTx(numOfTx int) error

SendTestTx generates some test Txs on storage node and returns error message. TODO: test whether this method can still be used at version 3.0.

func (*Client) SendTransferTx

func (c *Client) SendTransferTx(txDetail string) (*string, error)

SendTransferTx sends a transfer tx to storage node and returns error message.

func (*Client) SendTransferTxAsync

func (c *Client) SendTransferTxAsync(txDetail string) FutureReceivedResult

SendTransferTxAsync 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 SendTransferTx for the blocking version and more details.

func (*Client) SetHeartBeatTime

func (c *Client) SetHeartBeatTime(online, deviation, interval int64)

SetHeartBeatTime is used to reset heart beat params. TODO: to test whether it will be used.

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) TestAsync

func (c *Client) TestAsync() FuturePingResult

TestAsync is a temporary rpc command to trigger tx generate on storage node side. It should be cleaned up once client tx generation is stable.

func (*Client) TestTxAsync

func (c *Client) TestTxAsync(numOfTx int) FuturePingResult

TestTxAsync is a temporary rpc command to trigger tx generate on storage node side. It should be cleaned up once client tx generation is stable.

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

	// 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

	// EnableBCInfoHacks is an option provided to enable compatibility hacks
	// when connecting to blockchain.info RPC server
	EnableBCInfoHacks 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() error

Receive waits for the response promised by the future and returns an error if any occurred when performing the specified command.

type FutureBlockInfoResult

type FutureBlockInfoResult chan *response

FutureBlockInfoResult is a future promise to deliver the result of a QueryBlockInfoAsync RPC invocation (or an applicable error).

func (FutureBlockInfoResult) Receive

func (r FutureBlockInfoResult) Receive() (*btcjson.BlockInfo, error)

Receive waits for the response promised by the future and returns the result of querying BlockInfo.

type FutureGetAddedNodeInfoNoDNSResult

type FutureGetAddedNodeInfoNoDNSResult chan *response

FutureGetAddedNodeInfoNoDNSResult is a future promise to deliver the result of a GetAddedNodeInfoNoDNSAsync RPC invocation (or an applicable error).

func (FutureGetAddedNodeInfoNoDNSResult) Receive

Receive waits for the response promised by the future and returns a list of manually added (persistent) peers.

type FutureGetAddedNodeInfoResult

type FutureGetAddedNodeInfoResult chan *response

FutureGetAddedNodeInfoResult is a future promise to deliver the result of a GetAddedNodeInfoAsync RPC invocation (or an applicable error).

func (FutureGetAddedNodeInfoResult) Receive

Receive waits for the response promised by the future and returns information about manually added (persistent) peers.

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

Receive waits for the response promised by the future and returns the number of active connections to other peers.

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

Receive waits for the response promised by the future and returns network traffic statistics.

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

Receive waits for the response promised by the future and returns data about each connected network peer.

type FutureGetTxOut

type FutureGetTxOut chan *response

FutureGetTxOut is a future promise to deliver the result of a RPC invocation (or an applicable error).

func (FutureGetTxOut) Receive

func (r FutureGetTxOut) Receive() (byte, 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 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 FutureReceivedResult

type FutureReceivedResult chan *response

FutureReceivedResult is is a future promise to deliver the result of a RPC invocation.

func (FutureReceivedResult) Receive

func (r FutureReceivedResult) Receive() (*string, error)

Receive waits for the response promised by the future and returns the result of sending transfer tx to storage node.

type FutureSendRawTransaction

type FutureSendRawTransaction chan *response

FutureSendRawTransaction is a future promise to deliver the result of a RPC invocation (or an applicable error).

func (FutureSendRawTransaction) Receive

func (r FutureSendRawTransaction) Receive() error

Receive waits for the response promised by the future and returns the result of sending a rawTransaction.

type FutureShardInfoResult

type FutureShardInfoResult chan *response

FutureShardInfoResult is a future promise to deliver the result of a QueryShardInfoAsync RPC invocation (or an applicable error).

func (FutureShardInfoResult) Receive

Receive waits for the response promised by the future and returns the result of querying peer shard info.

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()

	// 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.

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.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL