2024-09-07 00:09:42 +00:00
|
|
|
use anyhow::Error;
|
|
|
|
|
2024-09-02 22:08:52 +00:00
|
|
|
use cuprate_rpc_types::{
|
|
|
|
bin::{
|
|
|
|
BinRequest, BinResponse, GetBlocksByHeightRequest, GetBlocksByHeightResponse,
|
|
|
|
GetBlocksRequest, GetBlocksResponse, GetHashesRequest, GetHashesResponse,
|
|
|
|
GetOutputIndexesRequest, GetOutputIndexesResponse, GetOutsRequest, GetOutsResponse,
|
|
|
|
GetTransactionPoolHashesRequest, GetTransactionPoolHashesResponse,
|
|
|
|
},
|
|
|
|
json::{GetOutputDistributionRequest, GetOutputDistributionResponse},
|
2024-09-02 21:37:18 +00:00
|
|
|
};
|
|
|
|
|
2024-09-05 22:11:27 +00:00
|
|
|
use crate::rpc::CupratedRpcHandlerState;
|
2024-09-02 21:37:18 +00:00
|
|
|
|
2024-09-05 22:06:07 +00:00
|
|
|
/// Map a [`BinRequest`] to the function that will lead to a [`BinResponse`].
|
|
|
|
pub(super) async fn map_request(
|
2024-09-05 22:11:27 +00:00
|
|
|
state: CupratedRpcHandlerState,
|
2024-09-02 22:08:52 +00:00
|
|
|
request: BinRequest,
|
2024-09-07 00:09:42 +00:00
|
|
|
) -> Result<BinResponse, Error> {
|
2024-09-02 22:08:52 +00:00
|
|
|
use BinRequest as Req;
|
|
|
|
use BinResponse as Resp;
|
2024-09-02 21:37:18 +00:00
|
|
|
|
2024-09-02 22:08:52 +00:00
|
|
|
Ok(match request {
|
2024-09-05 22:06:07 +00:00
|
|
|
Req::GetBlocks(r) => Resp::GetBlocks(get_blocks(state, r).await?),
|
|
|
|
Req::GetBlocksByHeight(r) => Resp::GetBlocksByHeight(get_blocks_by_height(state, r).await?),
|
|
|
|
Req::GetHashes(r) => Resp::GetHashes(get_hashes(state, r).await?),
|
|
|
|
Req::GetOutputIndexes(r) => Resp::GetOutputIndexes(get_output_indexes(state, r).await?),
|
|
|
|
Req::GetOuts(r) => Resp::GetOuts(get_outs(state, r).await?),
|
2024-09-02 21:37:18 +00:00
|
|
|
Req::GetTransactionPoolHashes(r) => {
|
2024-09-05 22:06:07 +00:00
|
|
|
Resp::GetTransactionPoolHashes(get_transaction_pool_hashes(state, r).await?)
|
2024-09-02 21:37:18 +00:00
|
|
|
}
|
|
|
|
Req::GetOutputDistribution(r) => {
|
2024-09-05 22:06:07 +00:00
|
|
|
Resp::GetOutputDistribution(get_output_distribution(state, r).await?)
|
2024-09-02 21:37:18 +00:00
|
|
|
}
|
2024-09-02 22:08:52 +00:00
|
|
|
})
|
2024-09-02 21:37:18 +00:00
|
|
|
}
|
|
|
|
|
2024-09-09 21:31:22 +00:00
|
|
|
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L611-L789>
|
2024-09-05 22:06:07 +00:00
|
|
|
async fn get_blocks(
|
2024-09-05 22:11:27 +00:00
|
|
|
state: CupratedRpcHandlerState,
|
2024-09-02 22:08:52 +00:00
|
|
|
request: GetBlocksRequest,
|
2024-09-07 00:09:42 +00:00
|
|
|
) -> Result<GetBlocksResponse, Error> {
|
2024-09-02 21:37:18 +00:00
|
|
|
todo!()
|
|
|
|
}
|
|
|
|
|
2024-09-09 21:31:22 +00:00
|
|
|
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L817-L857>
|
2024-09-05 22:06:07 +00:00
|
|
|
async fn get_blocks_by_height(
|
2024-09-05 22:11:27 +00:00
|
|
|
state: CupratedRpcHandlerState,
|
2024-09-02 21:37:18 +00:00
|
|
|
request: GetBlocksByHeightRequest,
|
2024-09-07 00:09:42 +00:00
|
|
|
) -> Result<GetBlocksByHeightResponse, Error> {
|
2024-09-02 21:37:18 +00:00
|
|
|
todo!()
|
|
|
|
}
|
|
|
|
|
2024-09-09 21:31:22 +00:00
|
|
|
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L859-L880>
|
2024-09-05 22:06:07 +00:00
|
|
|
async fn get_hashes(
|
2024-09-05 22:11:27 +00:00
|
|
|
state: CupratedRpcHandlerState,
|
2024-09-02 22:08:52 +00:00
|
|
|
request: GetHashesRequest,
|
2024-09-07 00:09:42 +00:00
|
|
|
) -> Result<GetHashesResponse, Error> {
|
2024-09-02 21:37:18 +00:00
|
|
|
todo!()
|
|
|
|
}
|
|
|
|
|
2024-09-09 21:31:22 +00:00
|
|
|
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L959-L977>
|
2024-09-05 22:06:07 +00:00
|
|
|
async fn get_output_indexes(
|
2024-09-05 22:11:27 +00:00
|
|
|
state: CupratedRpcHandlerState,
|
2024-09-02 21:37:18 +00:00
|
|
|
request: GetOutputIndexesRequest,
|
2024-09-07 00:09:42 +00:00
|
|
|
) -> Result<GetOutputIndexesResponse, Error> {
|
2024-09-02 21:37:18 +00:00
|
|
|
todo!()
|
|
|
|
}
|
|
|
|
|
2024-09-09 21:31:22 +00:00
|
|
|
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L882-L910>
|
2024-09-05 22:06:07 +00:00
|
|
|
async fn get_outs(
|
2024-09-05 22:11:27 +00:00
|
|
|
state: CupratedRpcHandlerState,
|
2024-09-02 22:08:52 +00:00
|
|
|
request: GetOutsRequest,
|
2024-09-07 00:09:42 +00:00
|
|
|
) -> Result<GetOutsResponse, Error> {
|
2024-09-02 21:37:18 +00:00
|
|
|
todo!()
|
|
|
|
}
|
|
|
|
|
2024-09-09 21:31:22 +00:00
|
|
|
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L1689-L1711>
|
2024-09-05 22:06:07 +00:00
|
|
|
async fn get_transaction_pool_hashes(
|
2024-09-05 22:11:27 +00:00
|
|
|
state: CupratedRpcHandlerState,
|
2024-09-02 21:37:18 +00:00
|
|
|
request: GetTransactionPoolHashesRequest,
|
2024-09-07 00:09:42 +00:00
|
|
|
) -> Result<GetTransactionPoolHashesResponse, Error> {
|
2024-09-02 21:37:18 +00:00
|
|
|
todo!()
|
|
|
|
}
|
2024-09-02 21:47:23 +00:00
|
|
|
|
2024-09-09 21:31:22 +00:00
|
|
|
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L3352-L3398>
|
2024-09-05 22:06:07 +00:00
|
|
|
async fn get_output_distribution(
|
2024-09-05 22:11:27 +00:00
|
|
|
state: CupratedRpcHandlerState,
|
2024-09-02 21:37:18 +00:00
|
|
|
request: GetOutputDistributionRequest,
|
2024-09-07 00:09:42 +00:00
|
|
|
) -> Result<GetOutputDistributionResponse, Error> {
|
2024-09-02 21:37:18 +00:00
|
|
|
todo!()
|
|
|
|
}
|