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