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