Documentation
¶
Index ¶
- Variables
- type Client
- func (c *Client) Disconnected() bool
- func (c *Client) GetBlock(blockHeight int64) (*rpchttp.BlockInfo, error)
- func (c *Client) GetBlockAsync(blockHeight int64) FutureGetBlockResult
- func (c *Client) GetBlockCount() (int64, error)
- func (c *Client) GetBlockCountAsync() FutureGetBlockCountResult
- func (c *Client) GetRawTransaction(txHash string) (*rpchttp.Transactions, error)
- func (c *Client) GetRawTransactionAsync(txHash string) FutureGetRawTransactionResult
- func (c *Client) NextID() uint64
- func (c *Client) SendCmd(cmd interface{}, suffix string) chan *response
- func (c *Client) SendRawTransaction(rawTx string) (string, error)
- func (c *Client) SendRawTransactionAsync(rawTx string) FutureSendRawTransactionResult
- func (c *Client) Shutdown()
- func (c *Client) WaitForShutdown()
- type ConnConfig
- type FutureGetBlockCountResult
- type FutureGetBlockResult
- type FutureGetRawTransactionResult
- type FutureSendRawTransactionResult
Constants ¶
This section is empty.
Variables ¶
var ( // 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") )
Functions ¶
This section is empty.
Types ¶
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) (*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) 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) GetBlockAsync ¶
func (c *Client) GetBlockAsync(blockHeight int64) FutureGetBlockResult
func (*Client) GetBlockCount ¶
GetBlockCount returns the number of blocks in the longest block chain.
func (*Client) GetBlockCountAsync ¶
func (c *Client) GetBlockCountAsync() FutureGetBlockCountResult
GetBlockCountAsync returns an instance of a type that can be used to get the result of the RPC at some future time by invoking the Receive function on the returned instance.
See GetBlockCount for the blocking version and more details.
func (*Client) GetRawTransaction ¶
func (c *Client) GetRawTransaction(txHash string) (*rpchttp.Transactions, error)
func (*Client) GetRawTransactionAsync ¶
func (c *Client) GetRawTransactionAsync(txHash string) FutureGetRawTransactionResult
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) SendRawTransaction ¶
func (*Client) SendRawTransactionAsync ¶
func (c *Client) SendRawTransactionAsync(rawTx string) FutureSendRawTransactionResult
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) 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 FutureGetBlockCountResult ¶
type FutureGetBlockCountResult chan *response
FutureGetBlockCountResult is a future promise to deliver the result of a GetBlockCountAsync RPC invocation (or an applicable error).
func (FutureGetBlockCountResult) Receive ¶
func (r FutureGetBlockCountResult) Receive() (int64, error)
Receive waits for the response promised by the future and returns the number of blocks in the longest block chain.
type FutureGetBlockResult ¶
type FutureGetBlockResult chan *response
type FutureGetRawTransactionResult ¶
type FutureGetRawTransactionResult chan *response
func (FutureGetRawTransactionResult) Receive ¶
func (r FutureGetRawTransactionResult) Receive() (*rpchttp.Transactions, error)
type FutureSendRawTransactionResult ¶
type FutureSendRawTransactionResult chan *response
func (FutureSendRawTransactionResult) Receive ¶
func (r FutureSendRawTransactionResult) Receive() (string, error)