cuprated/rpc/
json.rs

1use std::sync::Arc;
2
3use anyhow::Error;
4use tower::ServiceExt;
5
6use cuprate_rpc_types::json::{
7    AddAuxPowRequest, AddAuxPowResponse, BannedRequest, BannedResponse, CalcPowRequest,
8    CalcPowResponse, FlushCacheRequest, FlushCacheResponse, FlushTransactionPoolRequest,
9    FlushTransactionPoolResponse, GenerateBlocksRequest, GenerateBlocksResponse,
10    GetAlternateChainsRequest, GetAlternateChainsResponse, GetBansRequest, GetBansResponse,
11    GetBlockCountRequest, GetBlockCountResponse, GetBlockHeaderByHashRequest,
12    GetBlockHeaderByHashResponse, GetBlockHeaderByHeightRequest, GetBlockHeaderByHeightResponse,
13    GetBlockHeadersRangeRequest, GetBlockHeadersRangeResponse, GetBlockRequest, GetBlockResponse,
14    GetCoinbaseTxSumRequest, GetCoinbaseTxSumResponse, GetConnectionsRequest,
15    GetConnectionsResponse, GetFeeEstimateRequest, GetFeeEstimateResponse, GetInfoRequest,
16    GetInfoResponse, GetLastBlockHeaderRequest, GetLastBlockHeaderResponse, GetMinerDataRequest,
17    GetMinerDataResponse, GetOutputHistogramRequest, GetOutputHistogramResponse,
18    GetTransactionPoolBacklogRequest, GetTransactionPoolBacklogResponse, GetTxIdsLooseRequest,
19    GetTxIdsLooseResponse, GetVersionRequest, GetVersionResponse, HardForkInfoRequest,
20    HardForkInfoResponse, JsonRpcRequest, JsonRpcResponse, OnGetBlockHashRequest,
21    OnGetBlockHashResponse, PruneBlockchainRequest, PruneBlockchainResponse, RelayTxRequest,
22    RelayTxResponse, SetBansRequest, SetBansResponse, SubmitBlockRequest, SubmitBlockResponse,
23    SyncInfoRequest, SyncInfoResponse,
24};
25
26use crate::rpc::CupratedRpcHandler;
27
28/// Map a [`JsonRpcRequest`] to the function that will lead to a [`JsonRpcResponse`].
29pub(super) async fn map_request(
30    state: CupratedRpcHandler,
31    request: JsonRpcRequest,
32) -> Result<JsonRpcResponse, Error> {
33    use JsonRpcRequest as Req;
34    use JsonRpcResponse as Resp;
35
36    Ok(match request {
37        Req::GetBlockCount(r) => Resp::GetBlockCount(get_block_count(state, r).await?),
38        Req::OnGetBlockHash(r) => Resp::OnGetBlockHash(on_get_block_hash(state, r).await?),
39        Req::SubmitBlock(r) => Resp::SubmitBlock(submit_block(state, r).await?),
40        Req::GenerateBlocks(r) => Resp::GenerateBlocks(generate_blocks(state, r).await?),
41        Req::GetLastBlockHeader(r) => {
42            Resp::GetLastBlockHeader(get_last_block_header(state, r).await?)
43        }
44        Req::GetBlockHeaderByHash(r) => {
45            Resp::GetBlockHeaderByHash(get_block_header_by_hash(state, r).await?)
46        }
47        Req::GetBlockHeaderByHeight(r) => {
48            Resp::GetBlockHeaderByHeight(get_block_header_by_height(state, r).await?)
49        }
50        Req::GetBlockHeadersRange(r) => {
51            Resp::GetBlockHeadersRange(get_block_headers_range(state, r).await?)
52        }
53        Req::GetBlock(r) => Resp::GetBlock(get_block(state, r).await?),
54        Req::GetConnections(r) => Resp::GetConnections(get_connections(state, r).await?),
55        Req::GetInfo(r) => Resp::GetInfo(get_info(state, r).await?),
56        Req::HardForkInfo(r) => Resp::HardForkInfo(hard_fork_info(state, r).await?),
57        Req::SetBans(r) => Resp::SetBans(set_bans(state, r).await?),
58        Req::GetBans(r) => Resp::GetBans(get_bans(state, r).await?),
59        Req::Banned(r) => Resp::Banned(banned(state, r).await?),
60        Req::FlushTransactionPool(r) => {
61            Resp::FlushTransactionPool(flush_transaction_pool(state, r).await?)
62        }
63        Req::GetOutputHistogram(r) => {
64            Resp::GetOutputHistogram(get_output_histogram(state, r).await?)
65        }
66        Req::GetCoinbaseTxSum(r) => Resp::GetCoinbaseTxSum(get_coinbase_tx_sum(state, r).await?),
67        Req::GetVersion(r) => Resp::GetVersion(get_version(state, r).await?),
68        Req::GetFeeEstimate(r) => Resp::GetFeeEstimate(get_fee_estimate(state, r).await?),
69        Req::GetAlternateChains(r) => {
70            Resp::GetAlternateChains(get_alternate_chains(state, r).await?)
71        }
72        Req::RelayTx(r) => Resp::RelayTx(relay_tx(state, r).await?),
73        Req::SyncInfo(r) => Resp::SyncInfo(sync_info(state, r).await?),
74        Req::GetTransactionPoolBacklog(r) => {
75            Resp::GetTransactionPoolBacklog(get_transaction_pool_backlog(state, r).await?)
76        }
77        Req::GetMinerData(r) => Resp::GetMinerData(get_miner_data(state, r).await?),
78        Req::PruneBlockchain(r) => Resp::PruneBlockchain(prune_blockchain(state, r).await?),
79        Req::CalcPow(r) => Resp::CalcPow(calc_pow(state, r).await?),
80        Req::FlushCache(r) => Resp::FlushCache(flush_cache(state, r).await?),
81        Req::AddAuxPow(r) => Resp::AddAuxPow(add_aux_pow(state, r).await?),
82        Req::GetTxIdsLoose(r) => Resp::GetTxIdsLoose(get_tx_ids_loose(state, r).await?),
83    })
84}
85
86async fn get_block_count(
87    state: CupratedRpcHandler,
88    request: GetBlockCountRequest,
89) -> Result<GetBlockCountResponse, Error> {
90    todo!()
91}
92
93async fn on_get_block_hash(
94    state: CupratedRpcHandler,
95    request: OnGetBlockHashRequest,
96) -> Result<OnGetBlockHashResponse, Error> {
97    todo!()
98}
99
100async fn submit_block(
101    state: CupratedRpcHandler,
102    request: SubmitBlockRequest,
103) -> Result<SubmitBlockResponse, Error> {
104    todo!()
105}
106
107async fn generate_blocks(
108    state: CupratedRpcHandler,
109    request: GenerateBlocksRequest,
110) -> Result<GenerateBlocksResponse, Error> {
111    todo!()
112}
113
114async fn get_last_block_header(
115    state: CupratedRpcHandler,
116    request: GetLastBlockHeaderRequest,
117) -> Result<GetLastBlockHeaderResponse, Error> {
118    todo!()
119}
120
121async fn get_block_header_by_hash(
122    state: CupratedRpcHandler,
123    request: GetBlockHeaderByHashRequest,
124) -> Result<GetBlockHeaderByHashResponse, Error> {
125    todo!()
126}
127
128async fn get_block_header_by_height(
129    state: CupratedRpcHandler,
130    request: GetBlockHeaderByHeightRequest,
131) -> Result<GetBlockHeaderByHeightResponse, Error> {
132    todo!()
133}
134
135async fn get_block_headers_range(
136    state: CupratedRpcHandler,
137    request: GetBlockHeadersRangeRequest,
138) -> Result<GetBlockHeadersRangeResponse, Error> {
139    todo!()
140}
141
142async fn get_block(
143    state: CupratedRpcHandler,
144    request: GetBlockRequest,
145) -> Result<GetBlockResponse, Error> {
146    todo!()
147}
148
149async fn get_connections(
150    state: CupratedRpcHandler,
151    request: GetConnectionsRequest,
152) -> Result<GetConnectionsResponse, Error> {
153    todo!()
154}
155
156async fn get_info(
157    state: CupratedRpcHandler,
158    request: GetInfoRequest,
159) -> Result<GetInfoResponse, Error> {
160    todo!()
161}
162
163async fn hard_fork_info(
164    state: CupratedRpcHandler,
165    request: HardForkInfoRequest,
166) -> Result<HardForkInfoResponse, Error> {
167    todo!()
168}
169
170async fn set_bans(
171    state: CupratedRpcHandler,
172    request: SetBansRequest,
173) -> Result<SetBansResponse, Error> {
174    todo!()
175}
176
177async fn get_bans(
178    state: CupratedRpcHandler,
179    request: GetBansRequest,
180) -> Result<GetBansResponse, Error> {
181    todo!()
182}
183
184async fn banned(
185    state: CupratedRpcHandler,
186    request: BannedRequest,
187) -> Result<BannedResponse, Error> {
188    todo!()
189}
190
191async fn flush_transaction_pool(
192    state: CupratedRpcHandler,
193    request: FlushTransactionPoolRequest,
194) -> Result<FlushTransactionPoolResponse, Error> {
195    todo!()
196}
197
198async fn get_output_histogram(
199    state: CupratedRpcHandler,
200    request: GetOutputHistogramRequest,
201) -> Result<GetOutputHistogramResponse, Error> {
202    todo!()
203}
204
205async fn get_coinbase_tx_sum(
206    state: CupratedRpcHandler,
207    request: GetCoinbaseTxSumRequest,
208) -> Result<GetCoinbaseTxSumResponse, Error> {
209    todo!()
210}
211
212async fn get_version(
213    state: CupratedRpcHandler,
214    request: GetVersionRequest,
215) -> Result<GetVersionResponse, Error> {
216    todo!()
217}
218
219async fn get_fee_estimate(
220    state: CupratedRpcHandler,
221    request: GetFeeEstimateRequest,
222) -> Result<GetFeeEstimateResponse, Error> {
223    todo!()
224}
225
226async fn get_alternate_chains(
227    state: CupratedRpcHandler,
228    request: GetAlternateChainsRequest,
229) -> Result<GetAlternateChainsResponse, Error> {
230    todo!()
231}
232
233async fn relay_tx(
234    state: CupratedRpcHandler,
235    request: RelayTxRequest,
236) -> Result<RelayTxResponse, Error> {
237    todo!()
238}
239
240async fn sync_info(
241    state: CupratedRpcHandler,
242    request: SyncInfoRequest,
243) -> Result<SyncInfoResponse, Error> {
244    todo!()
245}
246
247async fn get_transaction_pool_backlog(
248    state: CupratedRpcHandler,
249    request: GetTransactionPoolBacklogRequest,
250) -> Result<GetTransactionPoolBacklogResponse, Error> {
251    todo!()
252}
253
254async fn get_miner_data(
255    state: CupratedRpcHandler,
256    request: GetMinerDataRequest,
257) -> Result<GetMinerDataResponse, Error> {
258    todo!()
259}
260
261async fn prune_blockchain(
262    state: CupratedRpcHandler,
263    request: PruneBlockchainRequest,
264) -> Result<PruneBlockchainResponse, Error> {
265    todo!()
266}
267
268async fn calc_pow(
269    state: CupratedRpcHandler,
270    request: CalcPowRequest,
271) -> Result<CalcPowResponse, Error> {
272    todo!()
273}
274
275async fn flush_cache(
276    state: CupratedRpcHandler,
277    request: FlushCacheRequest,
278) -> Result<FlushCacheResponse, Error> {
279    todo!()
280}
281
282async fn add_aux_pow(
283    state: CupratedRpcHandler,
284    request: AddAuxPowRequest,
285) -> Result<AddAuxPowResponse, Error> {
286    todo!()
287}
288
289async fn get_tx_ids_loose(
290    state: CupratedRpcHandler,
291    request: GetTxIdsLooseRequest,
292) -> Result<GetTxIdsLooseResponse, Error> {
293    todo!()
294}