github.com/516108736/tendermint@v0.36.0/light/proxy/routes.go (about) 1 package proxy 2 3 import ( 4 "github.com/tendermint/tendermint/libs/bytes" 5 lrpc "github.com/tendermint/tendermint/light/rpc" 6 rpcclient "github.com/tendermint/tendermint/rpc/client" 7 ctypes "github.com/tendermint/tendermint/rpc/core/types" 8 rpcserver "github.com/tendermint/tendermint/rpc/jsonrpc/server" 9 rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types" 10 "github.com/tendermint/tendermint/types" 11 ) 12 13 func RPCRoutes(c *lrpc.Client) map[string]*rpcserver.RPCFunc { 14 return map[string]*rpcserver.RPCFunc{ 15 // Subscribe/unsubscribe are reserved for websocket events. 16 "subscribe": rpcserver.NewWSRPCFunc(c.SubscribeWS, "query"), 17 "unsubscribe": rpcserver.NewWSRPCFunc(c.UnsubscribeWS, "query"), 18 "unsubscribe_all": rpcserver.NewWSRPCFunc(c.UnsubscribeAllWS, ""), 19 20 // info API 21 "health": rpcserver.NewRPCFunc(makeHealthFunc(c), ""), 22 "status": rpcserver.NewRPCFunc(makeStatusFunc(c), ""), 23 "net_info": rpcserver.NewRPCFunc(makeNetInfoFunc(c), ""), 24 "blockchain": rpcserver.NewRPCFunc(makeBlockchainInfoFunc(c), "minHeight,maxHeight"), 25 "genesis": rpcserver.NewRPCFunc(makeGenesisFunc(c), ""), 26 "block": rpcserver.NewRPCFunc(makeBlockFunc(c), "height"), 27 "block_by_hash": rpcserver.NewRPCFunc(makeBlockByHashFunc(c), "hash"), 28 "block_results": rpcserver.NewRPCFunc(makeBlockResultsFunc(c), "height"), 29 "commit": rpcserver.NewRPCFunc(makeCommitFunc(c), "height"), 30 "tx": rpcserver.NewRPCFunc(makeTxFunc(c), "hash,prove"), 31 "tx_search": rpcserver.NewRPCFunc(makeTxSearchFunc(c), "query,prove,page,per_page,order_by"), 32 "validators": rpcserver.NewRPCFunc(makeValidatorsFunc(c), "height,page,per_page"), 33 "dump_consensus_state": rpcserver.NewRPCFunc(makeDumpConsensusStateFunc(c), ""), 34 "consensus_state": rpcserver.NewRPCFunc(makeConsensusStateFunc(c), ""), 35 "consensus_params": rpcserver.NewRPCFunc(makeConsensusParamsFunc(c), "height"), 36 "unconfirmed_txs": rpcserver.NewRPCFunc(makeUnconfirmedTxsFunc(c), "limit"), 37 "num_unconfirmed_txs": rpcserver.NewRPCFunc(makeNumUnconfirmedTxsFunc(c), ""), 38 39 // tx broadcast API 40 "broadcast_tx_commit": rpcserver.NewRPCFunc(makeBroadcastTxCommitFunc(c), "tx"), 41 "broadcast_tx_sync": rpcserver.NewRPCFunc(makeBroadcastTxSyncFunc(c), "tx"), 42 "broadcast_tx_async": rpcserver.NewRPCFunc(makeBroadcastTxAsyncFunc(c), "tx"), 43 44 // abci API 45 "abci_query": rpcserver.NewRPCFunc(makeABCIQueryFunc(c), "path,data,height,prove"), 46 "abci_info": rpcserver.NewRPCFunc(makeABCIInfoFunc(c), ""), 47 48 // evidence API 49 "broadcast_evidence": rpcserver.NewRPCFunc(makeBroadcastEvidenceFunc(c), "evidence"), 50 } 51 } 52 53 type rpcHealthFunc func(ctx *rpctypes.Context) (*ctypes.ResultHealth, error) 54 55 func makeHealthFunc(c *lrpc.Client) rpcHealthFunc { 56 return func(ctx *rpctypes.Context) (*ctypes.ResultHealth, error) { 57 return c.Health(ctx.Context()) 58 } 59 } 60 61 type rpcStatusFunc func(ctx *rpctypes.Context) (*ctypes.ResultStatus, error) 62 63 // nolint: interfacer 64 func makeStatusFunc(c *lrpc.Client) rpcStatusFunc { 65 return func(ctx *rpctypes.Context) (*ctypes.ResultStatus, error) { 66 return c.Status(ctx.Context()) 67 } 68 } 69 70 type rpcNetInfoFunc func(ctx *rpctypes.Context, minHeight, maxHeight int64) (*ctypes.ResultNetInfo, error) 71 72 func makeNetInfoFunc(c *lrpc.Client) rpcNetInfoFunc { 73 return func(ctx *rpctypes.Context, minHeight, maxHeight int64) (*ctypes.ResultNetInfo, error) { 74 return c.NetInfo(ctx.Context()) 75 } 76 } 77 78 type rpcBlockchainInfoFunc func(ctx *rpctypes.Context, minHeight, maxHeight int64) (*ctypes.ResultBlockchainInfo, error) 79 80 func makeBlockchainInfoFunc(c *lrpc.Client) rpcBlockchainInfoFunc { 81 return func(ctx *rpctypes.Context, minHeight, maxHeight int64) (*ctypes.ResultBlockchainInfo, error) { 82 return c.BlockchainInfo(ctx.Context(), minHeight, maxHeight) 83 } 84 } 85 86 type rpcGenesisFunc func(ctx *rpctypes.Context) (*ctypes.ResultGenesis, error) 87 88 func makeGenesisFunc(c *lrpc.Client) rpcGenesisFunc { 89 return func(ctx *rpctypes.Context) (*ctypes.ResultGenesis, error) { 90 return c.Genesis(ctx.Context()) 91 } 92 } 93 94 type rpcBlockFunc func(ctx *rpctypes.Context, height *int64) (*ctypes.ResultBlock, error) 95 96 func makeBlockFunc(c *lrpc.Client) rpcBlockFunc { 97 return func(ctx *rpctypes.Context, height *int64) (*ctypes.ResultBlock, error) { 98 return c.Block(ctx.Context(), height) 99 } 100 } 101 102 type rpcBlockByHashFunc func(ctx *rpctypes.Context, hash []byte) (*ctypes.ResultBlock, error) 103 104 func makeBlockByHashFunc(c *lrpc.Client) rpcBlockByHashFunc { 105 return func(ctx *rpctypes.Context, hash []byte) (*ctypes.ResultBlock, error) { 106 return c.BlockByHash(ctx.Context(), hash) 107 } 108 } 109 110 type rpcBlockResultsFunc func(ctx *rpctypes.Context, height *int64) (*ctypes.ResultBlockResults, error) 111 112 func makeBlockResultsFunc(c *lrpc.Client) rpcBlockResultsFunc { 113 return func(ctx *rpctypes.Context, height *int64) (*ctypes.ResultBlockResults, error) { 114 return c.BlockResults(ctx.Context(), height) 115 } 116 } 117 118 type rpcCommitFunc func(ctx *rpctypes.Context, height *int64) (*ctypes.ResultCommit, error) 119 120 func makeCommitFunc(c *lrpc.Client) rpcCommitFunc { 121 return func(ctx *rpctypes.Context, height *int64) (*ctypes.ResultCommit, error) { 122 return c.Commit(ctx.Context(), height) 123 } 124 } 125 126 type rpcTxFunc func(ctx *rpctypes.Context, hash []byte, prove bool) (*ctypes.ResultTx, error) 127 128 func makeTxFunc(c *lrpc.Client) rpcTxFunc { 129 return func(ctx *rpctypes.Context, hash []byte, prove bool) (*ctypes.ResultTx, error) { 130 return c.Tx(ctx.Context(), hash, prove) 131 } 132 } 133 134 type rpcTxSearchFunc func(ctx *rpctypes.Context, query string, prove bool, 135 page, perPage *int, orderBy string) (*ctypes.ResultTxSearch, error) 136 137 func makeTxSearchFunc(c *lrpc.Client) rpcTxSearchFunc { 138 return func(ctx *rpctypes.Context, query string, prove bool, page, perPage *int, orderBy string) ( 139 *ctypes.ResultTxSearch, error) { 140 return c.TxSearch(ctx.Context(), query, prove, page, perPage, orderBy) 141 } 142 } 143 144 type rpcValidatorsFunc func(ctx *rpctypes.Context, height *int64, 145 page, perPage *int) (*ctypes.ResultValidators, error) 146 147 func makeValidatorsFunc(c *lrpc.Client) rpcValidatorsFunc { 148 return func(ctx *rpctypes.Context, height *int64, page, perPage *int) (*ctypes.ResultValidators, error) { 149 return c.Validators(ctx.Context(), height, page, perPage) 150 } 151 } 152 153 type rpcDumpConsensusStateFunc func(ctx *rpctypes.Context) (*ctypes.ResultDumpConsensusState, error) 154 155 func makeDumpConsensusStateFunc(c *lrpc.Client) rpcDumpConsensusStateFunc { 156 return func(ctx *rpctypes.Context) (*ctypes.ResultDumpConsensusState, error) { 157 return c.DumpConsensusState(ctx.Context()) 158 } 159 } 160 161 type rpcConsensusStateFunc func(ctx *rpctypes.Context) (*ctypes.ResultConsensusState, error) 162 163 func makeConsensusStateFunc(c *lrpc.Client) rpcConsensusStateFunc { 164 return func(ctx *rpctypes.Context) (*ctypes.ResultConsensusState, error) { 165 return c.ConsensusState(ctx.Context()) 166 } 167 } 168 169 type rpcConsensusParamsFunc func(ctx *rpctypes.Context, height *int64) (*ctypes.ResultConsensusParams, error) 170 171 func makeConsensusParamsFunc(c *lrpc.Client) rpcConsensusParamsFunc { 172 return func(ctx *rpctypes.Context, height *int64) (*ctypes.ResultConsensusParams, error) { 173 return c.ConsensusParams(ctx.Context(), height) 174 } 175 } 176 177 type rpcUnconfirmedTxsFunc func(ctx *rpctypes.Context, limit *int) (*ctypes.ResultUnconfirmedTxs, error) 178 179 func makeUnconfirmedTxsFunc(c *lrpc.Client) rpcUnconfirmedTxsFunc { 180 return func(ctx *rpctypes.Context, limit *int) (*ctypes.ResultUnconfirmedTxs, error) { 181 return c.UnconfirmedTxs(ctx.Context(), limit) 182 } 183 } 184 185 type rpcNumUnconfirmedTxsFunc func(ctx *rpctypes.Context) (*ctypes.ResultUnconfirmedTxs, error) 186 187 func makeNumUnconfirmedTxsFunc(c *lrpc.Client) rpcNumUnconfirmedTxsFunc { 188 return func(ctx *rpctypes.Context) (*ctypes.ResultUnconfirmedTxs, error) { 189 return c.NumUnconfirmedTxs(ctx.Context()) 190 } 191 } 192 193 type rpcBroadcastTxCommitFunc func(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) 194 195 func makeBroadcastTxCommitFunc(c *lrpc.Client) rpcBroadcastTxCommitFunc { 196 return func(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) { 197 return c.BroadcastTxCommit(ctx.Context(), tx) 198 } 199 } 200 201 type rpcBroadcastTxSyncFunc func(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcastTx, error) 202 203 func makeBroadcastTxSyncFunc(c *lrpc.Client) rpcBroadcastTxSyncFunc { 204 return func(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcastTx, error) { 205 return c.BroadcastTxSync(ctx.Context(), tx) 206 } 207 } 208 209 type rpcBroadcastTxAsyncFunc func(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcastTx, error) 210 211 func makeBroadcastTxAsyncFunc(c *lrpc.Client) rpcBroadcastTxAsyncFunc { 212 return func(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcastTx, error) { 213 return c.BroadcastTxAsync(ctx.Context(), tx) 214 } 215 } 216 217 type rpcABCIQueryFunc func(ctx *rpctypes.Context, path string, 218 data bytes.HexBytes, height int64, prove bool) (*ctypes.ResultABCIQuery, error) 219 220 func makeABCIQueryFunc(c *lrpc.Client) rpcABCIQueryFunc { 221 return func(ctx *rpctypes.Context, path string, data bytes.HexBytes, 222 height int64, prove bool) (*ctypes.ResultABCIQuery, error) { 223 224 return c.ABCIQueryWithOptions(ctx.Context(), path, data, rpcclient.ABCIQueryOptions{ 225 Height: height, 226 Prove: prove, 227 }) 228 } 229 } 230 231 type rpcABCIInfoFunc func(ctx *rpctypes.Context) (*ctypes.ResultABCIInfo, error) 232 233 func makeABCIInfoFunc(c *lrpc.Client) rpcABCIInfoFunc { 234 return func(ctx *rpctypes.Context) (*ctypes.ResultABCIInfo, error) { 235 return c.ABCIInfo(ctx.Context()) 236 } 237 } 238 239 type rpcBroadcastEvidenceFunc func(ctx *rpctypes.Context, ev types.Evidence) (*ctypes.ResultBroadcastEvidence, error) 240 241 // nolint: interfacer 242 func makeBroadcastEvidenceFunc(c *lrpc.Client) rpcBroadcastEvidenceFunc { 243 return func(ctx *rpctypes.Context, ev types.Evidence) (*ctypes.ResultBroadcastEvidence, error) { 244 return c.BroadcastEvidence(ctx.Context(), ev) 245 } 246 }