rpc_server

package
v0.38.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2023 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SubscribeTimeout       = 10 * time.Second
	SubscriptionBufferSize = 100
)

Variables

View Source
var Routes = map[string]*rpc.RPCFunc{

	"subscribe":       rpc.NewWSRPCFunc(Subscribe, "query"),
	"unsubscribe":     rpc.NewWSRPCFunc(Unsubscribe, "query"),
	"unsubscribe_all": rpc.NewWSRPCFunc(UnsubscribeAll, ""),

	"health":           rpc.NewRPCFunc(Health, ""),
	"status":           rpc.NewRPCFunc(Status, ""),
	"validators":       rpc.NewRPCFunc(Validators, "height,page,per_page"),
	"block":            rpc.NewRPCFunc(Block, "height", rpc.Cacheable("height")),
	"consensus_params": rpc.NewRPCFunc(ConsensusParams, "height", rpc.Cacheable("height")),

	"commit":        rpc.NewRPCFunc(Commit, "height", rpc.Cacheable("height")),
	"block_results": rpc.NewRPCFunc(BlockResults, "height", rpc.Cacheable("height")),
	"tx":            rpc.NewRPCFunc(Tx, "hash,prove", rpc.Cacheable()),
	"tx_search":     rpc.NewRPCFunc(TxSearch, "query,prove,page,per_page,order_by"),
	"block_search":  rpc.NewRPCFunc(BlockSearch, "query,page,per_page,order_by"),

	"broadcast_tx_commit": rpc.NewRPCFunc(BroadcastTxCommit, "tx"),
	"broadcast_tx_sync":   rpc.NewRPCFunc(BroadcastTxSync, "tx"),
	"broadcast_tx_async":  rpc.NewRPCFunc(BroadcastTxAsync, "tx"),

	"abci_query": rpc.NewRPCFunc(ABCIQuery, "path,data,height,prove"),
	"abci_info":  rpc.NewRPCFunc(ABCIInfo, ""),

	"advance_blocks":            rpc.NewRPCFunc(AdvanceBlocks, "num_blocks"),
	"set_signing_status":        rpc.NewRPCFunc(SetSigningStatus, "private_key_address,status"),
	"advance_time":              rpc.NewRPCFunc(AdvanceTime, "duration_in_seconds"),
	"cause_double_sign":         rpc.NewRPCFunc(CauseDoubleSign, "private_key_address"),
	"cause_light_client_attack": rpc.NewRPCFunc(CauseLightClientAttack, "private_key_address,misbehaviour_type"),
}

Functions

func ABCIInfo

func ABCIInfo(ctx *rpctypes.Context) (*ctypes.ResultABCIInfo, error)

func ABCIQuery

func ABCIQuery(
	ctx *rpctypes.Context,
	path string,
	data bytes.HexBytes,
	height int64,
	prove bool,
) (*ctypes.ResultABCIQuery, error)

func Block

func Block(ctx *rpctypes.Context, heightPtr *int64) (*ctypes.ResultBlock, error)

func BlockResults

func BlockResults(ctx *rpctypes.Context, heightPtr *int64) (*ctypes.ResultBlockResults, error)

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. Thus response.results.deliver_tx[5] is the results of executing getBlock(h).Txs[5] More: https://docs.cometbft.com/v0.37/rpc/#/Info/block_results

func BlockSearch

func BlockSearch(
	ctx *rpctypes.Context,
	query string,
	pagePtr, perPagePtr *int,
	orderBy string,
) (*ctypes.ResultBlockSearch, error)

BlockSearch searches for a paginated set of blocks matching BeginBlock and EndBlock event search criteria.

func BroadcastTx

func BroadcastTx(tx *types.Tx) (*ctypes.ResultBroadcastTxCommit, error)

BroadcastTx delivers a transaction to the ABCI client, includes it in the next block, then returns.

func BroadcastTxAsync

func BroadcastTxAsync(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcastTx, error)

BroadcastTxAsync would normally broadcast a transaction and return immediately. In our case, we always include the transition in the next block, and return when that block is committed. ResultBroadcastTx is empty, since we do not return the result of CheckTx nor DeliverTx.

func BroadcastTxCommit

func BroadcastTxCommit(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error)

BroadcastTxCommit broadcasts a transaction, and wait until it is included in a block and and comitted. In our case, this means running a block with just the the transition, then return.

func BroadcastTxSync

func BroadcastTxSync(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcastTx, error)

BroadcastTxSync would normally broadcast a transaction and wait until it gets the result from CheckTx. In our case, we run a block with just the transition in it, then return.

func Commit

func Commit(ctx *rpctypes.Context, heightPtr *int64) (*ctypes.ResultCommit, error)

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.cometbft.com/main/rpc/#/Info/commit

