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