client

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2024 License: Apache-2.0, UNKNOWN not legal advice Imports: 0 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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

type ABCIQueryOptions struct {
	Height int64
	Prove  bool
}

ABCIQueryOptions can be used to provide options for ABCIQuery call other than the DefaultABCIQueryOptions.

type Client

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

type Local struct {
	Logger *slog.Logger
	// contains filtered or unexported fields
}

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

func (c *Local) ABCIInfo() (*ctypes.ResultABCIInfo, error)

func (*Local) ABCIQuery

func (c *Local) ABCIQuery(path string, data []byte) (*ctypes.ResultABCIQuery, error)

func (*Local) ABCIQueryWithOptions

func (c *Local) ABCIQueryWithOptions(path string, data []byte, opts ABCIQueryOptions) (*ctypes.ResultABCIQuery, error)

func (*Local) Block

func (c *Local) Block(height *int64) (*ctypes.ResultBlock, 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 (c *Local) BroadcastTxAsync(tx types.Tx) (*ctypes.ResultBroadcastTx, error)

func (*Local) BroadcastTxCommit

func (c *Local) BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error)

func (*Local) BroadcastTxSync

func (c *Local) BroadcastTxSync(tx types.Tx) (*ctypes.ResultBroadcastTx, error)

func (*Local) Commit

func (c *Local) Commit(height *int64) (*ctypes.ResultCommit, error)

func (*Local) ConsensusParams

func (c *Local) ConsensusParams(height *int64) (*ctypes.ResultConsensusParams, error)

func (*Local) ConsensusState

func (c *Local) ConsensusState() (*ctypes.ResultConsensusState, error)

func (*Local) DialPeers

func (c *Local) DialPeers(peers []string, persistent bool) (*ctypes.ResultDialPeers, 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) Genesis

func (c *Local) Genesis() (*ctypes.ResultGenesis, error)

func (*Local) Health

func (c *Local) Health() (*ctypes.ResultHealth, error)

func (*Local) NetInfo

func (c *Local) NetInfo() (*ctypes.ResultNetInfo, error)

func (*Local) NumUnconfirmedTxs

func (c *Local) NumUnconfirmedTxs() (*ctypes.ResultUnconfirmedTxs, error)

func (*Local) SetLogger

func (c *Local) SetLogger(l *slog.Logger)

SetLogger allows to set a logger on the client.

func (*Local) Status

func (c *Local) Status() (*ctypes.ResultStatus, error)

func (*Local) Tx

