error signatures

This commit is contained in:
hinto.janai 2024-09-02 18:08:52 -04:00
parent 57677a5e90
commit 5f37771729
No known key found for this signature in database
GPG key ID: D47CE05FA175A499
9 changed files with 294 additions and 221 deletions

View file

@ -2,6 +2,8 @@
//!
//! Will contain the code to initiate the RPC and a request handler.
#![allow(clippy::needless_pass_by_value)] // TODO: remove after impl.
mod bin;
mod handler;
mod json;

View file

@ -1,68 +1,83 @@
use cuprate_rpc_types::bin::{
GetBlocksByHeightRequest, GetBlocksByHeightResponse, GetBlocksRequest, GetBlocksResponse,
GetHashesRequest, GetHashesResponse, GetOutputDistributionRequest,
GetOutputDistributionResponse, GetOutputIndexesRequest, GetOutputIndexesResponse,
GetOutsRequest, GetOutsResponse, GetTransactionPoolHashesRequest,
GetTransactionPoolHashesResponse,
use cuprate_rpc_interface::{RpcError, RpcResponse};
use cuprate_rpc_types::{
bin::{
BinRequest, BinResponse, GetBlocksByHeightRequest, GetBlocksByHeightResponse,
GetBlocksRequest, GetBlocksResponse, GetHashesRequest, GetHashesResponse,
GetOutputIndexesRequest, GetOutputIndexesResponse, GetOutsRequest, GetOutsResponse,
GetTransactionPoolHashesRequest, GetTransactionPoolHashesResponse,
},
json::{GetOutputDistributionRequest, GetOutputDistributionResponse},
};
use crate::rpc::CupratedRpcHandler;
pub(super) async fn map_request(state: CupratedRpcHandler, request: BinRpcRequest) -> BinRpcResponse {
use BinRpcRequest as Req;
use BinRpcResponse as Resp;
pub(super) fn map_request(
state: CupratedRpcHandler,
request: BinRequest,
) -> Result<BinResponse, RpcError> {
use BinRequest as Req;
use BinResponse as Resp;
match request {
Req::GetBlocks(r) => Resp::GetBlocks(get_blocks(state, r)),
Req::GetBlocksByHeight(r) => Resp::GetBlocksByHeight(get_blocks_by_height(state, r)),
Req::GetHashes(r) => Resp::GetHashes(get_hashes(state, r)),
Req::GetOutputIndexes(r) => Resp::GetOutputIndexes(get_output_indexes(state, r)),
Req::GetOuts(r) => Resp::GetOuts(get_outs(state, r)),
Ok(match request {
Req::GetBlocks(r) => Resp::GetBlocks(get_blocks(state, r)?),
Req::GetBlocksByHeight(r) => Resp::GetBlocksByHeight(get_blocks_by_height(state, r)?),
Req::GetHashes(r) => Resp::GetHashes(get_hashes(state, r)?),
Req::GetOutputIndexes(r) => Resp::GetOutputIndexes(get_output_indexes(state, r)?),
Req::GetOuts(r) => Resp::GetOuts(get_outs(state, r)?),
Req::GetTransactionPoolHashes(r) => {
Resp::GetTransactionPoolHashes(get_transaction_pool_hashes(state, r))
Resp::GetTransactionPoolHashes(get_transaction_pool_hashes(state, r)?)
}
Req::GetOutputDistribution(r) => {
Resp::GetOutputDistribution(get_output_distribution(state, r))
}
Resp::GetOutputDistribution(get_output_distribution(state, r)?)
}
})
}
async fn get_blocks(state: CupratedRpcHandler, request: GetBlocksRequest) -> GetBlocksResponse {
fn get_blocks(
state: CupratedRpcHandler,
request: GetBlocksRequest,
) -> Result<GetBlocksResponse, RpcError> {
todo!()
}
async fn get_blocks_by_height(
fn get_blocks_by_height(
state: CupratedRpcHandler,
request: GetBlocksByHeightRequest,
) -> GetBlocksByHeightResponse {
) -> Result<GetBlocksByHeightResponse, RpcError> {
todo!()
}
async fn get_hashes(state: CupratedRpcHandler, request: GetHashesRequest) -> GetHashesResponse {
fn get_hashes(
state: CupratedRpcHandler,
request: GetHashesRequest,
) -> Result<GetHashesResponse, RpcError> {
todo!()
}
async fn get_output_indexes(
fn get_output_indexes(
state: CupratedRpcHandler,
request: GetOutputIndexesRequest,
) -> GetOutputIndexesResponse {
) -> Result<GetOutputIndexesResponse, RpcError> {
todo!()
}
async fn get_outs(state: CupratedRpcHandler, request: GetOutsRequest) -> GetOutsResponse {
fn get_outs(
state: CupratedRpcHandler,
request: GetOutsRequest,
) -> Result<GetOutsResponse, RpcError> {
todo!()
}
async fn get_transaction_pool_hashes(
fn get_transaction_pool_hashes(
state: CupratedRpcHandler,
request: GetTransactionPoolHashesRequest,
) -> GetTransactionPoolHashesResponse {
) -> Result<GetTransactionPoolHashesResponse, RpcError> {
todo!()
}
async fn get_output_distribution(
fn get_output_distribution(
state: CupratedRpcHandler,
request: GetOutputDistributionRequest,
) -> GetOutputDistributionResponse {
) -> Result<GetOutputDistributionResponse, RpcError> {
todo!()
}

View file

@ -7,34 +7,26 @@ use futures::channel::oneshot::channel;
use serde::{Deserialize, Serialize};
use tower::Service;
use cuprate_blockchain::service::{BlockchainReadHandle, BlockchainWriteHandle};
use cuprate_blockchain::service::BlockchainReadHandle;
use cuprate_helper::asynch::InfallibleOneshotReceiver;
use cuprate_json_rpc::Id;
use cuprate_rpc_interface::{RpcError, RpcHandler, RpcRequest, RpcResponse};
use cuprate_txpool::service::{TxpoolReadHandle, TxpoolWriteHandle};
use cuprate_txpool::service::TxpoolReadHandle;
use crate::rpc::{bin, json, other};
//---------------------------------------------------------------------------------------------------- CupratedRpcHandler
/// TODO
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Deserialize, Serialize)]
#[derive(Clone)]
pub struct CupratedRpcHandler {
/// Should this RPC server be [restricted](RpcHandler::restricted)?
pub restricted: bool,
/// Read handle to the blockchain database.
pub blockchain_read: BlockchainReadHandle,
/// Write handle to the blockchain database.
pub blockchain_write: BlockchainWriteHandle,
/// Direct handle to the blockchain database.
pub blockchain_db: Arc<ConcreteEnv>,
pub blockchain: BlockchainReadHandle,
/// Read handle to the transaction pool database.
pub txpool_read: TxpoolReadHandle,
/// Write handle to the transaction pool database.
pub txpool_write: TxpoolWriteHandle,
/// Direct handle to the transaction pool database.
pub txpool_db: Arc<ConcreteEnv>,
pub txpool: TxpoolReadHandle,
}
//---------------------------------------------------------------------------------------------------- RpcHandler Impl
@ -60,16 +52,19 @@ impl Service<RpcRequest> for CupratedRpcHandler {
///
/// We can assume the request coming has the required permissions.
fn call(&mut self, req: RpcRequest) -> Self::Future {
let state = CupratedRpcHandler::clone(self);
let state = Self::clone(self);
let resp = match req {
RpcRequest::JsonRpc(r) => json::map_request(state, r), // JSON-RPC 2.0 requests.
RpcRequest::Binary(r) => bin::map_request(state, r), // Binary requests.
RpcRequest::Other(o) => other::map_request(state, r), // JSON (but not JSON-RPC) requests.
RpcRequest::JsonRpc(r) => {
RpcResponse::JsonRpc(json::map_request(state, r).expect("TODO"))
} // JSON-RPC 2.0 requests.
RpcRequest::Binary(r) => RpcResponse::Binary(bin::map_request(state, r).expect("TODO")), // Binary requests.
RpcRequest::Other(r) => RpcResponse::Other(other::map_request(state, r).expect("TODO")), // JSON (but not JSON-RPC) requests.
};
let (tx, rx) = channel();
drop(tx.send(Ok(resp)));
InfallibleOneshotReceiver::from(rx)
todo!()
// let (tx, rx) = channel();
// drop(tx.send(Ok(resp)));
// InfallibleOneshotReceiver::from(rx)
}
}

View file

@ -1,5 +1,6 @@
use std::sync::Arc;
use cuprate_rpc_interface::{RpcError, RpcResponse};
use cuprate_rpc_types::json::{
AddAuxPowRequest, AddAuxPowResponse, BannedRequest, BannedResponse, CalcPowRequest,
CalcPowResponse, FlushCacheRequest, FlushCacheResponse, FlushTransactionPoolRequest,
@ -22,230 +23,260 @@ use cuprate_rpc_types::json::{
use crate::rpc::CupratedRpcHandler;
pub(super) async fn map_request(
pub(super) fn map_request(
state: CupratedRpcHandler,
request: JsonRpcRequest,
) -> JsonRpcResponse {
) -> Result<JsonRpcResponse, RpcError> {
use JsonRpcRequest as Req;
use JsonRpcResponse as Resp;
match request {
Req::GetBlockCount(r) => Resp::GetBlockCount(get_block_count(state, r)),
Req::OnGetBlockHash(r) => Resp::OnGetBlockHash(on_get_block_hash(state, r)),
Req::SubmitBlock(r) => Resp::SubmitBlock(submit_block(state, r)),
Req::GenerateBlocks(r) => Resp::GenerateBlocks(generate_blocks(state, r)),
Req::GetLastBlockHeader(r) => Resp::GetLastBlockHeader(get_last_block_header(state, r)),
Ok(match request {
Req::GetBlockCount(r) => Resp::GetBlockCount(get_block_count(state, r)?),
Req::OnGetBlockHash(r) => Resp::OnGetBlockHash(on_get_block_hash(state, r)?),
Req::SubmitBlock(r) => Resp::SubmitBlock(submit_block(state, r)?),
Req::GenerateBlocks(r) => Resp::GenerateBlocks(generate_blocks(state, r)?),
Req::GetLastBlockHeader(r) => Resp::GetLastBlockHeader(get_last_block_header(state, r)?),
Req::GetBlockHeaderByHash(r) => {
Resp::GetBlockHeaderByHash(get_block_header_by_hash(state, r))
Resp::GetBlockHeaderByHash(get_block_header_by_hash(state, r)?)
}
Req::GetBlockHeaderByHeight(r) => {
Resp::GetBlockHeaderByHeight(get_block_header_by_height(state, r))
Resp::GetBlockHeaderByHeight(get_block_header_by_height(state, r)?)
}
Req::GetBlockHeadersRange(r) => {
Resp::GetBlockHeadersRange(get_block_headers_range(state, r))
Resp::GetBlockHeadersRange(get_block_headers_range(state, r)?)
}
Req::GetBlock(r) => Resp::GetBlock(get_block(state, r)),
Req::GetConnections(r) => Resp::GetConnections(get_connections(state, r)),
Req::GetInfo(r) => Resp::GetInfo(get_info(state, r)),
Req::HardForkInfo(r) => Resp::HardForkInfo(hard_fork_info(state, r)),
Req::SetBans(r) => Resp::SetBans(set_bans(state, r)),
Req::GetBans(r) => Resp::GetBans(get_bans(state, r)),
Req::Banned(r) => Resp::Banned(banned(state, r)),
Req::GetBlock(r) => Resp::GetBlock(get_block(state, r)?),
Req::GetConnections(r) => Resp::GetConnections(get_connections(state, r)?),
Req::GetInfo(r) => Resp::GetInfo(get_info(state, r)?),
Req::HardForkInfo(r) => Resp::HardForkInfo(hard_fork_info(state, r)?),
Req::SetBans(r) => Resp::SetBans(set_bans(state, r)?),
Req::GetBans(r) => Resp::GetBans(get_bans(state, r)?),
Req::Banned(r) => Resp::Banned(banned(state, r)?),
Req::FlushTransactionPool(r) => {
Resp::FlushTransactionPool(flush_transaction_pool(state, r))
Resp::FlushTransactionPool(flush_transaction_pool(state, r)?)
}
Req::GetOutputHistogram(r) => Resp::GetOutputHistogram(get_output_histogram(state, r)),
Req::GetCoinbaseTxSum(r) => Resp::GetCoinbaseTxSum(get_coinbase_tx_sum(state, r)),
Req::GetVersion(r) => Resp::GetVersion(get_version(state, r)),
Req::GetFeeEstimate(r) => Resp::GetFeeEstimate(get_fee_estimate(state, r)),
Req::GetAlternateChains(r) => Resp::GetAlternateChains(get_alternate_chains(state, r)),
Req::RelayTx(r) => Resp::RelayTx(relay_tx(state, r)),
Req::SyncInfo(r) => Resp::SyncInfo(sync_info(state, r)),
Req::GetOutputHistogram(r) => Resp::GetOutputHistogram(get_output_histogram(state, r)?),
Req::GetCoinbaseTxSum(r) => Resp::GetCoinbaseTxSum(get_coinbase_tx_sum(state, r)?),
Req::GetVersion(r) => Resp::GetVersion(get_version(state, r)?),
Req::GetFeeEstimate(r) => Resp::GetFeeEstimate(get_fee_estimate(state, r)?),
Req::GetAlternateChains(r) => Resp::GetAlternateChains(get_alternate_chains(state, r)?),
Req::RelayTx(r) => Resp::RelayTx(relay_tx(state, r)?),
Req::SyncInfo(r) => Resp::SyncInfo(sync_info(state, r)?),
Req::GetTransactionPoolBacklog(r) => {
Resp::GetTransactionPoolBacklog(get_transaction_pool_backlog(state, r))
}
Req::GetMinerData(r) => Resp::GetMinerData(get_miner_data(state, r)),
Req::PruneBlockchain(r) => Resp::PruneBlockchain(prune_blockchain(state, r)),
Req::CalcPow(r) => Resp::CalcPow(calc_pow(state, r)),
Req::FlushCache(r) => Resp::FlushCache(flush_cache(state, r)),
Req::AddAuxPow(r) => Resp::AddAuxPow(add_aux_pow(state, r)),
Req::GetTxIdsLoose(r) => Resp::GetTxIdsLoose(get_tx_ids_loose(state, r)),
Resp::GetTransactionPoolBacklog(get_transaction_pool_backlog(state, r)?)
}
Req::GetMinerData(r) => Resp::GetMinerData(get_miner_data(state, r)?),
Req::PruneBlockchain(r) => Resp::PruneBlockchain(prune_blockchain(state, r)?),
Req::CalcPow(r) => Resp::CalcPow(calc_pow(state, r)?),
Req::FlushCache(r) => Resp::FlushCache(flush_cache(state, r)?),
Req::AddAuxPow(r) => Resp::AddAuxPow(add_aux_pow(state, r)?),
Req::GetTxIdsLoose(r) => Resp::GetTxIdsLoose(get_tx_ids_loose(state, r)?),
})
}
async fn get_block_count(
fn get_block_count(
state: CupratedRpcHandler,
request: GetBlockCountRequest,
) -> GetBlockCountResponse {
) -> Result<GetBlockCountResponse, RpcError> {
todo!()
}
async fn on_get_block_hash(
fn on_get_block_hash(
state: CupratedRpcHandler,
request: OnGetBlockHashRequest,
) -> OnGetBlockHashResponse {
) -> Result<OnGetBlockHashResponse, RpcError> {
todo!()
}
async fn submit_block(
fn submit_block(
state: CupratedRpcHandler,
request: SubmitBlockRequest,
) -> SubmitBlockResponse {
) -> Result<SubmitBlockResponse, RpcError> {
todo!()
}
async fn generate_blocks(
fn generate_blocks(
state: CupratedRpcHandler,
request: GenerateBlocksRequest,
) -> GenerateBlocksResponse {
) -> Result<GenerateBlocksResponse, RpcError> {
todo!()
}
async fn get_last_block_header(
fn get_last_block_header(
state: CupratedRpcHandler,
request: GetLastBlockHeaderRequest,
) -> GetLastBlockHeaderResponse {
) -> Result<GetLastBlockHeaderResponse, RpcError> {
todo!()
}
async fn get_block_header_by_hash(
fn get_block_header_by_hash(
state: CupratedRpcHandler,
request: GetBlockHeaderByHashRequest,
) -> GetBlockHeaderByHashResponse {
) -> Result<GetBlockHeaderByHashResponse, RpcError> {
todo!()
}
async fn get_block_header_by_height(
fn get_block_header_by_height(
state: CupratedRpcHandler,
request: GetBlockHeaderByHeightRequest,
) -> GetBlockHeaderByHeightResponse {
) -> Result<GetBlockHeaderByHeightResponse, RpcError> {
todo!()
}
async fn get_block_headers_range(
fn get_block_headers_range(
state: CupratedRpcHandler,
request: GetBlockHeadersRangeRequest,
) -> GetBlockHeadersRangeResponse {
) -> Result<GetBlockHeadersRangeResponse, RpcError> {
todo!()
}
async fn get_block(state: CupratedRpcHandler, request: GetBlockRequest) -> GetBlockResponse {
fn get_block(
state: CupratedRpcHandler,
request: GetBlockRequest,
) -> Result<GetBlockResponse, RpcError> {
todo!()
}
async fn get_connections(
fn get_connections(
state: CupratedRpcHandler,
request: GetConnectionsRequest,
) -> GetConnectionsResponse {
) -> Result<GetConnectionsResponse, RpcError> {
todo!()
}
async fn get_info(state: CupratedRpcHandler, request: GetInfoRequest) -> GetInfoResponse {
fn get_info(
state: CupratedRpcHandler,
request: GetInfoRequest,
) -> Result<GetInfoResponse, RpcError> {
todo!()
}
async fn hard_fork_info(
fn hard_fork_info(
state: CupratedRpcHandler,
request: HardForkInfoRequest,
) -> HardForkInfoResponse {
) -> Result<HardForkInfoResponse, RpcError> {
todo!()
}
async fn set_bans(state: CupratedRpcHandler, request: SetBansRequest) -> SetBansResponse {
fn set_bans(
state: CupratedRpcHandler,
request: SetBansRequest,
) -> Result<SetBansResponse, RpcError> {
todo!()
}
async fn get_bans(state: CupratedRpcHandler, request: GetBansRequest) -> GetBansResponse {
fn get_bans(
state: CupratedRpcHandler,
request: GetBansRequest,
) -> Result<GetBansResponse, RpcError> {
todo!()
}
async fn banned(state: CupratedRpcHandler, request: BannedRequest) -> BannedResponse {
fn banned(state: CupratedRpcHandler, request: BannedRequest) -> Result<BannedResponse, RpcError> {
todo!()
}
async fn flush_transaction_pool(
fn flush_transaction_pool(
state: CupratedRpcHandler,
request: FlushTransactionPoolRequest,
) -> FlushTransactionPoolResponse {
) -> Result<FlushTransactionPoolResponse, RpcError> {
todo!()
}
async fn get_output_histogram(
fn get_output_histogram(
state: CupratedRpcHandler,
request: GetOutputHistogramRequest,
) -> GetOutputHistogramResponse {
) -> Result<GetOutputHistogramResponse, RpcError> {
todo!()
}
async fn get_coinbase_tx_sum(
fn get_coinbase_tx_sum(
state: CupratedRpcHandler,
request: GetCoinbaseTxSumRequest,
) -> GetCoinbaseTxSumResponse {
) -> Result<GetCoinbaseTxSumResponse, RpcError> {
todo!()
}
async fn get_version(state: CupratedRpcHandler, request: GetVersionRequest) -> GetVersionResponse {
fn get_version(
state: CupratedRpcHandler,
request: GetVersionRequest,
) -> Result<GetVersionResponse, RpcError> {
todo!()
}
async fn get_fee_estimate(
fn get_fee_estimate(
state: CupratedRpcHandler,
request: GetFeeEstimateRequest,
) -> GetFeeEstimateResponse {
) -> Result<GetFeeEstimateResponse, RpcError> {
todo!()
}
async fn get_alternate_chains(
fn get_alternate_chains(
state: CupratedRpcHandler,
request: GetAlternateChainsRequest,
) -> GetAlternateChainsResponse {
) -> Result<GetAlternateChainsResponse, RpcError> {
todo!()
}
async fn relay_tx(state: CupratedRpcHandler, request: RelayTxRequest) -> RelayTxResponse {
fn relay_tx(
state: CupratedRpcHandler,
request: RelayTxRequest,
) -> Result<RelayTxResponse, RpcError> {
todo!()
}
async fn sync_info(state: CupratedRpcHandler, request: SyncInfoRequest) -> SyncInfoResponse {
fn sync_info(
state: CupratedRpcHandler,
request: SyncInfoRequest,
) -> Result<SyncInfoResponse, RpcError> {
todo!()
}
async fn get_transaction_pool_backlog(
fn get_transaction_pool_backlog(
state: CupratedRpcHandler,
request: GetTransactionPoolBacklogRequest,
) -> GetTransactionPoolBacklogResponse {
) -> Result<GetTransactionPoolBacklogResponse, RpcError> {
todo!()
}
async fn get_miner_data(
fn get_miner_data(
state: CupratedRpcHandler,
request: GetMinerDataRequest,
) -> GetMinerDataResponse {
) -> Result<GetMinerDataResponse, RpcError> {
todo!()
}
async fn prune_blockchain(
fn prune_blockchain(
state: CupratedRpcHandler,
request: PruneBlockchainRequest,
) -> PruneBlockchainResponse {
) -> Result<PruneBlockchainResponse, RpcError> {
todo!()
}
async fn calc_pow(state: CupratedRpcHandler, request: CalcPowRequest) -> CalcPowResponse {
fn calc_pow(
state: CupratedRpcHandler,
request: CalcPowRequest,
) -> Result<CalcPowResponse, RpcError> {
todo!()
}
async fn flush_cache(state: CupratedRpcHandler, request: FlushCacheRequest) -> FlushCacheResponse {
fn flush_cache(
state: CupratedRpcHandler,
request: FlushCacheRequest,
) -> Result<FlushCacheResponse, RpcError> {
todo!()
}
async fn add_aux_pow(state: CupratedRpcHandler, request: AddAuxPowRequest) -> AddAuxPowResponse {
fn add_aux_pow(
state: CupratedRpcHandler,
request: AddAuxPowRequest,
) -> Result<AddAuxPowResponse, RpcError> {
todo!()
}
async fn get_tx_ids_loose(
fn get_tx_ids_loose(
state: CupratedRpcHandler,
request: GetTxIdsLooseRequest,
) -> GetTxIdsLooseResponse {
) -> Result<GetTxIdsLooseResponse, RpcError> {
todo!()
}

View file

@ -1,3 +1,4 @@
use cuprate_rpc_interface::{RpcError, RpcResponse};
use cuprate_rpc_types::other::{
GetAltBlocksHashesRequest, GetAltBlocksHashesResponse, GetHeightRequest, GetHeightResponse,
GetLimitRequest, GetLimitResponse, GetNetStatsRequest, GetNetStatsResponse, GetOutsRequest,
@ -6,211 +7,238 @@ use cuprate_rpc_types::other::{
GetTransactionPoolRequest, GetTransactionPoolResponse, GetTransactionPoolStatsRequest,
GetTransactionPoolStatsResponse, GetTransactionsRequest, GetTransactionsResponse,
InPeersRequest, InPeersResponse, IsKeyImageSpentRequest, IsKeyImageSpentResponse,
MiningStatusRequest, MiningStatusResponse, 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,
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;
pub(super) async fn map_request(
pub(super) fn map_request(
state: CupratedRpcHandler,
request: OtherRpcRequest,
) -> OtherRpcResponse {
use OtherRpcRequest as Req;
use OtherRpcResponse as Resp;
request: OtherRequest,
) -> Result<OtherResponse, RpcError> {
use OtherRequest as Req;
use OtherResponse as Resp;
match request {
Req::GetHeight(r) => Resp::GetHeight(get_height(state, r)),
Req::GetTransactions(r) => Resp::GetTransactions(get_transactions(state, r)),
Req::GetAltBlocksHashes(r) => Resp::GetAltBlocksHashes(get_alt_blocks_hashes(state, r)),
Req::IsKeyImageSpent(r) => Resp::IsKeyImageSpent(is_key_image_spent(state, r)),
Req::SendRawTransaction(r) => Resp::SendRawTransaction(send_raw_transaction(state, r)),
Req::StartMining(r) => Resp::StartMining(start_mining(state, r)),
Req::StopMining(r) => Resp::StopMining(stop_mining(state, r)),
Req::MiningStatus(r) => Resp::MiningStatus(mining_status(state, r)),
Req::SaveBc(r) => Resp::SaveBc(save_bc(state, r)),
Req::GetPeerList(r) => Resp::GetPeerList(get_peer_list(state, r)),
Req::SetLogHashRate(r) => Resp::SetLogHashRate(set_log_hash_rate(state, r)),
Req::SetLogLevel(r) => Resp::SetLogLevel(set_log_level(state, r)),
Req::SetLogCategories(r) => Resp::SetLogCategories(set_log_categories(state, r)),
Req::SetBootstrapDaemon(r) => Resp::SetBootstrapDaemon(set_bootstrap_daemon(state, r)),
Req::GetTransactionPool(r) => Resp::GetTransactionPool(get_transaction_pool(state, r)),
Ok(match request {
Req::GetHeight(r) => Resp::GetHeight(get_height(state, r)?),
Req::GetTransactions(r) => Resp::GetTransactions(get_transactions(state, r)?),
Req::GetAltBlocksHashes(r) => Resp::GetAltBlocksHashes(get_alt_blocks_hashes(state, r)?),
Req::IsKeyImageSpent(r) => Resp::IsKeyImageSpent(is_key_image_spent(state, r)?),
Req::SendRawTransaction(r) => Resp::SendRawTransaction(send_raw_transaction(state, r)?),
Req::StartMining(r) => Resp::StartMining(start_mining(state, r)?),
Req::StopMining(r) => Resp::StopMining(stop_mining(state, r)?),
Req::MiningStatus(r) => Resp::MiningStatus(mining_status(state, r)?),
Req::SaveBc(r) => Resp::SaveBc(save_bc(state, r)?),
Req::GetPeerList(r) => Resp::GetPeerList(get_peer_list(state, r)?),
Req::SetLogHashRate(r) => Resp::SetLogHashRate(set_log_hash_rate(state, r)?),
Req::SetLogLevel(r) => Resp::SetLogLevel(set_log_level(state, r)?),
Req::SetLogCategories(r) => Resp::SetLogCategories(set_log_categories(state, r)?),
Req::SetBootstrapDaemon(r) => Resp::SetBootstrapDaemon(set_bootstrap_daemon(state, r)?),
Req::GetTransactionPool(r) => Resp::GetTransactionPool(get_transaction_pool(state, r)?),
Req::GetTransactionPoolStats(r) => {
Resp::GetTransactionPoolStats(get_transaction_pool_stats(state, r))
Resp::GetTransactionPoolStats(get_transaction_pool_stats(state, r)?)
}
Req::StopDaemon(r) => Resp::StopDaemon(stop_daemon(state, r)),
Req::GetLimit(r) => Resp::GetLimit(get_limit(state, r)),
Req::SetLimit(r) => Resp::SetLimit(set_limit(state, r)),
Req::OutPeers(r) => Resp::OutPeers(out_peers(state, r)),
Req::InPeers(r) => Resp::InPeers(in_peers(state, r)),
Req::GetNetStats(r) => Resp::GetNetStats(get_net_stats(state, r)),
Req::GetOuts(r) => Resp::GetOuts(get_outs(state, r)),
Req::Update(r) => Resp::Update(update(state, r)),
Req::PopBlocks(r) => Resp::PopBlocks(pop_blocks(state, r)),
Req::StopDaemon(r) => Resp::StopDaemon(stop_daemon(state, r)?),
Req::GetLimit(r) => Resp::GetLimit(get_limit(state, r)?),
Req::SetLimit(r) => Resp::SetLimit(set_limit(state, r)?),
Req::OutPeers(r) => Resp::OutPeers(out_peers(state, r)?),
Req::InPeers(r) => Resp::InPeers(in_peers(state, r)?),
Req::GetNetStats(r) => Resp::GetNetStats(get_net_stats(state, r)?),
Req::GetOuts(r) => Resp::GetOuts(get_outs(state, r)?),
Req::Update(r) => Resp::Update(update(state, r)?),
Req::PopBlocks(r) => Resp::PopBlocks(pop_blocks(state, r)?),
Req::GetTransactionPoolHashes(r) => {
Resp::GetTransactionPoolHashes(get_transaction_pool_hashes(state, r))
}
Req::GetPublicNodes(r) => Resp::GetPublicNodes(get_public_nodes(state, r)),
Resp::GetTransactionPoolHashes(get_transaction_pool_hashes(state, r)?)
}
Req::GetPublicNodes(r) => Resp::GetPublicNodes(get_public_nodes(state, r)?),
})
}
async fn get_height(state: CupratedRpcHandler, request: GetHeightRequest) -> GetHeightResponse {
fn get_height(
state: CupratedRpcHandler,
request: GetHeightRequest,
) -> Result<GetHeightResponse, RpcError> {
todo!()
}
async fn get_transactions(
fn get_transactions(
state: CupratedRpcHandler,
request: GetTransactionsRequest,
) -> GetTransactionsResponse {
) -> Result<GetTransactionsResponse, RpcError> {
todo!()
}
async fn get_alt_blocks_hashes(
fn get_alt_blocks_hashes(
state: CupratedRpcHandler,
request: GetAltBlocksHashesRequest,
) -> GetAltBlocksHashesResponse {
) -> Result<GetAltBlocksHashesResponse, RpcError> {
todo!()
}
async fn is_key_image_spent(
fn is_key_image_spent(
state: CupratedRpcHandler,
request: IsKeyImageSpentRequest,
) -> IsKeyImageSpentResponse {
) -> Result<IsKeyImageSpentResponse, RpcError> {
todo!()
}
async fn send_raw_transaction(
fn send_raw_transaction(
state: CupratedRpcHandler,
request: SendRawTransactionRequest,
) -> SendRawTransactionResponse {
) -> Result<SendRawTransactionResponse, RpcError> {
todo!()
}
async fn start_mining(
fn start_mining(
state: CupratedRpcHandler,
request: StartMiningRequest,
) -> StartMiningResponse {
) -> Result<StartMiningResponse, RpcError> {
todo!()
}
async fn stop_mining(state: CupratedRpcHandler, request: StopMiningRequest) -> StopMiningResponse {
fn stop_mining(
state: CupratedRpcHandler,
request: StopMiningRequest,
) -> Result<StopMiningResponse, RpcError> {
todo!()
}
async fn mining_status(
fn mining_status(
state: CupratedRpcHandler,
request: MiningStatusRequest,
) -> MiningStatusResponse {
) -> Result<MiningStatusResponse, RpcError> {
todo!()
}
async fn save_bc(state: CupratedRpcHandler, request: SaveBcRequest) -> SaveBcResponse {
fn save_bc(state: CupratedRpcHandler, request: SaveBcRequest) -> Result<SaveBcResponse, RpcError> {
todo!()
}
async fn get_peer_list(
fn get_peer_list(
state: CupratedRpcHandler,
request: GetPeerListRequest,
) -> GetPeerListResponse {
) -> Result<GetPeerListResponse, RpcError> {
todo!()
}
async fn set_log_hash_rate(
fn set_log_hash_rate(
state: CupratedRpcHandler,
request: SetLogHashRateRequest,
) -> SetLogHashRateResponse {
) -> Result<SetLogHashRateResponse, RpcError> {
todo!()
}
async fn set_log_level(
fn set_log_level(
state: CupratedRpcHandler,
request: SetLogLevelRequest,
) -> SetLogLevelResponse {
) -> Result<SetLogLevelResponse, RpcError> {
todo!()
}
async fn set_log_categories(
fn set_log_categories(
state: CupratedRpcHandler,
request: SetLogCategoriesRequest,
) -> SetLogCategoriesResponse {
) -> Result<SetLogCategoriesResponse, RpcError> {
todo!()
}
async fn set_bootstrap_daemon(
fn set_bootstrap_daemon(
state: CupratedRpcHandler,
request: SetBootstrapDaemonRequest,
) -> SetBootstrapDaemonResponse {
) -> Result<SetBootstrapDaemonResponse, RpcError> {
todo!()
}
async fn get_transaction_pool(
fn get_transaction_pool(
state: CupratedRpcHandler,
request: GetTransactionPoolRequest,
) -> GetTransactionPoolResponse {
) -> Result<GetTransactionPoolResponse, RpcError> {
todo!()
}
async fn get_transaction_pool_stats(
fn get_transaction_pool_stats(
state: CupratedRpcHandler,
request: GetTransactionPoolStatsRequest,
) -> GetTransactionPoolStatsResponse {
) -> Result<GetTransactionPoolStatsResponse, RpcError> {
todo!()
}
async fn stop_daemon(state: CupratedRpcHandler, request: StopDaemonRequest) -> StopDaemonResponse {
fn stop_daemon(
state: CupratedRpcHandler,
request: StopDaemonRequest,
) -> Result<StopDaemonResponse, RpcError> {
todo!()
}
async fn get_limit(state: CupratedRpcHandler, request: GetLimitRequest) -> GetLimitResponse {
fn get_limit(
state: CupratedRpcHandler,
request: GetLimitRequest,
) -> Result<GetLimitResponse, RpcError> {
todo!()
}
async fn set_limit(state: CupratedRpcHandler, request: SetLimitRequest) -> SetLimitResponse {
fn set_limit(
state: CupratedRpcHandler,
request: SetLimitRequest,
) -> Result<SetLimitResponse, RpcError> {
todo!()
}
async fn out_peers(state: CupratedRpcHandler, request: OutPeersRequest) -> OutPeersResponse {
fn out_peers(
state: CupratedRpcHandler,
request: OutPeersRequest,
) -> Result<OutPeersResponse, RpcError> {
todo!()
}
async fn in_peers(state: CupratedRpcHandler, request: InPeersRequest) -> InPeersResponse {
fn in_peers(
state: CupratedRpcHandler,
request: InPeersRequest,
) -> Result<InPeersResponse, RpcError> {
todo!()
}
async fn get_net_stats(
fn get_net_stats(
state: CupratedRpcHandler,
request: GetNetStatsRequest,
) -> GetNetStatsResponse {
) -> Result<GetNetStatsResponse, RpcError> {
todo!()
}
async fn get_outs(state: CupratedRpcHandler, request: GetOutsRequest) -> GetOutsResponse {
fn get_outs(
state: CupratedRpcHandler,
request: GetOutsRequest,
) -> Result<GetOutsResponse, RpcError> {
todo!()
}
async fn update(state: CupratedRpcHandler, request: UpdateRequest) -> UpdateResponse {
fn update(state: CupratedRpcHandler, request: UpdateRequest) -> Result<UpdateResponse, RpcError> {
todo!()
}
async fn pop_blocks(state: CupratedRpcHandler, request: PopBlocksRequest) -> PopBlocksResponse {
fn pop_blocks(
state: CupratedRpcHandler,
request: PopBlocksRequest,
) -> Result<PopBlocksResponse, RpcError> {
todo!()
}
async fn get_transaction_pool_hashes(
fn get_transaction_pool_hashes(
state: CupratedRpcHandler,
request: GetTransactionPoolHashesRequest,
) -> GetTransactionPoolHashesResponse {
) -> Result<GetTransactionPoolHashesResponse, RpcError> {
todo!()
}
async fn get_public_nodes(
fn get_public_nodes(
state: CupratedRpcHandler,
request: GetPublicNodesRequest,
) -> GetPublicNodesResponse {
) -> Result<GetPublicNodesResponse, RpcError> {
todo!()
}

View file

@ -50,7 +50,7 @@ pub(crate) async fn json_rpc<H: RpcHandler>(
}
// Send request.
let request = RpcRequest::JsonRpc(request);
let request = RpcRequest::JsonRpc(request.body);
let channel = handler.oneshot(request).await?;
// Assert the response from the inner handler is correct.
@ -58,6 +58,8 @@ pub(crate) async fn json_rpc<H: RpcHandler>(
panic!("RPC handler returned incorrect response");
};
let response = todo!();
Ok(Json(response))
}

View file

@ -62,7 +62,7 @@ impl Service<RpcRequest> for RpcHandlerDummy {
#[rustfmt::skip]
#[allow(clippy::default_trait_access)]
let resp = match req {
RpcRequest::JsonRpc(j) => RpcResponse::JsonRpc(cuprate_json_rpc::Response::ok(Id::Null, match j.body {
RpcRequest::JsonRpc(j) => RpcResponse::JsonRpc(match j {
JReq::GetBlockCount(_) => JResp::GetBlockCount(Default::default()),
JReq::OnGetBlockHash(_) => JResp::OnGetBlockHash(Default::default()),
JReq::SubmitBlock(_) => JResp::SubmitBlock(Default::default()),
@ -93,7 +93,7 @@ impl Service<RpcRequest> for RpcHandlerDummy {
JReq::FlushCache(_) => JResp::FlushCache(Default::default()),
JReq::AddAuxPow(_) => JResp::AddAuxPow(Default::default()),
JReq::GetTxIdsLoose(_) => JResp::GetTxIdsLoose(Default::default()),
})),
}),
RpcRequest::Binary(b) => RpcResponse::Binary(match b {
BReq::GetBlocks(_) => BResp::GetBlocks(Default::default()),
BReq::GetBlocksByHeight(_) => BResp::GetBlocksByHeight(Default::default()),

View file

@ -19,7 +19,7 @@ use cuprate_rpc_types::{bin::BinRequest, json::JsonRpcRequest, other::OtherReque
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
pub enum RpcRequest {
/// JSON-RPC 2.0 requests.
JsonRpc(cuprate_json_rpc::Request<JsonRpcRequest>),
JsonRpc(JsonRpcRequest),
/// Binary requests.
Binary(BinRequest),
/// Other JSON requests.

View file

@ -19,7 +19,7 @@ use cuprate_rpc_types::{bin::BinResponse, json::JsonRpcResponse, other::OtherRes
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
pub enum RpcResponse {
/// JSON RPC 2.0 responses.
JsonRpc(cuprate_json_rpc::Response<JsonRpcResponse>),
JsonRpc(JsonRpcResponse),
/// Binary responses.
Binary(BinResponse),
/// Other JSON responses.