jaxrpc

package
v0.4.11 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2023 License: ISC Imports: 22 Imported by: 2

README

rpcclient

Build Status ISC License GoDoc

jaxrpc implements HTTP POST and 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
  • Websockets Example NOT IMPLEMENTED YET.
  • Wallet Websockets Example NOT IMPLEMENTED YET.
  • JaxNet Core HTTP POST Example Connects to a JaxNet 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

Installation

$ go get -u gitlab.com/jaxnet/jaxnetd/network/jaxrpc

License

Package jaxrpc is licensed under the copyfree ISC License.

Documentation

Overview

Package jaxrpc implements a Jaxnetd JSON-RPC client.

Overview

This client provides a robust and easy to use client for interfacing with a Bitcoin RPC server that uses a jaxnetd/bitcoin core compatible Bitcoin JSON-RPC API. This client has been tested with jaxnetd (https://gitlab.com/jaxnet/jaxnetd), jaxwallet (https://github.com/btcsuite/jaxwallet), and bitcoin core (https://github.com/bitcoin).

It provides standard HTTP POST JSON-RPC synchronous (blocking) API only.

## 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 jaxnetd (and jaxwallet 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 commands are extensions in their documentation.

Also, it is important to realize that jaxnetd intentionally separates the wallet functionality into a separate process named jaxwallet. This means if you are connected to the jaxnetd 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, jaxwallet 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 or endpoint

  • 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 is typically one of ErrInvalidAuth, ErrInvalidEndpoint.

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 *jaxjson.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.(*jaxjson.RPCError); ok {
  		switch jerr.Code {
  		case jaxjson.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

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 does not exist")

	ErrInvalidHosts = errors.New("rpc hosts not specified")

	ErrHostUnreachable = errors.New("rpc hosts unreachable")

	// ErrUnknownChain indicates that client tries to connect to unknown chain
	ErrUnknownChain = errors.New("unknown chain")
)

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 zerolog.Logger)

UseLogger uses a specified Logger to output package logging info. nolint

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 BackendVersion

type BackendVersion uint8

BackendVersion represents the version of the backend the client is currently connected to.

const (
	// JaxnetdPre19 represents a jaxnetd version before 0.19.0.
	JaxnetdPre19 BackendVersion = iota

	// JaxnetdPost19 represents a jaxnetd version equal to or greater than
	// 0.19.0.
	JaxnetdPost19

	// Jaxnetd represents a catch-all jaxnetd version.
	Jaxnetd
)

type BlockResult

type BlockResult struct {
	Block  *wire.MsgBlock
	Height int32
}

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.

IMPORTANT: The asynchronous form is not implemented at the moment.

func New

func New(config *ConnConfig) (*Client, error)

New creates a new RPC client based on the provided connection configuration details.

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

func (c *Client) BackendVersion() (BackendVersion, error)

BackendVersion retrieves the version of the backend the client is currently connected to.

func (*Client) ChainParams

func (c *Client) ChainParams() *chaincfg.Params

func (*Client) Config

func (c *Client) Config() *ConnConfig

Config returns a current configuration of the Client.

func (*Client) CreateRawTransaction

func (c *Client) CreateRawTransaction(chainID uint32, inputs []jaxjson.TransactionInput,
	amounts map[jaxutil.Address]jaxutil.Amount, lockTime *int64) (*wire.MsgTx, error)

CreateRawTransaction returns a new transaction spending the provided inputs and sending to the provided addresses. If the inputs are either nil or an empty slice, it is interpreted as an empty slice.

func (*Client) DebugLevel

func (c *Client) DebugLevel(levelSpec string) (string, error)

DebugLevel dynamically sets the debug logging level to the passed level specification.

The levelSpec can be either a debug level or of the form:

<subsystem>=<level>,<subsystem2>=<level2>,...

Additionally, the special keyword 'show' can be used to get a list of the available subsystems.

NOTE: This is a jaxnetd extension.

func (*Client) DecodeRawTransaction

func (c *Client) DecodeRawTransaction(chainID uint32, serializedTx []byte) (*jaxjson.TxRawResult, error)

DecodeRawTransaction returns information about a transaction given its serialized bytes.

func (*Client) DecodeScript

func (c *Client) DecodeScript(serializedScript []byte) (*jaxjson.DecodeScriptResult, error)

DecodeScript returns information about a script given its serialized bytes.

func (*Client) EstimateFee

func (c *Client) EstimateFee(chainID uint32, numBlocks int64) (float64, error)

EstimateFee provides an estimated fee in bitcoins per kilobyte.

func (*Client) EstimateLockTime

func (c *Client) EstimateLockTime(chainID uint32, amount int64) (*jaxjson.EstimateLockTimeResult, error)

EstimateLockTime estimates desired period in block for locking funds // in shard during the CrossShard Swap Tx.

func (*Client) EstimateSmartFee

func (c *Client) EstimateSmartFee(chainID uint32, confTarget int64, mode *jaxjson.EstimateSmartFeeMode) (*jaxjson.EstimateSmartFeeResult, error)

EstimateSmartFee requests the server to estimate a fee level based on the given parameters.

func (*Client) EstimateSwapLockTime

func (c *Client) EstimateSwapLockTime(source, dest uint32, amount int64) (*jaxjson.EstimateSwapLockTimeResult, error)

EstimateSwapLockTime estimates desired period in block for locking funds in source and destination shards during the CrossShard Swap Tx. TODO: unsure if code is correct

func (*Client) Generate

func (c *Client) Generate(numBlocks uint32) ([]*chainhash.Hash, error)

Generate generates numBlocks blocks and returns their hashes.

func (*Client) GenerateToAddress

func (c *Client) GenerateToAddress(numBlocks int64, address jaxutil.Address, maxTries *int64) ([]*chainhash.Hash, error)

GenerateToAddress generates numBlocks blocks to the given address and returns their hashes.

func (*Client) GetAddedNodeInfo

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

GetAddedNodeInfo returns information about manually added (persistent) peers.

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

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

func (c *Client) GetBeaconBlock(blockHash *chainhash.Hash) (*BlockResult, error)

GetBeaconBlock returns a raw block from the server given its hash.

See GetBeaconBlockVerbose to retrieve a data structure with information about the block instead.

func (*Client) GetBeaconBlockHeader

func (c *Client) GetBeaconBlockHeader(blockHash *chainhash.Hash) (wire.BlockHeader, error)

GetBeaconBlockHeader returns the getBeaconBlockHeader from the server given its hash. See GetBeaconBlockHeaderVerbose to retrieve a data structure with information about the block instead.

func (*Client) GetBeaconBlockHeaderVerbose

func (c *Client) GetBeaconBlockHeaderVerbose(blockHash *chainhash.Hash) (*jaxjson.GetBeaconBlockHeaderVerboseResult, error)

GetBeaconBlockHeaderVerbose returns a data structure with information about the block header from the server given its hash.

See GetBeaconBlockHeader to retrieve a block header instead.

func (*Client) GetBeaconBlockTemplate

func (c *Client) GetBeaconBlockTemplate(reqData *jaxjson.TemplateRequest) (*jaxjson.GetBlockTemplateResult, error)

GetBeaconBlockTemplate deals with generating and returning block templates to the caller. Deprecated: use the GetBlockTemplate instead.

func (*Client) GetBeaconBlockVerbose

func (c *Client) GetBeaconBlockVerbose(blockHash *chainhash.Hash) (*jaxjson.GetBeaconBlockVerboseResult, error)

GetBeaconBlockVerbose returns a data structure from the server with information about a block given its hash.

See GetBeaconBlockVerboseTx to retrieve transaction data structures as well. See GetBeaconBlock to retrieve a raw block instead.

func (*Client) GetBeaconBlockVerboseTx

func (c *Client) GetBeaconBlockVerboseTx(blockHash *chainhash.Hash) (*jaxjson.GetBeaconBlockVerboseResult, error)

GetBeaconBlockVerboseTx returns a data structure from the server with information about a block and its transactions given its hash.

See GetBeaconBlockVerbose if only transaction hashes are preferred. See GetBeaconBlock to retrieve a raw block instead.

func (*Client) GetBeaconHeaders

func (c *Client) GetBeaconHeaders(blockLocators []chainhash.Hash, hashStop *chainhash.Hash) ([]wire.BeaconHeader, error)

GetBeaconHeaders mimics the wire protocol getheaders and headers messages by returning all headers on the main chain after the first known block in the locators, up until a block hash matches hashStop.

NOTE: This is a btcsuite extension ported from github.com/decred/dcrrpcclient.

func (*Client) GetBestBlock

func (c *Client) GetBestBlock(chainID uint32) (*chainhash.Hash, int32, error)

GetBestBlock returns the hash and height of the block in the longest (best) chain.

NOTE: This is a jaxnetd extension.

func (*Client) GetBestBlockHash

func (c *Client) GetBestBlockHash(chainID uint32) (*chainhash.Hash, error)

GetBestBlockHash returns the hash of the best block in the longest blockchain.

func (*Client) GetBlockChainInfo

func (c *Client) GetBlockChainInfo(chainID uint32) (*jaxjson.GetBlockChainInfoResult, error)

GetBlockChainInfo returns information related to the processing state of various chain-specific details such as the current difficulty from the tip of the main chain.

func (*Client) GetBlockCount

func (c *Client) GetBlockCount(chainID uint32) (int64, error)

GetBlockCount returns the number of blocks in the longest block chain.

func (*Client) GetBlockHash

func (c *Client) GetBlockHash(chainID uint32, blockHeight int64) (*chainhash.Hash, error)

GetBlockHash returns the hash of the block in the best block chain at the given height.

func (*Client) GetBlockStats

func (c *Client) GetBlockStats(chainID uint32, hashOrHeight interface{}, stats *[]string) (*jaxjson.GetBlockStatsResult, error)

GetBlockStats returns block statistics. First argument specifies height or hash of the target block. Second argument allows to select certain stats to return.

func (*Client) GetBlockTemplate

func (c *Client) GetBlockTemplate(chainID uint32, reqData *jaxjson.TemplateRequest) (*jaxjson.GetBlockTemplateResult, error)

GetBlockTemplate deals with generating and returning block templates to the caller.

func (*Client) GetBlockTxOperations

func (c *Client) GetBlockTxOperations(chainID uint32, blockHash *chainhash.Hash) (*jaxjson.BlockTxOperations, error)

GetBlockTxOperations returns the transaction output info if it's unspent and nil, otherwise.

func (*Client) GetCFilter

func (c *Client) GetCFilter(chainID uint32, blockHash *chainhash.Hash,
	filterType wire.FilterType) (*wire.MsgCFilter, error)

GetCFilter returns a raw filter from the server given its block hash.

func (*Client) GetCFilterHeader

func (c *Client) GetCFilterHeader(chainID uint32, blockHash *chainhash.Hash,
	filterType wire.FilterType) (*wire.MsgCFHeaders, error)

GetCFilterHeader returns a raw filter header from the server given its block hash.

func (*Client) GetChainMetrics

func (c *Client) GetChainMetrics(chainID uint32) (*jaxjson.GetChainMetricsResult, error)

GetChainMetrics returns the chain metrics info for Prometheus

func (*Client) GetConnectionCount

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

GetConnectionCount returns the number of active connections to other peers.

func (*Client) GetCurrentNet

func (c *Client) GetCurrentNet() (wire.JaxNet, error)

GetCurrentNet returns the network the server is running on.

NOTE: This is a jaxnetd extension.

func (*Client) GetDifficulty

func (c *Client) GetDifficulty(chainID uint32) (float64, error)

GetDifficulty returns the proof-of-work difficulty as a multiple of the minimum difficulty.

func (*Client) GetExtendedFee

func (c *Client) GetExtendedFee(chainID uint32) (*jaxjson.ExtendedFeeFeeResult, error)

GetExtendedFee requests the server to estimate a fee level based on the given parameters.

func (*Client) GetGenerate

func (c *Client) GetGenerate() (bool, error)

GetGenerate returns true if the server is set to mine, otherwise false.

func (*Client) GetHashesPerSec

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

GetHashesPerSec returns a recent hashes per second performance measurement while generating coins (mining). Zero is returned if the server is not mining.

func (*Client) GetInfo

func (c *Client) GetInfo() (*jaxjson.InfoWalletResult, error)

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. NOTE: While getinfo is implemented here (in node.go), a btcd chain server will respond to getinfo requests as well, excluding any wallet information.

func (*Client) GetMempoolEntry

func (c *Client) GetMempoolEntry(chainID uint32, txHash string) (*jaxjson.GetMempoolEntryResult, error)

GetMempoolEntry returns a data structure with information about the transaction in the memory pool given its hash.

func (*Client) GetMempoolUTXOs

func (c *Client) GetMempoolUTXOs(chainID uint32) ([]jaxjson.MempoolUTXO, error)

GetMempoolUTXOs ...

func (*Client) GetMiningInfo

func (c *Client) GetMiningInfo() (*jaxjson.GetMiningInfoResult, error)

GetMiningInfo returns mining information.

func (*Client) GetNetTotals

func (c *Client) GetNetTotals() (*jaxjson.GetNetTotalsResult, error)

GetNetTotals returns network traffic statistics.

func (*Client) GetNetworkHashPS

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

GetNetworkHashPS returns the estimated network hashes per second using the default number of blocks and the most recent block height.

See GetNetworkHashPS2 to override the number of blocks to use and GetNetworkHashPS3 to override the height at which to calculate the estimate.

func (*Client) GetNetworkHashPS2

func (c *Client) GetNetworkHashPS2(blocks int) (int64, error)

GetNetworkHashPS2 returns the estimated network hashes per second for the specified previous number of blocks working backwards from the most recent block height. The blocks parameter can also be -1 in which case the number of blocks since the last difficulty change will be used.

See GetNetworkHashPS to use defaults and GetNetworkHashPS3 to override the height at which to calculate the estimate.

func (*Client) GetNetworkHashPS3

func (c *Client) GetNetworkHashPS3(blocks, height int) (int64, error)

GetNetworkHashPS3 returns the estimated network hashes per second for the specified previous number of blocks working backwards from the specified block height. The blocks parameter can also be -1 in which case the number of blocks since the last difficulty change will be used.

See GetNetworkHashPS and GetNetworkHashPS2 to use defaults.

func (*Client) GetNetworkInfo

func (c *Client) GetNetworkInfo() (*jaxjson.GetNetworkInfoResult, error)

GetNetworkInfo returns data about the current network.

func (*Client) GetNodeMetrics

func (c *Client) GetNodeMetrics() (*jaxjson.GetNodeMetricsResult, error)

GetNodeMetrics returns the node metrics info for Prometheus

func (*Client) GetPeerInfo

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

GetPeerInfo returns data about each connected network peer.

func (*Client) GetRawMempool

func (c *Client) GetRawMempool(chainID uint32) ([]*chainhash.Hash, error)

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

func (c *Client) GetRawMempoolVerbose(chainID uint32) (map[string]jaxjson.GetRawMempoolVerboseResult, error)

GetRawMempoolVerbose returns a map of transaction hashes to an associated data structure with information about the transaction for all transactions in the memory pool. See GetRawMempool to retrieve only the transaction hashes instead.

func (*Client) GetRawTransaction

func (c *Client) GetRawTransaction(chainID uint32, txHash *chainhash.Hash) (*jaxutil.Tx, error)

GetRawTransaction returns a transaction given its hash.

See GetRawTransactionVerbose to obtain additional information about the transaction.

func (*Client) GetRawTransactionVerbose

func (c *Client) GetRawTransactionVerbose(chainID uint32, txHash *chainhash.Hash) (*jaxjson.TxRawResult, error)

GetRawTransactionVerbose returns information about a transaction given its hash.

See GetRawTransaction to obtain only the transaction already deserialized.

func (*Client) GetShardBlock

func (c *Client) GetShardBlock(chainID uint32, blockHash *chainhash.Hash) (*BlockResult, error)

GetShardBlock returns a raw block from the server given its hash.

See GetShardBlockVerbose to retrieve a data structure with information about the block instead.

func (*Client) GetShardBlockHeader

func (c *Client) GetShardBlockHeader(chainID uint32, blockHash *chainhash.Hash) (wire.BlockHeader, error)

GetShardBlockHeader returns the getShardBlockHeader from the server given its hash.

See GetShardBlockHeaderVerbose to retrieve a data structure with information about the block instead.

func (*Client) GetShardBlockHeaderVerbose

func (c *Client) GetShardBlockHeaderVerbose(chainID uint32, blockHash *chainhash.Hash) (*jaxjson.GetShardBlockHeaderVerboseResult, error)

GetShardBlockHeaderVerbose returns a data structure with information about the block header from the server given its hash.

See GetShardBlockHeader to retrieve a block header instead.

func (*Client) GetShardBlockTemplate

func (c *Client) GetShardBlockTemplate(chainID uint32, reqData *jaxjson.TemplateRequest) (*jaxjson.GetBlockTemplateResult, error)

GetShardBlockTemplate deals with generating and returning block templates to the caller. Deprecated: use the GetBlockTemplate instead.

func (*Client) GetShardBlockVerbose

func (c *Client) GetShardBlockVerbose(chainID uint32, blockHash *chainhash.Hash) (*jaxjson.GetShardBlockVerboseResult, error)

GetShardBlockVerbose returns a data structure from the server with information about a block given its hash.

See GetShardBlockVerboseTx to retrieve transaction data structures as well. See GetShardBlock to retrieve a raw block instead.

func (*Client) GetShardBlockVerboseTx

func (c *Client) GetShardBlockVerboseTx(chainID uint32, blockHash *chainhash.Hash) (*jaxjson.GetShardBlockVerboseResult, error)

GetShardBlockVerboseTx returns a data structure from the server with information about a block and its transactions given its hash.

See GetShardBlockVerbose if only transaction hashes are preferred. See GetShardBlock to retrieve a raw block instead.

func (*Client) GetShardHeaders

func (c *Client) GetShardHeaders(chainID uint32, blockLocators []chainhash.Hash, hashStop *chainhash.Hash) ([]wire.ShardHeader, error)

GetShardHeaders mimics the wire protocol getheaders and headers messages by returning all headers on the main chain after the first known block in the locators, up until a block hash matches hashStop.

NOTE: This is a btcsuite extension ported from github.com/decred/dcrrpcclient.

func (*Client) GetTx

func (c *Client) GetTx(chainID uint32, txHash *chainhash.Hash, mempool bool) (*jaxjson.GetTxResult, error)

GetTx returns the transaction info

func (*Client) GetTxDetails

func (c *Client) GetTxDetails(chainID uint32, txHash *chainhash.Hash) (*jaxjson.TxRawResult, error)

GetTxDetails returns a transaction given its hash.

See GetRawTransactionVerbose to obtain additional information about the transaction.

func (*Client) GetTxOut

func (c *Client) GetTxOut(chainID uint32, txHash *chainhash.Hash, index uint32, mempool bool) (*jaxjson.GetTxOutResult, error)

GetTxOut returns the transaction output info if it's unspent and nil, otherwise.

func (*Client) GetTxOutStatus

func (c *Client) GetTxOutStatus(chainID uint32, outs []jaxjson.TxOutKey, onlyMempool bool) ([]jaxjson.TxOutStatus, error)

func (*Client) GetWork

func (c *Client) GetWork() (*jaxjson.GetWorkResult, error)

GetWork returns hash data to work on.

See GetWorkSubmit to submit the found solution.

func (*Client) GetWorkSubmit

func (c *Client) GetWorkSubmit(data string) (bool, error)

GetWorkSubmit submits a block header which is a solution to previously requested data and returns whether the solution was accepted.

See GetWork to request data to work on.

func (*Client) Host

func (c *Client) Host() Host

Host returns current host of the Client.

func (*Client) Hostname

func (c *Client) Hostname() string

Hostname returns current hostname of the Client.

func (*Client) InvalidateBlock

func (c *Client) InvalidateBlock(chainID uint32, blockHash *chainhash.Hash) error

InvalidateBlock invalidates a specific block.

func (*Client) ListAddressTransactions

func (c *Client) ListAddressTransactions(addresses []jaxutil.Address, account string) ([]jaxjson.ListTransactionsResult, error)

ListAddressTransactions returns information about all transactions associated with the provided addresses.

NOTE: This is a jaxwallet extension.

func (*Client) ListEADAddresses

func (c *Client) ListEADAddresses(shards []uint32, eadPublicKey *string) (*jaxjson.ListEADAddresses, error)

ListEADAddresses ...

func (*Client) ListShards

func (c *Client) ListShards() (*jaxjson.ShardListResult, error)

func (*Client) ListTxOut

func (c *Client) ListTxOut(chainID uint32) (*jaxjson.ListTxOutResult, error)

ListTxOut returns the transaction output info if it's unspent and nil, otherwise.

func (*Client) ManageShards

func (c *Client) ManageShards(action string, shardID uint32) error

ManageShards ... TODO: unsure if the code is correct

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

func (c *Client) Node(command jaxjson.NodeSubCmd, host string,
	connectSubCmd *string) error

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 disconnect a non-persistent one.

The connectSubCmd should be set either "perm" or "temp", depending on whether we are targeting a persistent or non-persistent peer. Passing nil will cause the default value to be used, which currently is "temp".

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

func (c *Client) RawRequest(shardID uint32, scope, 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 unmarshalled requests to another JSON-RPC server if a request cannot be handled directly.

func (*Client) RescanBlocks

func (c *Client) RescanBlocks(chainID uint32, blockHashes []chainhash.Hash) ([]jaxjson.RescannedBlock, error)

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

func (c *Client) SearchRawTransactions(chainID uint32, address jaxutil.Address, skip, count int, reverse bool, filterAddrs []string) ([]*wire.MsgTx, error)

SearchRawTransactions returns transactions that involve the passed address.

NOTE: Chain servers do not typically provide this capability unless it has specifically been enabled.

See SearchRawTransactionsVerbose to retrieve a list of data structures with information about the transactions instead of the transactions themselves.

func (*Client) SearchRawTransactionsVerbose

func (c *Client) SearchRawTransactionsVerbose(chainID uint32, address jaxutil.Address, skip,
	count int, includePrevOut, reverse bool, filterAddrs []string) ([]*jaxjson.SearchRawTransactionsResult, error)

SearchRawTransactionsVerbose returns a list of data structures that describe transactions which involve the passed address.

NOTE: Chain servers do not typically provide this capability unless it has specifically been enabled.

See SearchRawTransactions to retrieve a list of raw transactions instead.

func (*Client) SendRawTransaction

func (c *Client) SendRawTransaction(chainID uint32, tx *wire.MsgTx) (*chainhash.Hash, error)

SendRawTransaction submits the encoded transaction to the server which will then relay it to the network.

func (*Client) SetGenerate

func (c *Client) SetGenerate(enable bool, numCPUs int) error

SetGenerate sets the server to generate coins (mine) or not.

func (*Client) SubmitBlock

func (c *Client) SubmitBlock(chainID uint32, block *jaxutil.Block, options *jaxjson.SubmitBlockOptions) error

SubmitBlock attempts to submit a new block into the bitcoin network.

func (*Client) ValidateAddress

func (c *Client) ValidateAddress(address jaxutil.Address) (*jaxjson.ValidateAddressWalletResult, error)

ValidateAddress returns information about the given bitcoin address.

func (*Client) VerifyChain

func (c *Client) VerifyChain(chainID uint32) (bool, error)

VerifyChain requests the server to verify the block chain database using the default check level and number of blocks to verify.

See VerifyChainLevel and VerifyChainBlocks to override the defaults.

func (*Client) VerifyChainBlocks

func (c *Client) VerifyChainBlocks(chainID uint32, checkLevel, numBlocks int32) (bool, error)

VerifyChainBlocks requests the server to verify the block chain database using the passed check level and number of blocks to verify.

The check level controls how thorough the verification is with higher numbers increasing the amount of checks done as consequently how long the verification takes.

The number of blocks refers to the number of blocks from the end of the current longest chain.

See VerifyChain and VerifyChainLevel to use defaults.

func (*Client) VerifyChainLevel

func (c *Client) VerifyChainLevel(chainID uint32, checkLevel int32) (bool, error)

VerifyChainLevel requests the server to verify the blockchain database using the passed check level and default number of blocks to verify.

The check level controls how thorough the verification is with higher numbers increasing the amount of checks done as consequently how long the verification takes.

See VerifyChain to use the default check level and VerifyChainBlocks to override the number of blocks to verify.

func (*Client) VerifyMessage

func (c *Client) VerifyMessage(address jaxutil.Address, signature, message string) (bool, error)

VerifyMessage verifies a signed message.

NOTE: This function requires to the wallet to be unlocked. See the WalletPassphrase function for more details.

func (*Client) Version

func (c *Client) Version() (*jaxjson.NodeVersion, error)

Version returns information about the server's JSON-RPC API versions.

NOTE: This is a btcsuite extension ported from github.com/decred/dcrrpcclient.

type ConnConfig

type ConnConfig struct {
	Hosts []Host

	// Params is the string representing the network that the server
	// is running. If there is no parameter set in the config, then
	// mainnet will be used by default.
	Params 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

	// EnableBCInfoHacks is an option provided to enable compatibility hacks
	// when connecting to blockchain.info RPC server
	EnableBCInfoHacks bool

	// HTTPClientTimeout sets timeout before reconnecting to next RPC server if
	// there are more than one in configuration.
	HTTPClientTimeout time.Duration

	// HTTPClientRetryCount sets the number of attempts to send current request before
	// reconnecting to next RPC server if received timeout error.
	HTTPClientRetryCount int
}

ConnConfig describes the connection configuration parameters for the client. This

type Host

type Host struct {
	// Host is the IP address/hostname and port of the RPC server you want to connect to.
	Host 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
}

Host contains hostname with authentication credentials

type SigHashType

type SigHashType string

SigHashType enumerates the available signature hashing types that the SignRawTransaction function accepts.

const (
	// SigHashAll indicates ALL the outputs should be signed.
	SigHashAll SigHashType = "ALL"

	// SigHashNone indicates NONE of the outputs should be signed.  This
	// can be thought of as specifying the signer does not care where the
	// bitcoins go.
	SigHashNone SigHashType = "NONE"

	// SigHashSingle indicates that a SINGLE output should be signed.  This
	// can be thought of specifying the signer only cares about where ONE of
	// the outputs goes, but not any of the others.
	SigHashSingle SigHashType = "SINGLE"

	// SigHashAllAnyoneCanPay indicates that signer does not care where the
	// other inputs to the transaction come from, so it allows other people
	// to add inputs.  In addition, it uses the SigHashAll signing method
	// for outputs.
	SigHashAllAnyoneCanPay SigHashType = "ALL|ANYONECANPAY"

	// SigHashNoneAnyoneCanPay indicates that signer does not care where the
	// other inputs to the transaction come from, so it allows other people
	// to add inputs.  In addition, it uses the SigHashNone signing method
	// for outputs.
	SigHashNoneAnyoneCanPay SigHashType = "NONE|ANYONECANPAY"

	// SigHashSingleAnyoneCanPay indicates that signer does not care where
	// the other inputs to the transaction come from, so it allows other
	// people to add inputs.  In addition, it uses the SigHashSingle signing
	// method for outputs.
	SigHashSingleAnyoneCanPay SigHashType = "SINGLE|ANYONECANPAY"
)

Constants used to indicate the signature hash type for SignRawTransaction.

func (SigHashType) String

func (s SigHashType) String() string

String returns the SighHashType in human-readable form.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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