cuprated/rpc/
other.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
use anyhow::Error;

use cuprate_rpc_types::other::{
    GetAltBlocksHashesRequest, GetAltBlocksHashesResponse, GetHeightRequest, GetHeightResponse,
    GetLimitRequest, GetLimitResponse, GetNetStatsRequest, GetNetStatsResponse, GetOutsRequest,
    GetOutsResponse, GetPeerListRequest, GetPeerListResponse, GetPublicNodesRequest,
    GetPublicNodesResponse, GetTransactionPoolHashesRequest, GetTransactionPoolHashesResponse,
    GetTransactionPoolRequest, GetTransactionPoolResponse, GetTransactionPoolStatsRequest,
    GetTransactionPoolStatsResponse, GetTransactionsRequest, GetTransactionsResponse,
    InPeersRequest, InPeersResponse, IsKeyImageSpentRequest, IsKeyImageSpentResponse,
    MiningStatusRequest, MiningStatusResponse, OtherRequest, OtherResponse, OutPeersRequest,
    OutPeersResponse, PopBlocksRequest, PopBlocksResponse, SaveBcRequest, SaveBcResponse,
    SendRawTransactionRequest, SendRawTransactionResponse, SetBootstrapDaemonRequest,
    SetBootstrapDaemonResponse, SetLimitRequest, SetLimitResponse, SetLogCategoriesRequest,
    SetLogCategoriesResponse, SetLogHashRateRequest, SetLogHashRateResponse, SetLogLevelRequest,
    SetLogLevelResponse, StartMiningRequest, StartMiningResponse, StopDaemonRequest,
    StopDaemonResponse, StopMiningRequest, StopMiningResponse, UpdateRequest, UpdateResponse,
};

use crate::rpc::CupratedRpcHandler;

/// Map a [`OtherRequest`] to the function that will lead to a [`OtherResponse`].
pub(super) async fn map_request(
    state: CupratedRpcHandler,
    request: OtherRequest,
) -> Result<OtherResponse, Error> {
    use OtherRequest as Req;
    use OtherResponse as Resp;

    Ok(match request {
        Req::GetHeight(r) => Resp::GetHeight(get_height(state, r).await?),
        Req::GetTransactions(r) => Resp::GetTransactions(get_transactions(state, r).await?),
        Req::GetAltBlocksHashes(r) => {
            Resp::GetAltBlocksHashes(get_alt_blocks_hashes(state, r).await?)
        }
        Req::IsKeyImageSpent(r) => Resp::IsKeyImageSpent(is_key_image_spent(state, r).await?),
        Req::SendRawTransaction(r) => {
            Resp::SendRawTransaction(send_raw_transaction(state, r).await?)
        }
        Req::StartMining(r) => Resp::StartMining(start_mining(state, r).await?),
        Req::StopMining(r) => Resp::StopMining(stop_mining(state, r).await?),
        Req::MiningStatus(r) => Resp::MiningStatus(mining_status(state, r).await?),
        Req::SaveBc(r) => Resp::SaveBc(save_bc(state, r).await?),
        Req::GetPeerList(r) => Resp::GetPeerList(get_peer_list(state, r).await?),
        Req::SetLogHashRate(r) => Resp::SetLogHashRate(set_log_hash_rate(state, r).await?),
        Req::SetLogLevel(r) => Resp::SetLogLevel(set_log_level(state, r).await?),
        Req::SetLogCategories(r) => Resp::SetLogCategories(set_log_categories(state, r).await?),
        Req::SetBootstrapDaemon(r) => {
            Resp::SetBootstrapDaemon(set_bootstrap_daemon(state, r).await?)
        }
        Req::GetTransactionPool(r) => {
            Resp::GetTransactionPool(get_transaction_pool(state, r).await?)
        }
        Req::GetTransactionPoolStats(r) => {
            Resp::GetTransactionPoolStats(get_transaction_pool_stats(state, r).await?)
        }
        Req::StopDaemon(r) => Resp::StopDaemon(stop_daemon(state, r).await?),
        Req::GetLimit(r) => Resp::GetLimit(get_limit(state, r).await?),
        Req::SetLimit(r) => Resp::SetLimit(set_limit(state, r).await?),
        Req::OutPeers(r) => Resp::OutPeers(out_peers(state, r).await?),
        Req::InPeers(r) => Resp::InPeers(in_peers(state, r).await?),
        Req::GetNetStats(r) => Resp::GetNetStats(get_net_stats(state, r).await?),
        Req::GetOuts(r) => Resp::GetOuts(get_outs(state, r).await?),
        Req::Update(r) => Resp::Update(update(state, r).await?),
        Req::PopBlocks(r) => Resp::PopBlocks(pop_blocks(state, r).await?),
        Req::GetTransactionPoolHashes(r) => {
            Resp::GetTransactionPoolHashes(get_transaction_pool_hashes(state, r).await?)
        }
        Req::GetPublicNodes(r) => Resp::GetPublicNodes(get_public_nodes(state, r).await?),
    })
}

