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. //! 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 bin;
mod handler; mod handler;
mod json; mod json;

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -62,7 +62,7 @@ impl Service<RpcRequest> for RpcHandlerDummy {
#[rustfmt::skip] #[rustfmt::skip]
#[allow(clippy::default_trait_access)] #[allow(clippy::default_trait_access)]
let resp = match req { 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::GetBlockCount(_) => JResp::GetBlockCount(Default::default()),
JReq::OnGetBlockHash(_) => JResp::OnGetBlockHash(Default::default()), JReq::OnGetBlockHash(_) => JResp::OnGetBlockHash(Default::default()),
JReq::SubmitBlock(_) => JResp::SubmitBlock(Default::default()), JReq::SubmitBlock(_) => JResp::SubmitBlock(Default::default()),
@ -93,7 +93,7 @@ impl Service<RpcRequest> for RpcHandlerDummy {
JReq::FlushCache(_) => JResp::FlushCache(Default::default()), JReq::FlushCache(_) => JResp::FlushCache(Default::default()),
JReq::AddAuxPow(_) => JResp::AddAuxPow(Default::default()), JReq::AddAuxPow(_) => JResp::AddAuxPow(Default::default()),
JReq::GetTxIdsLoose(_) => JResp::GetTxIdsLoose(Default::default()), JReq::GetTxIdsLoose(_) => JResp::GetTxIdsLoose(Default::default()),
})), }),
RpcRequest::Binary(b) => RpcResponse::Binary(match b { RpcRequest::Binary(b) => RpcResponse::Binary(match b {
BReq::GetBlocks(_) => BResp::GetBlocks(Default::default()), BReq::GetBlocks(_) => BResp::GetBlocks(Default::default()),
BReq::GetBlocksByHeight(_) => BResp::GetBlocksByHeight(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))] #[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
pub enum RpcRequest { pub enum RpcRequest {
/// JSON-RPC 2.0 requests. /// JSON-RPC 2.0 requests.
JsonRpc(cuprate_json_rpc::Request<JsonRpcRequest>), JsonRpc(JsonRpcRequest),
/// Binary requests. /// Binary requests.
Binary(BinRequest), Binary(BinRequest),
/// Other JSON requests. /// 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))] #[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
pub enum RpcResponse { pub enum RpcResponse {
/// JSON RPC 2.0 responses. /// JSON RPC 2.0 responses.
JsonRpc(cuprate_json_rpc::Response<JsonRpcResponse>), JsonRpc(JsonRpcResponse),
/// Binary responses. /// Binary responses.
Binary(BinResponse), Binary(BinResponse),
/// Other JSON responses. /// Other JSON responses.