core

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2024 License: Apache-2.0 Imports: 39 Imported by: 0

README

Tendermint RPC

Pagination

Requests that return multiple items will be paginated to 30 items by default. You can specify further pages with the ?page parameter. You can also set a custom page size up to 100 with the ?per_page parameter.

Subscribing to events

The user can subscribe to events emitted by Tendermint, using /subscribe. If the maximum number of clients is reached or the client has too many subscriptions, an error will be returned. The subscription timeout is 5 sec. Each subscription has a buffer to accommodate short bursts of events or some slowness in clients. If the buffer gets full, the subscription will be canceled ("client is not pulling messages fast enough"). If Tendermint exits, all subscriptions are canceled ("Tendermint exited"). The user can unsubscribe using either /unsubscribe or /unsubscribe_all.

Documentation

Overview

Package core defines the Tendermint RPC endpoints.

Tendermint ships with its own JSONRPC library - https://github.com/tendermint/tendermint/tree/master/rpc/jsonrpc.

## Get the list

An HTTP Get request to the root RPC endpoint shows a list of available endpoints.

```bash curl 'localhost:26657' ```

> Response:

```plain Available endpoints: /abci_info /dump_consensus_state /genesis /net_info /num_unconfirmed_txs /status /health /unconfirmed_txs /unsafe_flush_mempool /validators

Endpoints that require arguments: /abci_query?path=_&data=_&prove=_ /block?height=_ /blockchain?minHeight=_&maxHeight=_ /broadcast_tx_async?tx=_ /broadcast_tx_commit?tx=_ /broadcast_tx_sync?tx=_ /commit?height=_ /dial_seeds?seeds=_ /dial_persistent_peers?persistent_peers=_ /subscribe?event=_ /tx?hash=_&prove=_ /unsubscribe?event=_ ```

Index

Constants