async fn get_height(
    state: CupratedRpcHandler,
    request: GetHeightRequest,
) -> Result<GetHeightResponse, Error> {
    todo!()
}

async fn get_transactions(
    state: CupratedRpcHandler,
    request: GetTransactionsRequest,
) -> Result<GetTransactionsResponse, Error> {
    todo!()
}

async fn get_alt_blocks_hashes(
    state: CupratedRpcHandler,
    request: GetAltBlocksHashesRequest,
) -> Result<GetAltBlocksHashesResponse, Error> {
    todo!()
}

async fn is_key_image_spent(
    state: CupratedRpcHandler,
    request: IsKeyImageSpentRequest,
) -> Result<IsKeyImageSpentResponse, Error> {
    todo!()
}

async fn send_raw_transaction(
    state: CupratedRpcHandler,
    request: SendRawTransactionRequest,
) -> Result<SendRawTransactionResponse, Error> {
    todo!()
}

async fn start_mining(
    state: CupratedRpcHandler,
    request: StartMiningRequest,
) -> Result<StartMiningResponse, Error> {
    todo!()
}

async fn stop_mining(
    state: CupratedRpcHandler,
    request: StopMiningRequest,
) -> Result<StopMiningResponse, Error> {
    todo!()
}

async fn mining_status(
    state: CupratedRpcHandler,
    request: MiningStatusRequest,
) -> Result<MiningStatusResponse, Error> {
    todo!()
}

async fn save_bc(
    state: CupratedRpcHandler,
    request: SaveBcRequest,
) -> Result<SaveBcResponse, Error> {
    todo!()
}

async fn get_peer_list(
    state: CupratedRpcHandler,
    request: GetPeerListRequest,
) -> Result<GetPeerListResponse, Error> {
    todo!()
}

async fn set_log_hash_rate(
    state: CupratedRpcHandler,
    request: SetLogHashRateRequest,
) -> Result<SetLogHashRateResponse, Error> {
    todo!()
}

async fn set_log_level(
    state: CupratedRpcHandler,
    request: SetLogLevelRequest,
) -> Result<SetLogLevelResponse, Error> {
    todo!()
}

async fn set_log_categories(
    state: CupratedRpcHandler,
    request: SetLogCategoriesRequest,
) -> Result<SetLogCategoriesResponse, Error> {
    todo!()
}

async fn set_bootstrap_daemon(
    state: CupratedRpcHandler,
    request: SetBootstrapDaemonRequest,
) -> Result<SetBootstrapDaemonResponse, Error> {
    todo!()
}

async fn get_transaction_pool(
    state: CupratedRpcHandler,
    request: GetTransactionPoolRequest,
) -> Result<GetTransactionPoolResponse, Error> {
    todo!()
}

async fn get_transaction_pool_stats(
    state: CupratedRpcHandler,
    request: GetTransactionPoolStatsRequest,
) -> Result<GetTransactionPoolStatsResponse, Error> {
    todo!()
}

async fn stop_daemon(
    state: CupratedRpcHandler,
    request: StopDaemonRequest,
) -> Result<StopDaemonResponse, Error> {
    todo!()
}

async fn get_limit(
    state: CupratedRpcHandler,
    request: GetLimitRequest,
) -> Result<GetLimitResponse, Error> {
    todo!()
}

async fn set_limit(
    state: CupratedRpcHandler,
    request: SetLimitRequest,
) -> Result<SetLimitResponse, Error> {
    todo!()
}

async fn out_peers(
    state: CupratedRpcHandler,
    request: OutPeersRequest,
) -> Result<OutPeersResponse, Error> {
    todo!()
}

async fn in_peers(
    state: CupratedRpcHandler,
    request: InPeersRequest,
) -> Result<InPeersResponse, Error> {
    todo!()
}

async fn get_net_stats(
    state: CupratedRpcHandler,
    request: GetNetStatsRequest,
) -> Result<GetNetStatsResponse, Error> {
    todo!()
}

async fn get_outs(
    state: CupratedRpcHandler,
    request: GetOutsRequest,
) -> Result<GetOutsResponse, Error> {
    todo!()
}

async fn update(
    state: CupratedRpcHandler,
    request: UpdateRequest,
) -> Result<UpdateResponse, Error> {
    todo!()
}

async fn pop_blocks(
    state: CupratedRpcHandler,
    request: PopBlocksRequest,
) -> Result<PopBlocksResponse, Error> {
    todo!()
}

async fn get_transaction_pool_hashes(
    state: CupratedRpcHandler,
    request: GetTransactionPoolHashesRequest,
) -> Result<GetTransactionPoolHashesResponse, Error> {
    todo!()
}

async fn get_public_nodes(
    state: CupratedRpcHandler,
    request: GetPublicNodesRequest,
) -> Result<GetPublicNodesResponse, Error> {
    todo!()
}