Documentation ¶
Overview ¶
Package client provides a general purpose interface (Client) for connecting to a tendermint node, as well as higher-level functionality.
The main implementation for production code is client.HTTP, which connects via http to the jsonrpc interface of the tendermint node.
For connecting to a node running in the same process (eg. when compiling the abci app in the same process), you can use the client.Local implementation.
For mocking out server responses during testing to see behavior for arbitrary return values, use the mock package.
In addition to the Client interface, which should be used externally for maximum flexibility and testability, and two implementations, this package also provides helper functions that work on any Client implementation.
Index ¶
- Variables
- type ABCIClient
- type ABCIQueryOptions
- type Client
- type HistoryClient
- type Local
- func (c *Local) ABCIInfo() (*ctypes.ResultABCIInfo, error)
- func (c *Local) ABCIQuery(path string, data []byte) (*ctypes.ResultABCIQuery, error)
- func (c *Local) ABCIQueryWithOptions(path string, data []byte, opts ABCIQueryOptions) (*ctypes.ResultABCIQuery, error)
- func (c *Local) Block(height *int64) (*ctypes.ResultBlock, error)
- func (c *Local) BlockResults(height *int64) (*ctypes.ResultBlockResults, error)
- func (c *Local) BlockchainInfo(minHeight, maxHeight int64) (*ctypes.ResultBlockchainInfo, error)
- func (c *Local) BroadcastTxAsync(tx types.Tx) (*ctypes.ResultBroadcastTx, error)
- func (c *Local) BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error)
- func (c *Local) BroadcastTxSync(tx types.Tx) (*ctypes.ResultBroadcastTx, error)
- func (c *Local) Commit(height *int64) (*ctypes.ResultCommit, error)
- func (c *Local) ConsensusParams(height *int64) (*ctypes.ResultConsensusParams, error)
- func (c *Local) ConsensusState() (*ctypes.ResultConsensusState, error)
- func (c *Local) DialPeers(peers []string, persistent bool) (*ctypes.ResultDialPeers, error)
- func (c *Local) DialSeeds(seeds []string) (*ctypes.ResultDialSeeds, error)
- func (c *Local) DumpConsensusState() (*ctypes.ResultDumpConsensusState, error)
- func (c *Local) Genesis() (*ctypes.ResultGenesis, error)
- func (c *Local) Health() (*ctypes.ResultHealth, error)
- func (c *Local) NetInfo() (*ctypes.ResultNetInfo, error)
- func (c *Local) NumUnconfirmedTxs() (*ctypes.ResultUnconfirmedTxs, error)
- func (c *Local) SetLogger(l *slog.Logger)
- func (c *Local) Status() (*ctypes.ResultStatus, error)
- func (c *Local) Tx(hash []byte) (*ctypes.ResultTx, error)
- func (c *Local) UnconfirmedTxs(limit int) (*ctypes.ResultUnconfirmedTxs, error)
- func (c *Local) Validators(height *int64) (*ctypes.ResultValidators, error)
- type MempoolClient
- type NetworkClient
- type Option
- type RPCBatch
- func (b *RPCBatch) ABCIInfo() error
- func (b *RPCBatch) ABCIQuery(path string, data []byte) error
- func (b *RPCBatch) ABCIQueryWithOptions(path string, data []byte, opts ABCIQueryOptions) error
- func (b *RPCBatch) Block(height *int64) error
- func (b *RPCBatch) BlockResults(height *int64) error
- func (b *RPCBatch) BlockchainInfo(minHeight, maxHeight int64) error
- func (b *RPCBatch) BroadcastTxAsync(tx types.Tx) error
- func (b *RPCBatch) BroadcastTxCommit(tx types.Tx) error
- func (b *RPCBatch) BroadcastTxSync(tx types.Tx) error
- func (b *RPCBatch) Clear() int
- func (b *RPCBatch) Commit(height *int64) error
- func (b *RPCBatch) ConsensusParams(height *int64) error
- func (b *RPCBatch) ConsensusState() error
- func (b *RPCBatch) Count() int
- func (b *RPCBatch) DumpConsensusState() error
- func (b *RPCBatch) Genesis() error
- func (b *RPCBatch) Health() error
- func (b *RPCBatch) NetInfo() error
- func (b *RPCBatch) NumUnconfirmedTxs() error
- func (b *RPCBatch) Send(ctx context.Context) ([]any, error)
- func (b *RPCBatch) Status() error
- func (b *RPCBatch) Tx(hash []byte) error
- func (b *RPCBatch) UnconfirmedTxs(limit int) error
- func (b *RPCBatch) Validators(height *int64) error
- type RPCClient
- func (c *RPCClient) ABCIInfo() (*ctypes.ResultABCIInfo, error)
- func (c *RPCClient) ABCIQuery(path string, data []byte) (*ctypes.ResultABCIQuery, error)
- func (c *RPCClient) ABCIQueryWithOptions(path string, data []byte, opts ABCIQueryOptions) (*ctypes.ResultABCIQuery, error)
- func (c *RPCClient) Block(height *int64) (*ctypes.ResultBlock, error)
- func (c *RPCClient) BlockResults(height *int64) (*ctypes.ResultBlockResults, error)
- func (c *RPCClient) BlockchainInfo(minHeight, maxHeight int64) (*ctypes.ResultBlockchainInfo, error)
- func (c *RPCClient) BroadcastTxAsync(tx types.Tx) (*ctypes.ResultBroadcastTx, error)
- func (c *RPCClient) BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error)
- func (c *RPCClient) BroadcastTxSync(tx types.Tx) (*ctypes.ResultBroadcastTx, error)
- func (c *RPCClient) Close() error
- func (c *RPCClient) Commit(height *int64) (*ctypes.ResultCommit, error)
- func (c *RPCClient) ConsensusParams(height *int64) (*ctypes.ResultConsensusParams, error)
- func (c *RPCClient) ConsensusState() (*ctypes.ResultConsensusState, error)
- func (c *RPCClient) DumpConsensusState() (*ctypes.ResultDumpConsensusState, error)
- func (c *RPCClient) Genesis() (*ctypes.ResultGenesis, error)
- func (c *RPCClient) Health() (*ctypes.ResultHealth, error)
- func (c *RPCClient) NetInfo() (*ctypes.ResultNetInfo, error)
- func (c *RPCClient) NewBatch() *RPCBatch
- func (c *RPCClient) NumUnconfirmedTxs() (*ctypes.ResultUnconfirmedTxs, error)
- func (c *RPCClient) Status() (*ctypes.ResultStatus, error)
- func (c *RPCClient) Tx(hash []byte) (*ctypes.ResultTx, error)
- func (c *RPCClient) UnconfirmedTxs(limit int) (*ctypes.ResultUnconfirmedTxs, error)
- func (c *RPCClient) Validators(height *int64) (*ctypes.ResultValidators, error)
- type SignClient
- type StatusClient
- type TxClient
Constants ¶
This section is empty.
Variables ¶
var DefaultABCIQueryOptions = ABCIQueryOptions{Height: 0, Prove: false}
DefaultABCIQueryOptions are latest height (0) and prove false.
Functions ¶
This section is empty.
Types ¶
type ABCIClient ¶
type ABCIClient interface { // Reading from abci app ABCIInfo() (*ctypes.ResultABCIInfo, error) ABCIQuery(path string, data []byte) (*ctypes.ResultABCIQuery, error) ABCIQueryWithOptions(path string, data []byte, opts ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) // Writing to abci app BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) BroadcastTxAsync(tx types.Tx) (*ctypes.ResultBroadcastTx, error) BroadcastTxSync(tx types.Tx) (*ctypes.ResultBroadcastTx, error) }
ABCIClient groups together the functionality that principally affects the ABCI app.
In many cases this will be all we want, so we can accept an interface which is easier to mock.
type ABCIQueryOptions ¶
ABCIQueryOptions can be used to provide options for ABCIQuery call other than the DefaultABCIQueryOptions.
type Client ¶
type Client interface { ABCIClient HistoryClient NetworkClient SignClient StatusClient MempoolClient TxClient }
Client wraps most important rpc calls a client would make.
NOTE: Events cannot be subscribed to from the RPC APIs. For events subscriptions and filters and queries, an external API must be used that first synchronously consumes the events from the node's synchronous event switch, or reads logged events from the filesystem.
type HistoryClient ¶
type HistoryClient interface { Genesis() (*ctypes.ResultGenesis, error) BlockchainInfo(minHeight, maxHeight int64) (*ctypes.ResultBlockchainInfo, error) }
HistoryClient provides access to data from genesis to now in large chunks.
type Local ¶
Local is a Client implementation that directly executes the rpc functions on a given node, without going through any network connection.
As this connects directly to a Node instance, a Local client only works after the Node has been started. Note that the way this works is (alas) through the use of singletons in rpc/core. As a consequence, you may only have one active node at a time, and Local can only connect to that specific node. Keep this in mind for parallel tests, or attempting to simulate a network.
This implementation is useful for:
- Running tests against a node in-process without the overhead of going through an http server
- Communication between an ABCI app and Tendermint core when they are compiled in process.
For real clients, you probably want to use the [HTTP] client. For more powerful control during testing, you probably want the "client/mock" package.
func NewLocal ¶
func NewLocal() *Local
NewLocal configures a client that calls the Node directly through rpc/core, without requiring a network connection. See Local.
func (*Local) ABCIQueryWithOptions ¶
func (c *Local) ABCIQueryWithOptions(path string, data []byte, opts ABCIQueryOptions) (*ctypes.ResultABCIQuery, error)
func (*Local) BlockResults ¶
func (c *Local) BlockResults(height *int64) (*ctypes.ResultBlockResults, error)
func (*Local) BlockchainInfo ¶
func (c *Local) BlockchainInfo(minHeight, maxHeight int64) (*ctypes.ResultBlockchainInfo, error)
func (*Local) BroadcastTxAsync ¶
func (*Local) BroadcastTxCommit ¶
func (*Local) BroadcastTxSync ¶
func (*Local) ConsensusParams ¶
func (c *Local) ConsensusParams(height *int64) (*ctypes.ResultConsensusParams, error)
func (*Local) ConsensusState ¶
func (c *Local) ConsensusState() (*ctypes.ResultConsensusState, error)
func (*Local) DialSeeds ¶
func (c *Local) DialSeeds(seeds []string) (*ctypes.ResultDialSeeds, error)
func (*Local) DumpConsensusState ¶
func (c *Local) DumpConsensusState() (*ctypes.ResultDumpConsensusState, error)
func (*Local) NumUnconfirmedTxs ¶
func (c *Local) NumUnconfirmedTxs() (*ctypes.ResultUnconfirmedTxs, error)
func (*Local) UnconfirmedTxs ¶
func (c *Local) UnconfirmedTxs(limit int) (*ctypes.ResultUnconfirmedTxs, error)
func (*Local) Validators ¶
func (c *Local) Validators(height *int64) (*ctypes.ResultValidators, error)
type MempoolClient ¶
type MempoolClient interface { UnconfirmedTxs(limit int) (*ctypes.ResultUnconfirmedTxs, error) NumUnconfirmedTxs() (*ctypes.ResultUnconfirmedTxs, error) }
MempoolClient shows us data about current mempool state.
type NetworkClient ¶
type NetworkClient interface { NetInfo() (*ctypes.ResultNetInfo, error) DumpConsensusState() (*ctypes.ResultDumpConsensusState, error) ConsensusState() (*ctypes.ResultConsensusState, error) ConsensusParams(height *int64) (*ctypes.ResultConsensusParams, error) Health() (*ctypes.ResultHealth, error) }
NetworkClient is general info about the network state. May not be needed usually.
type Option ¶
type Option func(client *RPCClient)
func WithRequestTimeout ¶
WithRequestTimeout sets the request timeout
type RPCBatch ¶
type RPCBatch struct {
// contains filtered or unexported fields
}
func (*RPCBatch) ABCIQueryWithOptions ¶
func (b *RPCBatch) ABCIQueryWithOptions(path string, data []byte, opts ABCIQueryOptions) error
func (*RPCBatch) BlockResults ¶
func (*RPCBatch) BlockchainInfo ¶
func (*RPCBatch) ConsensusParams ¶
func (*RPCBatch) ConsensusState ¶
func (*RPCBatch) DumpConsensusState ¶
func (*RPCBatch) NumUnconfirmedTxs ¶
func (*RPCBatch) UnconfirmedTxs ¶
func (*RPCBatch) Validators ¶
type RPCClient ¶
type RPCClient struct {
// contains filtered or unexported fields
}
RPCClient encompasses common RPC client methods
func NewHTTPClient ¶
NewHTTPClient takes a remote endpoint in the form <protocol>://<host>:<port>, and returns an HTTP client that communicates with a Tendermint node over JSON RPC.
Request batching is available for JSON RPC requests over HTTP, which conforms to the JSON RPC specification (https://www.jsonrpc.org/specification#batch). See the example for more details
func NewRPCClient ¶
NewRPCClient creates a new RPC client instance with the given caller
func NewWSClient ¶
NewWSClient takes a remote endpoint in the form <protocol>://<host>:<port>, and returns a WS client that communicates with a Tendermint node over WS connection.
Request batching is available for JSON RPC requests over WS, which conforms to the JSON RPC specification (https://www.jsonrpc.org/specification#batch). See the example for more details
func (*RPCClient) ABCIQueryWithOptions ¶
func (c *RPCClient) ABCIQueryWithOptions(path string, data []byte, opts ABCIQueryOptions) (*ctypes.ResultABCIQuery, error)
func (*RPCClient) BlockResults ¶
func (c *RPCClient) BlockResults(height *int64) (*ctypes.ResultBlockResults, error)
func (*RPCClient) BlockchainInfo ¶
func (c *RPCClient) BlockchainInfo(minHeight, maxHeight int64) (*ctypes.ResultBlockchainInfo, error)
func (*RPCClient) BroadcastTxAsync ¶
func (*RPCClient) BroadcastTxCommit ¶
func (*RPCClient) BroadcastTxSync ¶
func (*RPCClient) ConsensusParams ¶
func (c *RPCClient) ConsensusParams(height *int64) (*ctypes.ResultConsensusParams, error)
func (*RPCClient) ConsensusState ¶
func (c *RPCClient) ConsensusState() (*ctypes.ResultConsensusState, error)
func (*RPCClient) DumpConsensusState ¶
func (c *RPCClient) DumpConsensusState() (*ctypes.ResultDumpConsensusState, error)
func (*RPCClient) NumUnconfirmedTxs ¶
func (c *RPCClient) NumUnconfirmedTxs() (*ctypes.ResultUnconfirmedTxs, error)
func (*RPCClient) UnconfirmedTxs ¶
func (c *RPCClient) UnconfirmedTxs(limit int) (*ctypes.ResultUnconfirmedTxs, error)
func (*RPCClient) Validators ¶
func (c *RPCClient) Validators(height *int64) (*ctypes.ResultValidators, error)
type SignClient ¶
type SignClient interface { Block(height *int64) (*ctypes.ResultBlock, error) BlockResults(height *int64) (*ctypes.ResultBlockResults, error) Commit(height *int64) (*ctypes.ResultCommit, error) Validators(height *int64) (*ctypes.ResultValidators, error) }
SignClient groups together the functionality needed to get valid signatures and prove anything about the chain.
type StatusClient ¶
type StatusClient interface {
Status() (*ctypes.ResultStatus, error)
}
StatusClient provides access to general chain info.