View Source
const (

	// SubscribeTimeout is the maximum time we wait to subscribe for an event.
	// must be less than the server's write timeout (see rpcserver.DefaultConfig)
	SubscribeTimeout = 5 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Environment

type Environment struct {
	// external, thread safe interfaces
	ProxyApp abciclient.Client

	// interfaces defined in types and above
	StateStore       sm.Store
	BlockStore       sm.BlockStore
	EvidencePool     sm.EvidencePool
	ConsensusState   *consensus.State
	ConsensusReactor *consensus.Reactor
	BlockSyncReactor *blocksync.Reactor

	IsListening bool
	Listeners   []string
	NodeInfo    types.NodeInfo

	// interfaces for new p2p interfaces
	PeerManager peerManager

	// objects
	ProTxHash         crypto.ProTxHash
	GenDoc            *types.GenesisDoc // cache the genesis structure
	EventSinks        []indexer.EventSink
	EventBus          *eventbus.EventBus // thread safe
	EventLog          *eventlog.Log
	Mempool           mempool.Mempool
	StateSyncMetricer statesync.Metricer

	Logger log.Logger

	Config config.RPCConfig
	// contains filtered or unexported fields
}

---------------------------------------------- Environment contains objects and interfaces used by the RPC. It is expected to be setup once during startup.

func (*Environment) ABCIInfo

func (env *Environment) ABCIInfo(ctx context.Context) (*coretypes.ResultABCIInfo, error)

ABCIInfo gets some info about the application. More: https://docs.tendermint.com/master/rpc/#/ABCI/abci_info

func (*Environment) ABCIQuery

ABCIQuery queries the application for some information. More: https://docs.tendermint.com/master/rpc/#/ABCI/abci_query

func (*Environment) Block

Block gets block at a given height. If no height is provided, it will fetch the latest block. More: https://docs.tendermint.com/master/rpc/#/Info/block

func (*Environment) BlockByHash

BlockByHash gets block by hash. More: https://docs.tendermint.com/master/rpc/#/Info/block_by_hash

func (*Environment) BlockResults

BlockResults gets ABCIResults at a given height. If no height is provided, it will fetch results for the latest block.

Results are for the height of the block containing the txs. More: https://docs.tendermint.com/master/rpc/#/Info/block_results

func (*Environment) BlockSearch

BlockSearch searches for a paginated set of blocks matching the provided query.

func (*Environment) BlockchainInfo

BlockchainInfo gets block headers for minHeight <= height <= maxHeight.

If maxHeight does not yet exist, blocks up to the current height will be returned. If minHeight does not exist (due to pruning), earliest existing height will be used.

At most 20 items will be returned. Block headers are returned in descending order (highest first).

More: https://docs.tendermint.com/master/rpc/#/Info/blockchain

func (*Environment) BroadcastEvidence

BroadcastEvidence broadcasts evidence of the misbehavior. More: https://docs.tendermint.com/master/rpc/#/Evidence/broadcast_evidence

func (*Environment) BroadcastTx

BroadcastTx returns with the response from CheckTx. Does not wait for DeliverTx result. More: https://docs.tendermint.com/master/rpc/#/Tx/broadcast_tx_sync

func (*Environment) BroadcastTxAsync

BroadcastTxAsync returns right away, with no response. Does not wait for CheckTx nor DeliverTx results. More: https://docs.tendermint.com/master/rpc/#/Tx/broadcast_tx_async Deprecated and should be removed in 0.37

func (*Environment) BroadcastTxCommit

BroadcastTxCommit returns with the responses from CheckTx and DeliverTx. More: https://docs.tendermint.com/master/rpc/#/Tx/broadcast_tx_commit

func (*Environment) BroadcastTxSync

Deprecated and should be remove in 0.37

func (*Environment) CheckTx

CheckTx checks the transaction without executing it. The transaction won't be added to the mempool either. More: https://docs.tendermint.com/master/rpc/#/Tx/check_tx

func (*Environment) Commit

Commit gets block commit at a given height. If no height is provided, it will fetch the commit for the latest block. More: https://docs.tendermint.com/master/rpc/#/Info/commit

func (*Environment) ConsensusParams

ConsensusParams gets the consensus parameters at the given block height. If no height is provided, it will fetch the latest consensus params. More: https://docs.tendermint.com/master/rpc/#/Info/consensus_params

func (*Environment) DumpConsensusState

func (env *Environment) DumpConsensusState(_ctx context.Context) (*coretypes.ResultDumpConsensusState, error)

DumpConsensusState dumps consensus state. UNSTABLE More: https://docs.tendermint.com/master/rpc/#/Info/dump_consensus_state

func (*Environment) Events

Events applies a query to the event log. If an event log is not enabled, Events reports an error. Otherwise, it filters the current contents of the log to return matching events.

Events returns up to maxItems of the newest eligible event items. An item is eligible if it is older than before (or before is zero), it is newer than after (or after is zero), and its data matches the filter. A nil filter matches all event data.

If before is zero and no eligible event items are available, Events waits for up to waitTime for a matching item to become available. The wait is terminated early if ctx ends.

If maxItems ≤ 0, a default positive number of events is chosen. The values of maxItems and waitTime may be capped to sensible internal maxima without reporting an error to the caller.

func (*Environment) Genesis

func (env *Environment) Genesis(_ctx context.Context) (*coretypes.ResultGenesis, error)

Genesis returns genesis file. More: https://docs.tendermint.com/master/rpc/#/Info/genesis

func (*Environment) GenesisChunked

func (*Environment) GetConsensusState

func (env *Environment) GetConsensusState(_ctx context.Context) (*coretypes.ResultConsensusState, error)

ConsensusState returns a concise summary of the consensus state. UNSTABLE More: https://docs.tendermint.com/master/rpc/#/Info/consensus_state

func (*Environment) Header

Header gets block header at a given height. If no height is provided, it will fetch the latest header. More: https://docs.tendermint.com/master/rpc/#/Info/header

func (*Environment) HeaderByHash

HeaderByHash gets header by hash. More: https://docs.tendermint.com/master/rpc/#/Info/header_by_hash

func (*Environment) Health

func (env *Environment) Health(_ctx context.Context) (*coretypes.ResultHealth, error)

Health gets node health. Returns empty result (200 OK) on success, no response - in case of an error. More: https://docs.tendermint.com/master/rpc/#/Info/health

func (*Environment) InitGenesisChunks

func (env *Environment) InitGenesisChunks() error

InitGenesisChunks configures the environment and should be called on service startup.

func (*Environment) NetInfo

func (env *Environment) NetInfo(_ctx context.Context) (*coretypes.ResultNetInfo, error)

NetInfo returns network info. More: https://docs.tendermint.com/master/rpc/#/Info/net_info

func (*Environment) NumUnconfirmedTxs

func (env *Environment) NumUnconfirmedTxs(_ctx context.Context) (*coretypes.ResultUnconfirmedTxs, error)

NumUnconfirmedTxs gets number of unconfirmed transactions. More: https://docs.tendermint.com/master/rpc/#/Info/num_unconfirmed_txs

func (*Environment) RemoveTx

func (env *Environment) RemoveTx(_ctx context.Context, req *coretypes.RequestRemoveTx) error

func (*Environment) StartService

func (env *Environment) StartService(ctx context.Context, conf *config.Config) ([]net.Listener, error)

StartService constructs and starts listeners for the RPC service according to the config object, returning an error if the service cannot be constructed or started. The listeners, which provide access to the service, run until the context is canceled.

func (*Environment) Status

func (env *Environment) Status(ctx context.Context) (*coretypes.ResultStatus, error)

Status returns Tendermint status including node info, pubkey, latest block hash, app hash, block height, current max peer block height, and time. More: https://docs.tendermint.com/master/rpc/#/Info/status

func (*Environment) Subscribe

Subscribe for events via WebSocket. More: https://docs.tendermint.com/master/rpc/#/Websocket/subscribe

func (*Environment) Tx

Tx allows you to query the transaction results. `nil` could mean the transaction is in the mempool, invalidated, or was not sent in the first place. More: https://docs.tendermint.com/master/rpc/#/Info/tx

func (*Environment) TxSearch

TxSearch allows you to query for multiple transactions results. It returns a list of transactions (maximum ?per_page entries) and the total count. More: https://docs.tendermint.com/master/rpc/#/Info/tx_search

func (*Environment) UnconfirmedTxs

UnconfirmedTxs gets unconfirmed transactions from the mempool in order of priority More: https://docs.tendermint.com/master/rpc/#/Info/unconfirmed_txs

func (*Environment) UnsafeFlushMempool

func (env *Environment) UnsafeFlushMempool(_ctx context.Context) (*coretypes.ResultUnsafeFlushMempool, error)

UnsafeFlushMempool removes all transactions from the mempool.

func (*Environment) Unsubscribe

Unsubscribe from events via WebSocket. More: https://docs.tendermint.com/master/rpc/#/Websocket/unsubscribe

func (*Environment) UnsubscribeAll

func (env *Environment) UnsubscribeAll(ctx context.Context) (*coretypes.ResultUnsubscribe, error)

UnsubscribeAll from all events via WebSocket. More: https://docs.tendermint.com/master/rpc/#/Websocket/unsubscribe_all

func (*Environment) Validators

Validators gets the validator set at the given block height.

If no height is provided, it will fetch the latest validator set. Note the validators are sorted by their voting power - this is the canonical order for the validators in the set as used in computing their Merkle root.

More: https://docs.tendermint.com/master/rpc/#/Info/validators

type RPCService

type RPCService interface {
	ABCIInfo(ctx context.Context) (*coretypes.ResultABCIInfo, error)
	ABCIQuery(ctx context.Context, req *coretypes.RequestABCIQuery) (*coretypes.ResultABCIQuery, error)
	Block(ctx context.Context, req *coretypes.RequestBlockInfo) (*coretypes.ResultBlock, error)
	BlockByHash(ctx context.Context, req *coretypes.RequestBlockByHash) (*coretypes.ResultBlock, error)
	BlockResults(ctx context.Context, req *coretypes.RequestBlockInfo) (*coretypes.ResultBlockResults, error)
	BlockSearch(ctx context.Context, req *coretypes.RequestBlockSearch) (*coretypes.ResultBlockSearch, error)
	BlockchainInfo(ctx context.Context, req *coretypes.RequestBlockchainInfo) (*coretypes.ResultBlockchainInfo, error)
	BroadcastEvidence(ctx context.Context, req *coretypes.RequestBroadcastEvidence) (*coretypes.ResultBroadcastEvidence, error)
	BroadcastTx(ctx context.Context, req *coretypes.RequestBroadcastTx) (*coretypes.ResultBroadcastTx, error)
	BroadcastTxAsync(ctx context.Context, req *coretypes.RequestBroadcastTx) (*coretypes.ResultBroadcastTx, error)
	BroadcastTxCommit(ctx context.Context, req *coretypes.RequestBroadcastTx) (*coretypes.ResultBroadcastTxCommit, error)
	BroadcastTxSync(ctx context.Context, req *coretypes.RequestBroadcastTx) (*coretypes.ResultBroadcastTx, error)
	CheckTx(ctx context.Context, req *coretypes.RequestCheckTx) (*coretypes.ResultCheckTx, error)
	Commit(ctx context.Context, req *coretypes.RequestBlockInfo) (*coretypes.ResultCommit, error)
	ConsensusParams(ctx context.Context, req *coretypes.RequestConsensusParams) (*coretypes.ResultConsensusParams, error)
	DumpConsensusState(ctx context.Context) (*coretypes.ResultDumpConsensusState, error)
	Events(ctx context.Context, req *coretypes.RequestEvents) (*coretypes.ResultEvents, error)
	Genesis(ctx context.Context) (*coretypes.ResultGenesis, error)
	GenesisChunked(ctx context.Context, req *coretypes.RequestGenesisChunked) (*coretypes.ResultGenesisChunk, error)
	GetConsensusState(ctx context.Context) (*coretypes.ResultConsensusState, error)
	Header(ctx context.Context, req *coretypes.RequestBlockInfo) (*coretypes.ResultHeader, error)
	HeaderByHash(ctx context.Context, req *coretypes.RequestBlockByHash) (*coretypes.ResultHeader, error)
	Health(ctx context.Context) (*coretypes.ResultHealth, error)
	NetInfo(ctx context.Context) (*coretypes.ResultNetInfo, error)
	NumUnconfirmedTxs(ctx context.Context) (*coretypes.ResultUnconfirmedTxs, error)
	RemoveTx(ctx context.Context, req *coretypes.RequestRemoveTx) error
	Status(ctx context.Context) (*coretypes.ResultStatus, error)
	Subscribe(ctx context.Context, req *coretypes.RequestSubscribe) (*coretypes.ResultSubscribe, error)
	Tx(ctx context.Context, req *coretypes.RequestTx) (*coretypes.ResultTx, error)
	TxSearch(ctx context.Context, req *coretypes.RequestTxSearch) (*coretypes.ResultTxSearch, error)
	UnconfirmedTxs(ctx context.Context, req *coretypes.RequestUnconfirmedTxs) (*coretypes.ResultUnconfirmedTxs, error)
	Unsubscribe(ctx context.Context, req *coretypes.RequestUnsubscribe) (*coretypes.ResultUnsubscribe, error)
	UnsubscribeAll(ctx context.Context) (*coretypes.ResultUnsubscribe, error)
	Validators(ctx context.Context, req *coretypes.RequestValidators) (*coretypes.ResultValidators, error)
}

RPCService defines the set of methods exported by the RPC service implementation, for use in constructing a routing table.

type RPCUnsafe

type RPCUnsafe interface {
	UnsafeFlushMempool(ctx context.Context) (*coretypes.ResultUnsafeFlushMempool, error)
}

RPCUnsafe defines the set of "unsafe" methods that may optionally be exported by the RPC service.

type RouteOptions

type RouteOptions struct {
	Unsafe bool // include "unsafe" methods (default false)
}

RouteOptions provide optional settings to NewRoutesMap. A nil *RouteOptions is ready for use and provides defaults as specified.

type RoutesMap

type RoutesMap map[string]*rpc.RPCFunc

func NewRoutesMap

func NewRoutesMap(svc RPCService, opts *RouteOptions) RoutesMap

NewRoutesMap constructs an RPC routing map for the given service implementation. If svc implements RPCUnsafe and opts.Unsafe is true, the "unsafe" methods will also be added to the map. The caller may also edit the map after construction; each call to NewRoutesMap returns a fresh map.

Jump to

Keyboard shortcuts

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