mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-06 21:36:26 +00:00
rpc: consolidate RPC route map construction (#7582)
Define interfaces for the various methods a service may implement. This is basically just the set of things on Environment that are exported as RPCs, but these are also implemented by the light proxy. * internal/rpc: use NewRoutesMap to construct routes on service start * light/proxy: use NewRoutesMap to construct RPC routes
This commit is contained in:
@@ -223,11 +223,9 @@ func (env *Environment) StartService(ctx context.Context, conf *config.Config) (
|
||||
}
|
||||
|
||||
listenAddrs := strings.SplitAndTrimEmpty(conf.RPC.ListenAddress, ",", " ")
|
||||
routes := env.GetRoutes()
|
||||
|
||||
if conf.RPC.Unsafe {
|
||||
env.AddUnsafe(routes)
|
||||
}
|
||||
routes := NewRoutesMap(env, &RouteOptions{
|
||||
Unsafe: conf.RPC.Unsafe,
|
||||
})
|
||||
|
||||
cfg := rpcserver.DefaultConfig()
|
||||
cfg.MaxBodyBytes = conf.RPC.MaxBodyBytes
|
||||
|
||||
@@ -1,62 +1,120 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/tendermint/tendermint/libs/bytes"
|
||||
"github.com/tendermint/tendermint/rpc/coretypes"
|
||||
rpc "github.com/tendermint/tendermint/rpc/jsonrpc/server"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
)
|
||||
|
||||
// TODO: better system than "unsafe" prefix
|
||||
|
||||
type RoutesMap map[string]*rpc.RPCFunc
|
||||
|
||||
// Routes is a map of available routes.
|
||||
func (env *Environment) GetRoutes() RoutesMap {
|
||||
return RoutesMap{
|
||||
// RouteOptions provide optional settings to NewRoutesMap. A nil *RouteOptions
|
||||
// is ready for use and provides defaults as specified.
|
||||
type RouteOptions struct {
|
||||
Unsafe bool // include "unsafe" methods (default false)
|
||||
}
|
||||
|
||||
// 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.
|
||||
func NewRoutesMap(svc RPCService, opts *RouteOptions) RoutesMap {
|
||||
if opts == nil {
|
||||
opts = new(RouteOptions)
|
||||
}
|
||||
out := RoutesMap{
|
||||
// subscribe/unsubscribe are reserved for websocket events.
|
||||
"subscribe": rpc.NewWSRPCFunc(env.Subscribe, "query"),
|
||||
"unsubscribe": rpc.NewWSRPCFunc(env.Unsubscribe, "query"),
|
||||
"unsubscribe_all": rpc.NewWSRPCFunc(env.UnsubscribeAll, ""),
|
||||
"subscribe": rpc.NewWSRPCFunc(svc.Subscribe, "query"),
|
||||
"unsubscribe": rpc.NewWSRPCFunc(svc.Unsubscribe, "query"),
|
||||
"unsubscribe_all": rpc.NewWSRPCFunc(svc.UnsubscribeAll, ""),
|
||||
|
||||
// info API
|
||||
"health": rpc.NewRPCFunc(env.Health, ""),
|
||||
"status": rpc.NewRPCFunc(env.Status, ""),
|
||||
"net_info": rpc.NewRPCFunc(env.NetInfo, ""),
|
||||
"blockchain": rpc.NewRPCFunc(env.BlockchainInfo, "minHeight,maxHeight"),
|
||||
"genesis": rpc.NewRPCFunc(env.Genesis, ""),
|
||||
"genesis_chunked": rpc.NewRPCFunc(env.GenesisChunked, "chunk"),
|
||||
"header": rpc.NewRPCFunc(env.Header, "height"),
|
||||
"header_by_hash": rpc.NewRPCFunc(env.HeaderByHash, "hash"),
|
||||
"block": rpc.NewRPCFunc(env.Block, "height"),
|
||||
"block_by_hash": rpc.NewRPCFunc(env.BlockByHash, "hash"),
|
||||
"block_results": rpc.NewRPCFunc(env.BlockResults, "height"),
|
||||
"commit": rpc.NewRPCFunc(env.Commit, "height"),
|
||||
"check_tx": rpc.NewRPCFunc(env.CheckTx, "tx"),
|
||||
"remove_tx": rpc.NewRPCFunc(env.RemoveTx, "txkey"),
|
||||
"tx": rpc.NewRPCFunc(env.Tx, "hash,prove"),
|
||||
"tx_search": rpc.NewRPCFunc(env.TxSearch, "query,prove,page,per_page,order_by"),
|
||||
"block_search": rpc.NewRPCFunc(env.BlockSearch, "query,page,per_page,order_by"),
|
||||
"validators": rpc.NewRPCFunc(env.Validators, "height,page,per_page"),
|
||||
"dump_consensus_state": rpc.NewRPCFunc(env.DumpConsensusState, ""),
|
||||
"consensus_state": rpc.NewRPCFunc(env.GetConsensusState, ""),
|
||||
"consensus_params": rpc.NewRPCFunc(env.ConsensusParams, "height"),
|
||||
"unconfirmed_txs": rpc.NewRPCFunc(env.UnconfirmedTxs, "limit"),
|
||||
"num_unconfirmed_txs": rpc.NewRPCFunc(env.NumUnconfirmedTxs, ""),
|
||||
"health": rpc.NewRPCFunc(svc.Health, ""),
|
||||
"status": rpc.NewRPCFunc(svc.Status, ""),
|
||||
"net_info": rpc.NewRPCFunc(svc.NetInfo, ""),
|
||||
"blockchain": rpc.NewRPCFunc(svc.BlockchainInfo, "minHeight,maxHeight"),
|
||||
"genesis": rpc.NewRPCFunc(svc.Genesis, ""),
|
||||
"genesis_chunked": rpc.NewRPCFunc(svc.GenesisChunked, "chunk"),
|
||||
"header": rpc.NewRPCFunc(svc.Header, "height"),
|
||||
"header_by_hash": rpc.NewRPCFunc(svc.HeaderByHash, "hash"),
|
||||
"block": rpc.NewRPCFunc(svc.Block, "height"),
|
||||
"block_by_hash": rpc.NewRPCFunc(svc.BlockByHash, "hash"),
|
||||
"block_results": rpc.NewRPCFunc(svc.BlockResults, "height"),
|
||||
"commit": rpc.NewRPCFunc(svc.Commit, "height"),
|
||||
"check_tx": rpc.NewRPCFunc(svc.CheckTx, "tx"),
|
||||
"remove_tx": rpc.NewRPCFunc(svc.RemoveTx, "txkey"),
|
||||
"tx": rpc.NewRPCFunc(svc.Tx, "hash,prove"),
|
||||
"tx_search": rpc.NewRPCFunc(svc.TxSearch, "query,prove,page,per_page,order_by"),
|
||||
"block_search": rpc.NewRPCFunc(svc.BlockSearch, "query,page,per_page,order_by"),
|
||||
"validators": rpc.NewRPCFunc(svc.Validators, "height,page,per_page"),
|
||||
"dump_consensus_state": rpc.NewRPCFunc(svc.DumpConsensusState, ""),
|
||||
"consensus_state": rpc.NewRPCFunc(svc.GetConsensusState, ""),
|
||||
"consensus_params": rpc.NewRPCFunc(svc.ConsensusParams, "height"),
|
||||
"unconfirmed_txs": rpc.NewRPCFunc(svc.UnconfirmedTxs, "limit"),
|
||||
"num_unconfirmed_txs": rpc.NewRPCFunc(svc.NumUnconfirmedTxs, ""),
|
||||
|
||||
// tx broadcast API
|
||||
"broadcast_tx_commit": rpc.NewRPCFunc(env.BroadcastTxCommit, "tx"),
|
||||
"broadcast_tx_sync": rpc.NewRPCFunc(env.BroadcastTxSync, "tx"),
|
||||
"broadcast_tx_async": rpc.NewRPCFunc(env.BroadcastTxAsync, "tx"),
|
||||
"broadcast_tx_commit": rpc.NewRPCFunc(svc.BroadcastTxCommit, "tx"),
|
||||
"broadcast_tx_sync": rpc.NewRPCFunc(svc.BroadcastTxSync, "tx"),
|
||||
"broadcast_tx_async": rpc.NewRPCFunc(svc.BroadcastTxAsync, "tx"),
|
||||
|
||||
// abci API
|
||||
"abci_query": rpc.NewRPCFunc(env.ABCIQuery, "path,data,height,prove"),
|
||||
"abci_info": rpc.NewRPCFunc(env.ABCIInfo, ""),
|
||||
"abci_query": rpc.NewRPCFunc(svc.ABCIQuery, "path,data,height,prove"),
|
||||
"abci_info": rpc.NewRPCFunc(svc.ABCIInfo, ""),
|
||||
|
||||
// evidence API
|
||||
"broadcast_evidence": rpc.NewRPCFunc(env.BroadcastEvidence, "evidence"),
|
||||
"broadcast_evidence": rpc.NewRPCFunc(svc.BroadcastEvidence, "evidence"),
|
||||
}
|
||||
if u, ok := svc.(RPCUnsafe); ok && opts.Unsafe {
|
||||
out["unsafe_flush_mempool"] = rpc.NewRPCFunc(u.UnsafeFlushMempool, "")
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// AddUnsafeRoutes adds unsafe routes.
|
||||
func (env *Environment) AddUnsafe(routes RoutesMap) {
|
||||
// control API
|
||||
routes["unsafe_flush_mempool"] = rpc.NewRPCFunc(env.UnsafeFlushMempool, "")
|
||||
// RPCService defines the set of methods exported by the RPC service
|
||||
// implementation, for use in constructing a routing table.
|
||||
type RPCService interface {
|
||||
ABCIInfo(ctx context.Context) (*coretypes.ResultABCIInfo, error)
|
||||
ABCIQuery(ctx context.Context, path string, data bytes.HexBytes, height int64, prove bool) (*coretypes.ResultABCIQuery, error)
|
||||
Block(ctx context.Context, heightPtr *int64) (*coretypes.ResultBlock, error)
|
||||
BlockByHash(ctx context.Context, hash bytes.HexBytes) (*coretypes.ResultBlock, error)
|
||||
BlockResults(ctx context.Context, heightPtr *int64) (*coretypes.ResultBlockResults, error)
|
||||
BlockSearch(ctx context.Context, query string, pagePtr, perPagePtr *int, orderBy string) (*coretypes.ResultBlockSearch, error)
|
||||
BlockchainInfo(ctx context.Context, minHeight, maxHeight int64) (*coretypes.ResultBlockchainInfo, error)
|
||||
BroadcastEvidence(ctx context.Context, ev types.Evidence) (*coretypes.ResultBroadcastEvidence, error)
|
||||
BroadcastTxAsync(ctx context.Context, tx types.Tx) (*coretypes.ResultBroadcastTx, error)
|
||||
BroadcastTxCommit(ctx context.Context, tx types.Tx) (*coretypes.ResultBroadcastTxCommit, error)
|
||||
BroadcastTxSync(ctx context.Context, tx types.Tx) (*coretypes.ResultBroadcastTx, error)
|
||||
CheckTx(ctx context.Context, tx types.Tx) (*coretypes.ResultCheckTx, error)
|
||||
Commit(ctx context.Context, heightPtr *int64) (*coretypes.ResultCommit, error)
|
||||
ConsensusParams(ctx context.Context, heightPtr *int64) (*coretypes.ResultConsensusParams, error)
|
||||
DumpConsensusState(ctx context.Context) (*coretypes.ResultDumpConsensusState, error)
|
||||
Genesis(ctx context.Context) (*coretypes.ResultGenesis, error)
|
||||
GenesisChunked(ctx context.Context, chunk uint) (*coretypes.ResultGenesisChunk, error)
|
||||
GetConsensusState(ctx context.Context) (*coretypes.ResultConsensusState, error)
|
||||
Header(ctx context.Context, heightPtr *int64) (*coretypes.ResultHeader, error)
|
||||
HeaderByHash(ctx context.Context, hash bytes.HexBytes) (*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, txkey types.TxKey) error
|
||||
Status(ctx context.Context) (*coretypes.ResultStatus, error)
|
||||
Subscribe(ctx context.Context, query string) (*coretypes.ResultSubscribe, error)
|
||||
Tx(ctx context.Context, hash bytes.HexBytes, prove bool) (*coretypes.ResultTx, error)
|
||||
TxSearch(ctx context.Context, query string, prove bool, pagePtr, perPagePtr *int, orderBy string) (*coretypes.ResultTxSearch, error)
|
||||
UnconfirmedTxs(ctx context.Context, limitPtr *int) (*coretypes.ResultUnconfirmedTxs, error)
|
||||
Unsubscribe(ctx context.Context, query string) (*coretypes.ResultUnsubscribe, error)
|
||||
UnsubscribeAll(ctx context.Context) (*coretypes.ResultUnsubscribe, error)
|
||||
Validators(ctx context.Context, heightPtr *int64, pagePtr, perPagePtr *int) (*coretypes.ResultValidators, error)
|
||||
}
|
||||
|
||||
// RPCUnsafe defines the set of "unsafe" methods that may optionally be
|
||||
// exported by the RPC service.
|
||||
type RPCUnsafe interface {
|
||||
UnsafeFlushMempool(ctx context.Context) (*coretypes.ResultUnsafeFlushMempool, error)
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"net/http"
|
||||
|
||||
tmpubsub "github.com/tendermint/tendermint/internal/pubsub"
|
||||
rpccore "github.com/tendermint/tendermint/internal/rpc/core"
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
"github.com/tendermint/tendermint/light"
|
||||
lrpc "github.com/tendermint/tendermint/light/rpc"
|
||||
@@ -90,7 +91,7 @@ func (p *Proxy) listen(ctx context.Context) (net.Listener, *http.ServeMux, error
|
||||
mux := http.NewServeMux()
|
||||
|
||||
// 1) Register regular routes.
|
||||
r := RPCRoutes(p.Client)
|
||||
r := rpccore.NewRoutesMap(proxyService{Client: p.Client}, nil)
|
||||
rpcserver.RegisterRPCFuncs(mux, r, p.Logger)
|
||||
|
||||
// 2) Allow websocket connections.
|
||||
|
||||
@@ -3,303 +3,40 @@ package proxy
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/tendermint/tendermint/libs/bytes"
|
||||
tmbytes "github.com/tendermint/tendermint/libs/bytes"
|
||||
lrpc "github.com/tendermint/tendermint/light/rpc"
|
||||
rpcclient "github.com/tendermint/tendermint/rpc/client"
|
||||
"github.com/tendermint/tendermint/rpc/coretypes"
|
||||
rpcserver "github.com/tendermint/tendermint/rpc/jsonrpc/server"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
)
|
||||
|
||||
func RPCRoutes(c *lrpc.Client) map[string]*rpcserver.RPCFunc {
|
||||
return map[string]*rpcserver.RPCFunc{
|
||||
// Subscribe/unsubscribe are reserved for websocket events.
|
||||
"subscribe": rpcserver.NewWSRPCFunc(c.SubscribeWS, "query"),
|
||||
"unsubscribe": rpcserver.NewWSRPCFunc(c.UnsubscribeWS, "query"),
|
||||
"unsubscribe_all": rpcserver.NewWSRPCFunc(c.UnsubscribeAllWS, ""),
|
||||
|
||||
// info API
|
||||
"health": rpcserver.NewRPCFunc(makeHealthFunc(c), ""),
|
||||
"status": rpcserver.NewRPCFunc(makeStatusFunc(c), ""),
|
||||
"net_info": rpcserver.NewRPCFunc(makeNetInfoFunc(c), ""),
|
||||
"blockchain": rpcserver.NewRPCFunc(makeBlockchainInfoFunc(c), "minHeight,maxHeight"),
|
||||
"genesis": rpcserver.NewRPCFunc(makeGenesisFunc(c), ""),
|
||||
"genesis_chunked": rpcserver.NewRPCFunc(makeGenesisChunkedFunc(c), ""),
|
||||
"header": rpcserver.NewRPCFunc(makeHeaderFunc(c), "height"),
|
||||
"header_by_hash": rpcserver.NewRPCFunc(makeHeaderByHashFunc(c), "hash"),
|
||||
"block": rpcserver.NewRPCFunc(makeBlockFunc(c), "height"),
|
||||
"block_by_hash": rpcserver.NewRPCFunc(makeBlockByHashFunc(c), "hash"),
|
||||
"block_results": rpcserver.NewRPCFunc(makeBlockResultsFunc(c), "height"),
|
||||
"commit": rpcserver.NewRPCFunc(makeCommitFunc(c), "height"),
|
||||
"tx": rpcserver.NewRPCFunc(makeTxFunc(c), "hash,prove"),
|
||||
"tx_search": rpcserver.NewRPCFunc(makeTxSearchFunc(c), "query,prove,page,per_page,order_by"),
|
||||
"block_search": rpcserver.NewRPCFunc(makeBlockSearchFunc(c), "query,page,per_page,order_by"),
|
||||
"validators": rpcserver.NewRPCFunc(makeValidatorsFunc(c), "height,page,per_page"),
|
||||
"dump_consensus_state": rpcserver.NewRPCFunc(makeDumpConsensusStateFunc(c), ""),
|
||||
"consensus_state": rpcserver.NewRPCFunc(makeConsensusStateFunc(c), ""),
|
||||
"consensus_params": rpcserver.NewRPCFunc(makeConsensusParamsFunc(c), "height"),
|
||||
"unconfirmed_txs": rpcserver.NewRPCFunc(makeUnconfirmedTxsFunc(c), "limit"),
|
||||
"num_unconfirmed_txs": rpcserver.NewRPCFunc(makeNumUnconfirmedTxsFunc(c), ""),
|
||||
|
||||
// tx broadcast API
|
||||
"broadcast_tx_commit": rpcserver.NewRPCFunc(makeBroadcastTxCommitFunc(c), "tx"),
|
||||
"broadcast_tx_sync": rpcserver.NewRPCFunc(makeBroadcastTxSyncFunc(c), "tx"),
|
||||
"broadcast_tx_async": rpcserver.NewRPCFunc(makeBroadcastTxAsyncFunc(c), "tx"),
|
||||
|
||||
// abci API
|
||||
"abci_query": rpcserver.NewRPCFunc(makeABCIQueryFunc(c), "path,data,height,prove"),
|
||||
"abci_info": rpcserver.NewRPCFunc(makeABCIInfoFunc(c), ""),
|
||||
|
||||
// evidence API
|
||||
"broadcast_evidence": rpcserver.NewRPCFunc(makeBroadcastEvidenceFunc(c), "evidence"),
|
||||
}
|
||||
// proxyService wraps a light RPC client to export the RPC service interfaces.
|
||||
// This is needed because the service and the client use different signatures
|
||||
// for some of the methods.
|
||||
type proxyService struct {
|
||||
*lrpc.Client
|
||||
}
|
||||
|
||||
type rpcHealthFunc func(ctx context.Context) (*coretypes.ResultHealth, error)
|
||||
func (p proxyService) ABCIQuery(ctx context.Context, path string, data tmbytes.HexBytes,
|
||||
height int64, prove bool) (*coretypes.ResultABCIQuery, error) {
|
||||
|
||||
func makeHealthFunc(c *lrpc.Client) rpcHealthFunc {
|
||||
return func(ctx context.Context) (*coretypes.ResultHealth, error) {
|
||||
return c.Health(ctx)
|
||||
}
|
||||
return p.ABCIQueryWithOptions(ctx, path, data, rpcclient.ABCIQueryOptions{
|
||||
Height: height,
|
||||
Prove: prove,
|
||||
})
|
||||
}
|
||||
|
||||
type rpcStatusFunc func(ctx context.Context) (*coretypes.ResultStatus, error)
|
||||
|
||||
// nolint: interfacer
|
||||
func makeStatusFunc(c *lrpc.Client) rpcStatusFunc {
|
||||
return func(ctx context.Context) (*coretypes.ResultStatus, error) {
|
||||
return c.Status(ctx)
|
||||
}
|
||||
func (p proxyService) GetConsensusState(ctx context.Context) (*coretypes.ResultConsensusState, error) {
|
||||
return p.ConsensusState(ctx)
|
||||
}
|
||||
|
||||
type rpcNetInfoFunc func(ctx context.Context) (*coretypes.ResultNetInfo, error)
|
||||
|
||||
func makeNetInfoFunc(c *lrpc.Client) rpcNetInfoFunc {
|
||||
return func(ctx context.Context) (*coretypes.ResultNetInfo, error) {
|
||||
return c.NetInfo(ctx)
|
||||
}
|
||||
func (p proxyService) Subscribe(ctx context.Context, query string) (*coretypes.ResultSubscribe, error) {
|
||||
return p.SubscribeWS(ctx, query)
|
||||
}
|
||||
|
||||
type rpcBlockchainInfoFunc func(ctx context.Context, minHeight, maxHeight int64) (*coretypes.ResultBlockchainInfo, error)
|
||||
|
||||
func makeBlockchainInfoFunc(c *lrpc.Client) rpcBlockchainInfoFunc {
|
||||
return func(ctx context.Context, minHeight, maxHeight int64) (*coretypes.ResultBlockchainInfo, error) {
|
||||
return c.BlockchainInfo(ctx, minHeight, maxHeight)
|
||||
}
|
||||
func (p proxyService) Unsubscribe(ctx context.Context, query string) (*coretypes.ResultUnsubscribe, error) {
|
||||
return p.UnsubscribeWS(ctx, query)
|
||||
}
|
||||
|
||||
type rpcGenesisFunc func(ctx context.Context) (*coretypes.ResultGenesis, error)
|
||||
|
||||
func makeGenesisFunc(c *lrpc.Client) rpcGenesisFunc {
|
||||
return func(ctx context.Context) (*coretypes.ResultGenesis, error) {
|
||||
return c.Genesis(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
type rpcGenesisChunkedFunc func(ctx context.Context, chunk uint) (*coretypes.ResultGenesisChunk, error)
|
||||
|
||||
func makeGenesisChunkedFunc(c *lrpc.Client) rpcGenesisChunkedFunc {
|
||||
return func(ctx context.Context, chunk uint) (*coretypes.ResultGenesisChunk, error) {
|
||||
return c.GenesisChunked(ctx, chunk)
|
||||
}
|
||||
}
|
||||
|
||||
type rpcHeaderFunc func(ctx context.Context, height *int64) (*coretypes.ResultHeader, error)
|
||||
|
||||
func makeHeaderFunc(c *lrpc.Client) rpcHeaderFunc {
|
||||
return func(ctx context.Context, height *int64) (*coretypes.ResultHeader, error) {
|
||||
return c.Header(ctx, height)
|
||||
}
|
||||
}
|
||||
|
||||
type rpcHeaderByHashFunc func(ctx context.Context, hash []byte) (*coretypes.ResultHeader, error)
|
||||
|
||||
func makeHeaderByHashFunc(c *lrpc.Client) rpcHeaderByHashFunc {
|
||||
return func(ctx context.Context, hash []byte) (*coretypes.ResultHeader, error) {
|
||||
return c.HeaderByHash(ctx, hash)
|
||||
}
|
||||
}
|
||||
|
||||
type rpcBlockFunc func(ctx context.Context, height *int64) (*coretypes.ResultBlock, error)
|
||||
|
||||
func makeBlockFunc(c *lrpc.Client) rpcBlockFunc {
|
||||
return func(ctx context.Context, height *int64) (*coretypes.ResultBlock, error) {
|
||||
return c.Block(ctx, height)
|
||||
}
|
||||
}
|
||||
|
||||
type rpcBlockByHashFunc func(ctx context.Context, hash []byte) (*coretypes.ResultBlock, error)
|
||||
|
||||
func makeBlockByHashFunc(c *lrpc.Client) rpcBlockByHashFunc {
|
||||
return func(ctx context.Context, hash []byte) (*coretypes.ResultBlock, error) {
|
||||
return c.BlockByHash(ctx, hash)
|
||||
}
|
||||
}
|
||||
|
||||
type rpcBlockResultsFunc func(ctx context.Context, height *int64) (*coretypes.ResultBlockResults, error)
|
||||
|
||||
func makeBlockResultsFunc(c *lrpc.Client) rpcBlockResultsFunc {
|
||||
return func(ctx context.Context, height *int64) (*coretypes.ResultBlockResults, error) {
|
||||
return c.BlockResults(ctx, height)
|
||||
}
|
||||
}
|
||||
|
||||
type rpcCommitFunc func(ctx context.Context, height *int64) (*coretypes.ResultCommit, error)
|
||||
|
||||
func makeCommitFunc(c *lrpc.Client) rpcCommitFunc {
|
||||
return func(ctx context.Context, height *int64) (*coretypes.ResultCommit, error) {
|
||||
return c.Commit(ctx, height)
|
||||
}
|
||||
}
|
||||
|
||||
type rpcTxFunc func(ctx context.Context, hash []byte, prove bool) (*coretypes.ResultTx, error)
|
||||
|
||||
func makeTxFunc(c *lrpc.Client) rpcTxFunc {
|
||||
return func(ctx context.Context, hash []byte, prove bool) (*coretypes.ResultTx, error) {
|
||||
return c.Tx(ctx, hash, prove)
|
||||
}
|
||||
}
|
||||
|
||||
type rpcTxSearchFunc func(
|
||||
ctx context.Context,
|
||||
query string,
|
||||
prove bool,
|
||||
page, perPage *int,
|
||||
orderBy string,
|
||||
) (*coretypes.ResultTxSearch, error)
|
||||
|
||||
func makeTxSearchFunc(c *lrpc.Client) rpcTxSearchFunc {
|
||||
return func(
|
||||
ctx context.Context,
|
||||
query string,
|
||||
prove bool,
|
||||
page, perPage *int,
|
||||
orderBy string,
|
||||
) (*coretypes.ResultTxSearch, error) {
|
||||
return c.TxSearch(ctx, query, prove, page, perPage, orderBy)
|
||||
}
|
||||
}
|
||||
|
||||
type rpcBlockSearchFunc func(
|
||||
ctx context.Context,
|
||||
query string,
|
||||
prove bool,
|
||||
page, perPage *int,
|
||||
orderBy string,
|
||||
) (*coretypes.ResultBlockSearch, error)
|
||||
|
||||
func makeBlockSearchFunc(c *lrpc.Client) rpcBlockSearchFunc {
|
||||
return func(
|
||||
ctx context.Context,
|
||||
query string,
|
||||
prove bool,
|
||||
page, perPage *int,
|
||||
orderBy string,
|
||||
) (*coretypes.ResultBlockSearch, error) {
|
||||
return c.BlockSearch(ctx, query, page, perPage, orderBy)
|
||||
}
|
||||
}
|
||||
|
||||
type rpcValidatorsFunc func(ctx context.Context, height *int64,
|
||||
page, perPage *int) (*coretypes.ResultValidators, error)
|
||||
|
||||
func makeValidatorsFunc(c *lrpc.Client) rpcValidatorsFunc {
|
||||
return func(ctx context.Context, height *int64, page, perPage *int) (*coretypes.ResultValidators, error) {
|
||||
return c.Validators(ctx, height, page, perPage)
|
||||
}
|
||||
}
|
||||
|
||||
type rpcDumpConsensusStateFunc func(ctx context.Context) (*coretypes.ResultDumpConsensusState, error)
|
||||
|
||||
func makeDumpConsensusStateFunc(c *lrpc.Client) rpcDumpConsensusStateFunc {
|
||||
return func(ctx context.Context) (*coretypes.ResultDumpConsensusState, error) {
|
||||
return c.DumpConsensusState(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
type rpcConsensusStateFunc func(ctx context.Context) (*coretypes.ResultConsensusState, error)
|
||||
|
||||
func makeConsensusStateFunc(c *lrpc.Client) rpcConsensusStateFunc {
|
||||
return func(ctx context.Context) (*coretypes.ResultConsensusState, error) {
|
||||
return c.ConsensusState(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
type rpcConsensusParamsFunc func(ctx context.Context, height *int64) (*coretypes.ResultConsensusParams, error)
|
||||
|
||||
func makeConsensusParamsFunc(c *lrpc.Client) rpcConsensusParamsFunc {
|
||||
return func(ctx context.Context, height *int64) (*coretypes.ResultConsensusParams, error) {
|
||||
return c.ConsensusParams(ctx, height)
|
||||
}
|
||||
}
|
||||
|
||||
type rpcUnconfirmedTxsFunc func(ctx context.Context, limit *int) (*coretypes.ResultUnconfirmedTxs, error)
|
||||
|
||||
func makeUnconfirmedTxsFunc(c *lrpc.Client) rpcUnconfirmedTxsFunc {
|
||||
return func(ctx context.Context, limit *int) (*coretypes.ResultUnconfirmedTxs, error) {
|
||||
return c.UnconfirmedTxs(ctx, limit)
|
||||
}
|
||||
}
|
||||
|
||||
type rpcNumUnconfirmedTxsFunc func(ctx context.Context) (*coretypes.ResultUnconfirmedTxs, error)
|
||||
|
||||
func makeNumUnconfirmedTxsFunc(c *lrpc.Client) rpcNumUnconfirmedTxsFunc {
|
||||
return func(ctx context.Context) (*coretypes.ResultUnconfirmedTxs, error) {
|
||||
return c.NumUnconfirmedTxs(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
type rpcBroadcastTxCommitFunc func(ctx context.Context, tx types.Tx) (*coretypes.ResultBroadcastTxCommit, error)
|
||||
|
||||
func makeBroadcastTxCommitFunc(c *lrpc.Client) rpcBroadcastTxCommitFunc {
|
||||
return func(ctx context.Context, tx types.Tx) (*coretypes.ResultBroadcastTxCommit, error) {
|
||||
return c.BroadcastTxCommit(ctx, tx)
|
||||
}
|
||||
}
|
||||
|
||||
type rpcBroadcastTxSyncFunc func(ctx context.Context, tx types.Tx) (*coretypes.ResultBroadcastTx, error)
|
||||
|
||||
func makeBroadcastTxSyncFunc(c *lrpc.Client) rpcBroadcastTxSyncFunc {
|
||||
return func(ctx context.Context, tx types.Tx) (*coretypes.ResultBroadcastTx, error) {
|
||||
return c.BroadcastTxSync(ctx, tx)
|
||||
}
|
||||
}
|
||||
|
||||
type rpcBroadcastTxAsyncFunc func(ctx context.Context, tx types.Tx) (*coretypes.ResultBroadcastTx, error)
|
||||
|
||||
func makeBroadcastTxAsyncFunc(c *lrpc.Client) rpcBroadcastTxAsyncFunc {
|
||||
return func(ctx context.Context, tx types.Tx) (*coretypes.ResultBroadcastTx, error) {
|
||||
return c.BroadcastTxAsync(ctx, tx)
|
||||
}
|
||||
}
|
||||
|
||||
type rpcABCIQueryFunc func(ctx context.Context, path string,
|
||||
data bytes.HexBytes, height int64, prove bool) (*coretypes.ResultABCIQuery, error)
|
||||
|
||||
func makeABCIQueryFunc(c *lrpc.Client) rpcABCIQueryFunc {
|
||||
return func(ctx context.Context, path string, data bytes.HexBytes,
|
||||
height int64, prove bool) (*coretypes.ResultABCIQuery, error) {
|
||||
|
||||
return c.ABCIQueryWithOptions(ctx, path, data, rpcclient.ABCIQueryOptions{
|
||||
Height: height,
|
||||
Prove: prove,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
type rpcABCIInfoFunc func(ctx context.Context) (*coretypes.ResultABCIInfo, error)
|
||||
|
||||
func makeABCIInfoFunc(c *lrpc.Client) rpcABCIInfoFunc {
|
||||
return func(ctx context.Context) (*coretypes.ResultABCIInfo, error) {
|
||||
return c.ABCIInfo(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
type rpcBroadcastEvidenceFunc func(ctx context.Context, ev types.Evidence) (*coretypes.ResultBroadcastEvidence, error)
|
||||
|
||||
// nolint: interfacer
|
||||
func makeBroadcastEvidenceFunc(c *lrpc.Client) rpcBroadcastEvidenceFunc {
|
||||
return func(ctx context.Context, ev types.Evidence) (*coretypes.ResultBroadcastEvidence, error) {
|
||||
return c.BroadcastEvidence(ctx, ev)
|
||||
}
|
||||
func (p proxyService) UnsubscribeAll(ctx context.Context) (*coretypes.ResultUnsubscribe, error) {
|
||||
return p.UnsubscribeAllWS(ctx)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user