github.com/opzlabs/tendermint@v0.34.27-terra.rc.2/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", rpcserver.Cacheable()), 25 "genesis": rpcserver.NewRPCFunc(makeGenesisFunc(c), "", rpcserver.Cacheable()), 26 "genesis_chunked": rpcserver.NewRPCFunc(makeGenesisChunkedFunc(c), "", rpcserver.Cacheable()), 27 "block": rpcserver.NewRPCFunc(makeBlockFunc(c), "height", rpcserver.Cacheable("height")), 28 "block_by_hash": rpcserver.NewRPCFunc(makeBlockByHashFunc(c), "hash", rpcserver.Cacheable()), 29 "block_results": rpcserver.NewRPCFunc(makeBlockResultsFunc(c), "height", rpcserver.Cacheable("height")), 30 "commit": rpcserver.NewRPCFunc(makeCommitFunc(c), "height", rpcserver.Cacheable("height")), 31 "tx": rpcserver.NewRPCFunc(makeTxFunc(c), "hash,prove", rpcserver.Cacheable()), 32 "tx_search": rpcserver.NewRPCFunc(makeTxSearchFuncMatchEvents(c), "query,prove,page,per_page,order_by,match_events"), 33 "block_search": rpcserver.NewRPCFunc(makeBlockSearchFuncMatchEvents(c), "query,page,per_page,order_by,match_events"), 34 "validators": rpcserver.NewRPCFunc(makeValidatorsFunc(c), "height,page,per_page", rpcserver.Cacheable("height")), 35 "dump_consensus_state": rpcserver.NewRPCFunc(makeDumpConsensusStateFunc(c), ""), 36 "consensus_state": rpcserver.NewRPCFunc(makeConsensusStateFunc(c), ""), 37 "consensus_params": rpcserver.NewRPCFunc(makeConsensusParamsFunc(c), "height", rpcserver.Cacheable("height")), 38 "unconfirmed_txs": rpcserver.NewRPCFunc(makeUnconfirmedTxsFunc(c), "limit"), 39 "num_unconfirmed_txs": rpcserver.NewRPCFunc(makeNumUnconfirmedTxsFunc(c), ""), 40 41 // tx broadcast API 42 "broadcast_tx_commit": rpcserver.NewRPCFunc(makeBroadcastTxCommitFunc(c), "tx"), 43 "broadcast_tx_sync": rpcserver.NewRPCFunc(makeBroadcastTxSyncFunc(c), "tx"), 44 "broadcast_tx_async": rpcserver.NewRPCFunc(makeBroadcastTxAsyncFunc(c), "tx"), 45 46 // abci API 47 "abci_query": rpcserver.NewRPCFunc(makeABCIQueryFunc(c), "path,data,height,prove"), 48 "abci_info": rpcserver.NewRPCFunc(makeABCIInfoFunc(c), "", rpcserver.Cacheable()), 49 50 // evidence API 51 "broadcast_evidence": rpcserver.NewRPCFunc(makeBroadcastEvidenceFunc(c), "evidence"), 52 } 53 } 54 55 type rpcHealthFunc func(ctx *rpctypes.Context) (*ctypes.ResultHealth, error) 56 57 func makeHealthFunc(c *lrpc.Client) rpcHealthFunc { 58 return func(ctx *rpctypes.Context) (*ctypes.ResultHealth, error) { 59 return c.Health(ctx.Context()) 60 } 61 } 62 63 type rpcStatusFunc func(ctx *rpctypes.Context) (*ctypes.ResultStatus, error) 64 65 //nolint:interfacer 66 func makeStatusFunc(c *lrpc.Client) rpcStatusFunc { 67 return func(ctx *rpctypes.Context) (*ctypes.ResultStatus, error) { 68 return c.Status(ctx.Context()) 69 } 70 } 71 72 type rpcNetInfoFunc func(ctx *rpctypes.Context, minHeight, maxHeight int64) (*ctypes.ResultNetInfo, error) 73 74 func makeNetInfoFunc(c *lrpc.Client) rpcNetInfoFunc { 75 return func(ctx *rpctypes.Context, minHeight, maxHeight int64) (*ctypes.ResultNetInfo, error) { 76 return c.NetInfo(ctx.Context()) 77 } 78 } 79 80 type rpcBlockchainInfoFunc func(ctx *rpctypes.Context, minHeight, maxHeight int64) (*ctypes.ResultBlockchainInfo, error) 81 82 func makeBlockchainInfoFunc(c *lrpc.Client) rpcBlockchainInfoFunc { 83 return func(ctx *rpctypes.Context, minHeight, maxHeight int64) (*ctypes.ResultBlockchainInfo, error) { 84 return c.BlockchainInfo(ctx.Context(), minHeight, maxHeight) 85 } 86 } 87 88 type rpcGenesisFunc func(ctx *rpctypes.Context) (*ctypes.ResultGenesis, error) 89 90 func makeGenesisFunc(c *lrpc.Client) rpcGenesisFunc { 91 return func(ctx *rpctypes.Context) (*ctypes.ResultGenesis, error) { 92 return c.Genesis(ctx.Context()) 93 } 94 } 95 96 type rpcGenesisChunkedFunc func(ctx *rpctypes.Context, chunk uint) (*ctypes.ResultGenesisChunk, error) 97 98 func makeGenesisChunkedFunc(c *lrpc.Client) rpcGenesisChunkedFunc { 99 return func(ctx *rpctypes.Context, chunk uint) (*ctypes.ResultGenesisChunk, error) { 100 return c.GenesisChunked(ctx.Context(), chunk) 101 } 102 } 103 104 type rpcBlockFunc func(ctx *rpctypes.Context, height *int64) (*ctypes.ResultBlock, error) 105 106 func makeBlockFunc(c *lrpc.Client) rpcBlockFunc { 107 return func(ctx *rpctypes.Context, height *int64) (*ctypes.ResultBlock, error) { 108 return c.Block(ctx.Context(), height) 109 } 110 } 111 112 type rpcBlockByHashFunc func(ctx *rpctypes.Context, hash []byte) (*ctypes.ResultBlock, error) 113 114 func makeBlockByHashFunc(c *lrpc.Client) rpcBlockByHashFunc { 115 return func(ctx *rpctypes.Context, hash []byte) (*ctypes.ResultBlock, error) { 116 return c.BlockByHash(ctx.Context(), hash) 117 } 118 } 119 120 type rpcBlockResultsFunc func(ctx *rpctypes.Context, height *int64) (*ctypes.ResultBlockResults, error) 121 122 func makeBlockResultsFunc(c *lrpc.Client) rpcBlockResultsFunc { 123 return func(ctx *rpctypes.Context, height *int64) (*ctypes.ResultBlockResults, error) { 124 return c.BlockResults(ctx.Context(), height) 125 } 126 } 127 128 type rpcCommitFunc func(ctx *rpctypes.Context, height *int64) (*ctypes.ResultCommit, error) 129 130 func makeCommitFunc(c *lrpc.Client) rpcCommitFunc { 131 return func(ctx *rpctypes.Context, height *int64) (*ctypes.ResultCommit, error) { 132 return c.Commit(ctx.Context(), height) 133 } 134 } 135 136 type rpcTxFunc func(ctx *rpctypes.Context, hash []byte, prove bool) (*ctypes.ResultTx, error) 137 138 func makeTxFunc(c *lrpc.Client) rpcTxFunc { 139 return func(ctx *rpctypes.Context, hash []byte, prove bool) (*ctypes.ResultTx, error) { 140 return c.Tx(ctx.Context(), hash, prove) 141 } 142 } 143 144 type rpcTxSearchFuncMatchEvents func( 145 ctx *rpctypes.Context, 146 query string, 147 prove bool, 148 page, perPage *int, 149 orderBy string, 150 matchEvents bool, 151 ) (*ctypes.ResultTxSearch, error) 152 153 func makeTxSearchFuncMatchEvents(c *lrpc.Client) rpcTxSearchFuncMatchEvents { 154 return func( 155 ctx *rpctypes.Context, 156 query string, 157 prove bool, 158 page, perPage *int, 159 orderBy string, 160 matchEvents bool, 161 ) (*ctypes.ResultTxSearch, error) { 162 if matchEvents { 163 query = "match.events = 1 AND " + query 164 } else { 165 query = "match.events = 0 AND " + query 166 } 167 return c.TxSearch(ctx.Context(), query, prove, page, perPage, orderBy) 168 } 169 } 170 171 type rpcBlockSearchFuncMatchEvents func( 172 ctx *rpctypes.Context, 173 query string, 174 prove bool, 175 page, perPage *int, 176 orderBy string, 177 matchEvents bool, 178 ) (*ctypes.ResultBlockSearch, error) 179 180 func makeBlockSearchFuncMatchEvents(c *lrpc.Client) rpcBlockSearchFuncMatchEvents { 181 return func( 182 ctx *rpctypes.Context, 183 query string, 184 prove bool, 185 page, perPage *int, 186 orderBy string, 187 matchEvents bool, 188 ) (*ctypes.ResultBlockSearch, error) { 189 if matchEvents { 190 query = "match.events = 1 AND " + query 191 } else { 192 query = "match.events = 0 AND " + query 193 } 194 return c.BlockSearch(ctx.Context(), query, page, perPage, orderBy) 195 } 196 } 197 198 type rpcValidatorsFunc func(ctx *rpctypes.Context, height *int64, 199 page, perPage *int) (*ctypes.ResultValidators, error) 200 201 func makeValidatorsFunc(c *lrpc.Client) rpcValidatorsFunc { 202 return func(ctx *rpctypes.Context, height *int64, page, perPage *int) (*ctypes.ResultValidators, error) { 203 return c.Validators(ctx.Context(), height, page, perPage) 204 } 205 } 206 207 type rpcDumpConsensusStateFunc func(ctx *rpctypes.Context) (*ctypes.ResultDumpConsensusState, error) 208 209 func makeDumpConsensusStateFunc(c *lrpc.Client) rpcDumpConsensusStateFunc { 210 return func(ctx *rpctypes.Context) (*ctypes.ResultDumpConsensusState, error) { 211 return c.DumpConsensusState(ctx.Context()) 212 } 213 } 214 215 type rpcConsensusStateFunc func(ctx *rpctypes.Context) (*ctypes.ResultConsensusState, error) 216 217 func makeConsensusStateFunc(c *lrpc.Client) rpcConsensusStateFunc { 218 return func(ctx *rpctypes.Context) (*ctypes.ResultConsensusState, error) { 219 return c.ConsensusState(ctx.Context()) 220 } 221 } 222 223 type rpcConsensusParamsFunc func(ctx *rpctypes.Context, height *int64) (*ctypes.ResultConsensusParams, error) 224 225 func makeConsensusParamsFunc(c *lrpc.Client) rpcConsensusParamsFunc { 226 return func(ctx *rpctypes.Context, height *int64) (*ctypes.ResultConsensusParams, error) { 227 return c.ConsensusParams(ctx.Context(), height) 228 } 229 } 230 231 type rpcUnconfirmedTxsFunc func(ctx *rpctypes.Context, limit *int) (*ctypes.ResultUnconfirmedTxs, error) 232 233 func makeUnconfirmedTxsFunc(c *lrpc.Client) rpcUnconfirmedTxsFunc { 234 return func(ctx *rpctypes.Context, limit *int) (*ctypes.ResultUnconfirmedTxs, error) { 235 return c.UnconfirmedTxs(ctx.Context(), limit) 236 } 237 } 238 239 type rpcNumUnconfirmedTxsFunc func(ctx *rpctypes.Context) (*ctypes.ResultUnconfirmedTxs, error) 240 241 func makeNumUnconfirmedTxsFunc(c *lrpc.Client) rpcNumUnconfirmedTxsFunc { 242 return func(ctx *rpctypes.Context) (*ctypes.ResultUnconfirmedTxs, error) { 243 return c.NumUnconfirmedTxs(ctx.Context()) 244 } 245 } 246 247 type rpcBroadcastTxCommitFunc func(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) 248 249 func makeBroadcastTxCommitFunc(c *lrpc.Client) rpcBroadcastTxCommitFunc { 250 return func(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) { 251 return c.BroadcastTxCommit(ctx.Context(), tx) 252 } 253 } 254 255 type rpcBroadcastTxSyncFunc func(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcastTx, error) 256 257 func makeBroadcastTxSyncFunc(c *lrpc.Client) rpcBroadcastTxSyncFunc { 258 return func(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcastTx, error) { 259 return c.BroadcastTxSync(ctx.Context(), tx) 260 } 261 } 262 263 type rpcBroadcastTxAsyncFunc func(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcastTx, error) 264 265 func makeBroadcastTxAsyncFunc(c *lrpc.Client) rpcBroadcastTxAsyncFunc { 266 return func(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcastTx, error) { 267 return c.BroadcastTxAsync(ctx.Context(), tx) 268 } 269 } 270 271 type rpcABCIQueryFunc func(ctx *rpctypes.Context, path string, 272 data bytes.HexBytes, height int64, prove bool) (*ctypes.ResultABCIQuery, error) 273 274 func makeABCIQueryFunc(c *lrpc.Client) rpcABCIQueryFunc { 275 return func(ctx *rpctypes.Context, path string, data bytes.HexBytes, 276 height int64, prove bool, 277 ) (*ctypes.ResultABCIQuery, error) { 278 return c.ABCIQueryWithOptions(ctx.Context(), path, data, rpcclient.ABCIQueryOptions{ 279 Height: height, 280 Prove: prove, 281 }) 282 } 283 } 284 285 type rpcABCIInfoFunc func(ctx *rpctypes.Context) (*ctypes.ResultABCIInfo, error) 286 287 func makeABCIInfoFunc(c *lrpc.Client) rpcABCIInfoFunc { 288 return func(ctx *rpctypes.Context) (*ctypes.ResultABCIInfo, error) { 289 return c.ABCIInfo(ctx.Context()) 290 } 291 } 292 293 type rpcBroadcastEvidenceFunc func(ctx *rpctypes.Context, ev types.Evidence) (*ctypes.ResultBroadcastEvidence, error) 294 295 //nolint:interfacer 296 func makeBroadcastEvidenceFunc(c *lrpc.Client) rpcBroadcastEvidenceFunc { 297 return func(ctx *rpctypes.Context, ev types.Evidence) (*ctypes.ResultBroadcastEvidence, error) { 298 return c.BroadcastEvidence(ctx.Context(), ev) 299 } 300 }