func ConsensusParams

func ConsensusParams(ctx *rpctypes.Context, heightPtr *int64) (*ctypes.ResultConsensusParams, error)

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.cometbft.com/v0.37/rpc/#/Info/consensus_params

func ExtraLogHandler

func ExtraLogHandler(handler http.Handler, logger log.Logger) http.Handler

RecoverAndLogHandler wraps an HTTP handler, adding error logging. If the inner function panics, the outer function recovers, logs, sends an HTTP 500 error response.

func Health

func Health(ctx *rpctypes.Context) (*ctypes.ResultHealth, error)

Health gets node health. Returns empty result (200 OK) on success, no response - in case of an error.

func StartRPCServer

func StartRPCServer(listenAddr string, logger log.Logger, config *rpcserver.Config)

func StartRPCServerWithDefaultConfig

func StartRPCServerWithDefaultConfig(listenAddr string, logger log.Logger)

func Status

func Status(ctx *rpctypes.Context) (*ctypes.ResultStatus, error)

Status returns CometBFT status including node info, pubkey, latest block hash, app hash, block height and time. More: https://docs.cometbft.com/v0.37/rpc/#/Info/status

func Subscribe

func Subscribe(ctx *rpctypes.Context, query string) (*ctypes.ResultSubscribe, error)

Subscribe for events via WebSocket. More: https://docs.cometbft.com/v0.38.x/rpc/#/Websocket/subscribe

func Tx

func Tx(ctx *rpctypes.Context, hash []byte, prove bool) (*ctypes.ResultTx, error)

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/v0.34/rpc/#/Info/tx

func TxSearch

func TxSearch(
	ctx *rpctypes.Context,
	query string,
	prove bool,
	pagePtr, perPagePtr *int,
	orderBy string,
) (*ctypes.ResultTxSearch, error)

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/v0.34/rpc/#/Info/tx_search

func Unsubscribe

func Unsubscribe(ctx *rpctypes.Context, query string) (*ctypes.ResultUnsubscribe, error)

Unsubscribe from events via WebSocket. More: https://docs.cometbft.com/v0.38.x/rpc/#/Websocket/unsubscribe

func UnsubscribeAll

func UnsubscribeAll(ctx *rpctypes.Context) (*ctypes.ResultUnsubscribe, error)

UnsubscribeAll from all events via WebSocket. More: https://docs.cometbft.com/v0.38.x/rpc/#/Websocket/unsubscribe_all

func Validators

func Validators(ctx *rpctypes.Context, heightPtr *int64, pagePtr, perPagePtr *int) (*ctypes.ResultValidators, error)

func WriteRPCResponseHTTP

func WriteRPCResponseHTTP(w http.ResponseWriter, res ...types.RPCResponse) error

WriteRPCResponseHTTP marshals res as JSON (with indent) and writes it to w.

func WriteRPCResponseHTTPError

func WriteRPCResponseHTTPError(
	w http.ResponseWriter,
	httpCode int,
	res types.RPCResponse,
) error

WriteRPCResponseHTTPError marshals res as JSON (with indent) and writes it to w.

source: https://www.jsonrpc.org/historical/json-rpc-over-http.html

Types

type ResultAdvanceBlocks

type ResultAdvanceBlocks struct{}

func AdvanceBlocks

func AdvanceBlocks(ctx *rpctypes.Context, numBlocks int) (*ResultAdvanceBlocks, error)

AdvanceBlocks advances the block height by numBlocks, running empty blocks. This API is specific to CometMock.

type ResultAdvanceTime

type ResultAdvanceTime struct {
	NewTime time.Time `json:"new_time"`
}

func AdvanceTime

func AdvanceTime(ctx *rpctypes.Context, duration_in_seconds time.Duration) (*ResultAdvanceTime, error)

AdvanceTime advances the block time by the given duration. This API is specific to CometMock.

type ResultCauseDoubleSign

type ResultCauseDoubleSign struct{}

func CauseDoubleSign

func CauseDoubleSign(ctx *rpctypes.Context, privateKeyAddress string) (*ResultCauseDoubleSign, error)

type ResultCauseLightClientAttack

type ResultCauseLightClientAttack struct{}

func CauseLightClientAttack

func CauseLightClientAttack(ctx *rpctypes.Context, privateKeyAddress, misbehaviourType string) (*ResultCauseLightClientAttack, error)

type ResultSetSigningStatus

type ResultSetSigningStatus struct {
	NewSigningStatusMap map[string]bool `json:"new_signing_status_map"`
}

func SetSigningStatus

func SetSigningStatus(ctx *rpctypes.Context, privateKeyAddress string, status string) (*ResultSetSigningStatus, error)

Jump to

Keyboard shortcuts

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