2024-09-03 00:34:02 +00:00
|
|
|
use cuprate_rpc_interface::RpcError;
|
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
|
|
|
};
|
|
|
|
|
|
|
|
use crate::rpc::CupratedRpcHandler;
|
|
|
|
|
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-02 22:08:52 +00:00
|
|
|
state: CupratedRpcHandler,
|
|
|
|
request: BinRequest,
|
|
|
|
) -> Result<BinResponse, RpcError> {
|
|
|
|
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-05 22:06:07 +00:00
|
|
|
async fn get_blocks(
|
2024-09-02 22:08:52 +00:00
|
|
|
state: CupratedRpcHandler,
|
|
|
|
request: GetBlocksRequest,
|
|
|
|
) -> Result<GetBlocksResponse, RpcError> {
|
2024-09-02 21:37:18 +00:00
|
|
|
todo!()
|
|
|
|
}
|
|
|
|
|
2024-09-05 22:06:07 +00:00
|
|
|
async fn get_blocks_by_height(
|
2024-09-02 21:37:18 +00:00
|
|
|
state: CupratedRpcHandler,
|
|
|
|
request: GetBlocksByHeightRequest,
|
2024-09-02 22:08:52 +00:00
|
|
|
) -> Result<GetBlocksByHeightResponse, RpcError> {
|
2024-09-02 21:37:18 +00:00
|
|
|
todo!()
|
|
|
|
}
|
|
|
|
|
2024-09-05 22:06:07 +00:00
|
|
|
async fn get_hashes(
|
2024-09-02 22:08:52 +00:00
|
|
|
state: CupratedRpcHandler,
|
|
|
|
request: GetHashesRequest,
|
|
|
|
) -> Result<GetHashesResponse, RpcError> {
|
2024-09-02 21:37:18 +00:00
|
|
|
todo!()
|
|
|
|
}
|
|
|
|
|
2024-09-05 22:06:07 +00:00
|
|
|
async fn get_output_indexes(
|
2024-09-02 21:37:18 +00:00
|
|
|
state: CupratedRpcHandler,
|
|
|
|
request: GetOutputIndexesRequest,
|
2024-09-02 22:08:52 +00:00
|
|
|
) -> Result<GetOutputIndexesResponse, RpcError> {
|
2024-09-02 21:37:18 +00:00
|
|
|
todo!()
|
|
|
|
}
|
|
|
|
|
2024-09-05 22:06:07 +00:00
|
|
|
async fn get_outs(
|
2024-09-02 22:08:52 +00:00
|
|
|
state: CupratedRpcHandler,
|
|
|
|
request: GetOutsRequest,
|
|
|
|
) -> Result<GetOutsResponse, RpcError> {
|
2024-09-02 21:37:18 +00:00
|
|
|
todo!()
|
|
|
|
}
|
|
|
|
|
2024-09-05 22:06:07 +00:00
|
|
|
async fn get_transaction_pool_hashes(
|
2024-09-02 21:37:18 +00:00
|
|
|
state: CupratedRpcHandler,
|
|
|
|
request: GetTransactionPoolHashesRequest,
|
2024-09-02 22:08:52 +00:00
|
|
|
) -> Result<GetTransactionPoolHashesResponse, RpcError> {
|
2024-09-02 21:37:18 +00:00
|
|
|
todo!()
|
|
|
|
}
|
2024-09-02 21:47:23 +00:00
|
|
|
|
2024-09-05 22:06:07 +00:00
|
|
|
async fn get_output_distribution(
|
2024-09-02 21:37:18 +00:00
|
|
|
state: CupratedRpcHandler,
|
|
|
|
request: GetOutputDistributionRequest,
|
2024-09-02 22:08:52 +00:00
|
|
|
) -> Result<GetOutputDistributionResponse, RpcError> {
|
2024-09-02 21:37:18 +00:00
|
|
|
todo!()
|
|
|
|
}
|