gitlab.com/gpdionisio/tendermint@v0.34.19-dev2/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 "genesis_chunked": rpcserver.NewRPCFunc(makeGenesisChunkedFunc(c), ""), 27 "block": rpcserver.NewRPCFunc(makeBlockFunc(c), "height"), 28 "block_by_hash": rpcserver.NewRPCFunc(makeBlockByHashFunc(c), "hash"), 29 "block_results": rpcserver.NewRPCFunc(makeBlockResultsFunc(c), "height"), 30 "commit": rpcserver.NewRPCFunc(makeCommitFunc(c), "height"), 31 "tx": rpcserver.NewRPCFunc(makeTxFunc(c), "hash,prove"), 32 "tx_search": rpcserver.NewRPCFunc(makeTxSearchFunc(c), "query,prove,page,per_page,order_by"), 33 "block_search": rpcserver.NewRPCFunc(makeBlockSearchFunc(c), "query,page,per_page,order_by"), 34 "validators": rpcserver.NewRPCFunc(makeValidatorsFunc(c), "height,page,per_page"), 35 "dump_consensus_state": rpcserver.NewRPCFunc(makeDumpConsensusStateFunc(c), ""), 36 "consensus_state": rpcserver.NewRPCFunc(makeConsensusStateFunc(c), ""), 37 "consensus_params": rpcserver.NewRPCFunc(makeConsensusParamsFunc(c), "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), ""), 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 rpcTxSearchFunc func( 145 ctx *rpctypes.Context, 146 query string, 147 prove bool, 148 page, perPage *int, 149 orderBy string, 150 ) (*ctypes.ResultTxSearch, error) 151 152 func makeTxSearchFunc(c *lrpc.Client) rpcTxSearchFunc { 153 return func( 154 ctx *rpctypes.Context, 155 query string, 156 prove bool, 157 page, perPage *int, 158 orderBy string, 159 ) (*ctypes.ResultTxSearch, error) { 160 return c.TxSearch(ctx.Context(), query, prove, page, perPage, orderBy) 161 } 162 } 163 164 type rpcBlockSearchFunc func( 165 ctx *rpctypes.Context, 166 query string, 167 prove bool, 168 page, perPage *int, 169 orderBy string, 170 ) (*ctypes.ResultBlockSearch, error) 171 172 func makeBlockSearchFunc(c *lrpc.Client) rpcBlockSearchFunc { 173 return func( 174 ctx *rpctypes.Context, 175 query string, 176 prove bool, 177 page, perPage *int, 178 orderBy string, 179 ) (*ctypes.ResultBlockSearch, error) { 180 return c.BlockSearch(ctx.Context(), query, page, perPage, orderBy) 181 } 182 } 183 184 type rpcValidatorsFunc func(ctx *rpctypes.Context, height *int64, 185 page, perPage *int) (*ctypes.ResultValidators, error) 186 187 func makeValidatorsFunc(c *lrpc.Client) rpcValidatorsFunc { 188 return func(ctx *rpctypes.Context, height *int64, page, perPage *int) (*ctypes.ResultValidators, error) { 189 return c.Validators(ctx.Context(), height, page, perPage) 190 } 191 } 192 193 type rpcDumpConsensusStateFunc func(ctx *rpctypes.Context) (*ctypes.ResultDumpConsensusState, error) 194 195 func makeDumpConsensusStateFunc(c *lrpc.Client) rpcDumpConsensusStateFunc { 196 return func(ctx *rpctypes.Context) (*ctypes.ResultDumpConsensusState, error) { 197 return c.DumpConsensusState(ctx.Context()) 198 } 199 } 200 201 type rpcConsensusStateFunc func(ctx *rpctypes.Context) (*ctypes.ResultConsensusState, error) 202 203 func makeConsensusStateFunc(c *lrpc.Client) rpcConsensusStateFunc { 204 return func(ctx *rpctypes.Context) (*ctypes.ResultConsensusState, error) { 205 return c.ConsensusState(ctx.Context()) 206 } 207 } 208 209 type rpcConsensusParamsFunc func(ctx *rpctypes.Context, height *int64) (*ctypes.ResultConsensusParams, error) 210 211 func makeConsensusParamsFunc(c *lrpc.Client) rpcConsensusParamsFunc { 212 return func(ctx *rpctypes.Context, height *int64) (*ctypes.ResultConsensusParams, error) { 213 return c.ConsensusParams(ctx.Context(), height) 214 } 215 } 216 217 type rpcUnconfirmedTxsFunc func(ctx *rpctypes.Context, limit *int) (*ctypes.ResultUnconfirmedTxs, error) 218 219 func makeUnconfirmedTxsFunc(c *lrpc.Client) rpcUnconfirmedTxsFunc { 220 return func(ctx *rpctypes.Context, limit *int) (*ctypes.ResultUnconfirmedTxs, error) { 221 return c.UnconfirmedTxs(ctx.Context(), limit) 222 } 223 } 224 225 type rpcNumUnconfirmedTxsFunc func(ctx *rpctypes.Context) (*ctypes.ResultUnconfirmedTxs, error) 226 227 func makeNumUnconfirmedTxsFunc(c *lrpc.Client) rpcNumUnconfirmedTxsFunc { 228 return func(ctx *rpctypes.Context) (*ctypes.ResultUnconfirmedTxs, error) { 229 return c.NumUnconfirmedTxs(ctx.Context()) 230 } 231 } 232 233 type rpcBroadcastTxCommitFunc func(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) 234 235 func makeBroadcastTxCommitFunc(c *lrpc.Client) rpcBroadcastTxCommitFunc { 236 return func(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) { 237 return c.BroadcastTxCommit(ctx.Context(), tx) 238 } 239 } 240 241 type rpcBroadcastTxSyncFunc func(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcastTx, error) 242 243 func makeBroadcastTxSyncFunc(c *lrpc.Client) rpcBroadcastTxSyncFunc { 244 return func(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcastTx, error) { 245 return c.BroadcastTxSync(ctx.Context(), tx) 246 } 247 } 248 249 type rpcBroadcastTxAsyncFunc func(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcastTx, error) 250 251 func makeBroadcastTxAsyncFunc(c *lrpc.Client) rpcBroadcastTxAsyncFunc { 252 return func(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcastTx, error) { 253 return c.BroadcastTxAsync(ctx.Context(), tx) 254 } 255 } 256 257 type rpcABCIQueryFunc func(ctx *rpctypes.Context, path string, 258 data bytes.HexBytes, height int64, prove bool) (*ctypes.ResultABCIQuery, error) 259 260 func makeABCIQueryFunc(c *lrpc.Client) rpcABCIQueryFunc { 261 return func(ctx *rpctypes.Context, path string, data bytes.HexBytes, 262 height int64, prove bool) (*ctypes.ResultABCIQuery, error) { 263 264 return c.ABCIQueryWithOptions(ctx.Context(), path, data, rpcclient.ABCIQueryOptions{ 265 Height: height, 266 Prove: prove, 267 }) 268 } 269 } 270 271 type rpcABCIInfoFunc func(ctx *rpctypes.Context) (*ctypes.ResultABCIInfo, error) 272 273 func makeABCIInfoFunc(c *lrpc.Client) rpcABCIInfoFunc { 274 return func(ctx *rpctypes.Context) (*ctypes.ResultABCIInfo, error) { 275 return c.ABCIInfo(ctx.Context()) 276 } 277 } 278 279 type rpcBroadcastEvidenceFunc func(ctx *rpctypes.Context, ev types.Evidence) (*ctypes.ResultBroadcastEvidence, error) 280 281 // nolint: interfacer 282 func makeBroadcastEvidenceFunc(c *lrpc.Client) rpcBroadcastEvidenceFunc { 283 return func(ctx *rpctypes.Context, ev types.Evidence) (*ctypes.ResultBroadcastEvidence, error) { 284 return c.BroadcastEvidence(ctx.Context(), ev) 285 } 286 }