func (c *Local) Tx(hash []byte) (*ctypes.ResultTx, 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

func WithRequestTimeout(timeout time.Duration) Option

WithRequestTimeout sets the request timeout

type RPCBatch

type RPCBatch struct {
	// contains filtered or unexported fields
}

func (*RPCBatch) ABCIInfo

func (b *RPCBatch) ABCIInfo() error

func (*RPCBatch) ABCIQuery

func (b *RPCBatch) ABCIQuery(path string, data []byte) error

func (*RPCBatch) ABCIQueryWithOptions

func (b *RPCBatch) ABCIQueryWithOptions(path string, data []byte, opts ABCIQueryOptions) error

func (*RPCBatch) Block

func (b *RPCBatch) Block(height *int64) error

func (*RPCBatch) BlockResults

func (b *RPCBatch) BlockResults(height *int64) error

func (*RPCBatch) BlockchainInfo

func (b *RPCBatch) BlockchainInfo(minHeight, maxHeight int64) error

func (*RPCBatch) BroadcastTxAsync

func (b *RPCBatch) BroadcastTxAsync(tx types.Tx) error

func (*RPCBatch) BroadcastTxCommit

func (b *RPCBatch) BroadcastTxCommit(tx types.Tx) error

func (*RPCBatch) BroadcastTxSync

func (b *RPCBatch) BroadcastTxSync(tx types.Tx) error

func (*RPCBatch) Clear

func (b *RPCBatch) Clear() int

func (*RPCBatch) Commit

func (b *RPCBatch) Commit(height *int64) error

func (*RPCBatch) ConsensusParams

func (b *RPCBatch) ConsensusParams(height *int64) error

func (*RPCBatch) ConsensusState

func (b *RPCBatch) ConsensusState() error

func (*RPCBatch) Count

func (b *RPCBatch) Count() int

func (*RPCBatch) DumpConsensusState

func (b *RPCBatch) DumpConsensusState() error

func (*RPCBatch) Genesis

func (b *RPCBatch) Genesis() error

func (*RPCBatch) Health

func (b *RPCBatch) Health() error

func (*RPCBatch) NetInfo

func (b *RPCBatch) NetInfo() error

func (*RPCBatch) NumUnconfirmedTxs

func (b *RPCBatch) NumUnconfirmedTxs() error

func (*RPCBatch) Send

func (b *RPCBatch) Send(ctx context.Context) ([]any, error)

func (*RPCBatch) Status

func (b *RPCBatch) Status() error

func (*RPCBatch) Tx

func (b *RPCBatch) Tx(hash []byte) error

func (*RPCBatch) UnconfirmedTxs

func (b *RPCBatch) UnconfirmedTxs(limit int) error

func (*RPCBatch) Validators

func (b *RPCBatch) Validators(height *int64) error

type RPCClient

type RPCClient struct {
	// contains filtered or unexported fields
}

RPCClient encompasses common RPC client methods

func NewHTTPClient

func NewHTTPClient(rpcURL string) (*RPCClient, error)

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

func NewRPCClient(caller rpcclient.Client, opts ...Option) *RPCClient

NewRPCClient creates a new RPC client instance with the given caller

func NewWSClient

func NewWSClient(rpcURL string) (*RPCClient, error)

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

func (c *RPCClient) ABCIInfo() (*ctypes.ResultABCIInfo, error)

func (*RPCClient) ABCIQuery

func (c *RPCClient) ABCIQuery(path string, data []byte) (*ctypes.ResultABCIQuery, error)

func (*RPCClient) ABCIQueryWithOptions

func (c *RPCClient) ABCIQueryWithOptions(path string, data []byte, opts ABCIQueryOptions) (*ctypes.ResultABCIQuery, error)

func (*RPCClient) Block

func (c *RPCClient) Block(height *int64) (*ctypes.ResultBlock, 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 (c *RPCClient) BroadcastTxAsync(tx types.Tx) (*ctypes.ResultBroadcastTx, error)

func (*RPCClient) BroadcastTxCommit

func (c *RPCClient) BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error)

func (*RPCClient) BroadcastTxSync

func (c *RPCClient) BroadcastTxSync(tx types.Tx) (*ctypes.ResultBroadcastTx, error)

func (*RPCClient) Close

func (c *RPCClient) Close() error

Close attempts to gracefully close the RPC client

func (*RPCClient) Commit

func (c *RPCClient) Commit(height *int64) (*ctypes.ResultCommit, error)

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

func (c *RPCClient) Genesis() (*ctypes.ResultGenesis, error)

func (*RPCClient) Health

func (c *RPCClient) Health() (*ctypes.ResultHealth, error)

func (*RPCClient) NetInfo

func (c *RPCClient) NetInfo() (*ctypes.ResultNetInfo, error)

func (*RPCClient) NewBatch

func (c *RPCClient) NewBatch() *RPCBatch

NewBatch creates a new RPC batch

func (*RPCClient) NumUnconfirmedTxs

func (c *RPCClient) NumUnconfirmedTxs() (*ctypes.ResultUnconfirmedTxs, error)

func (*RPCClient) Status

func (c *RPCClient) Status() (*ctypes.ResultStatus, error)

func (*RPCClient) Tx

func (c *RPCClient) Tx(hash []byte) (*ctypes.ResultTx, 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.

type TxClient

type TxClient interface {
	Tx(hash []byte) (*ctypes.ResultTx, error)
}

Jump to

Keyboard shortcuts

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