diff --git a/binaries/cuprated/src/constants.rs b/binaries/cuprated/src/constants.rs index 2685f66..057e8bd 100644 --- a/binaries/cuprated/src/constants.rs +++ b/binaries/cuprated/src/constants.rs @@ -18,9 +18,6 @@ pub const VERSION_BUILD: &str = if cfg!(debug_assertions) { pub const PANIC_CRITICAL_SERVICE_ERROR: &str = "A service critical to Cuprate's function returned an unexpected error."; -/// The error message returned when an unsupported RPC call is requested. -pub const UNSUPPORTED_RPC_CALL: &str = "This RPC call is not supported by Cuprate."; - pub const EXAMPLE_CONFIG: &str = include_str!("../Cuprated.toml"); #[cfg(test)] diff --git a/binaries/cuprated/src/rpc.rs b/binaries/cuprated/src/rpc.rs index 71ca192..85832d3 100644 --- a/binaries/cuprated/src/rpc.rs +++ b/binaries/cuprated/src/rpc.rs @@ -2,13 +2,9 @@ //! //! Will contain the code to initiate the RPC and a request handler. -mod bin; mod constants; -mod handler; -mod helper; -mod json; -mod other; -mod request; -mod shared; +mod handlers; +mod rpc_handler; +mod service; -pub use handler::CupratedRpcHandler; +pub use rpc_handler::CupratedRpcHandler; diff --git a/binaries/cuprated/src/rpc/constants.rs b/binaries/cuprated/src/rpc/constants.rs index 1236269..834728d 100644 --- a/binaries/cuprated/src/rpc/constants.rs +++ b/binaries/cuprated/src/rpc/constants.rs @@ -3,3 +3,6 @@ /// The string message used in RPC response fields for when /// `cuprated` does not support a field that `monerod` has. pub(super) const FIELD_NOT_SUPPORTED: &str = "`cuprated` does not support this field."; + +/// The error message returned when an unsupported RPC call is requested. +pub(super) const UNSUPPORTED_RPC_CALL: &str = "This RPC call is not supported by Cuprate."; diff --git a/binaries/cuprated/src/rpc/handlers.rs b/binaries/cuprated/src/rpc/handlers.rs new file mode 100644 index 0000000..a5a415e --- /dev/null +++ b/binaries/cuprated/src/rpc/handlers.rs @@ -0,0 +1,18 @@ +//! RPC handler functions. +//! +//! These are the glue (async) functions that connect all the +//! internal `cuprated` functions and fulfill the request. +//! +//! - JSON-RPC handlers are in [`json_rpc`] +//! - Other JSON endpoint handlers are in [`other_json`] +//! - Other binary endpoint handlers are in [`bin`] +//! +//! - [`helper`] contains helper functions used by many handlers +//! - [`shared`] contains shared functions used by multiple handlers + +pub(super) mod bin; +pub(super) mod json_rpc; +pub(super) mod other_json; + +mod helper; +mod shared; diff --git a/binaries/cuprated/src/rpc/bin.rs b/binaries/cuprated/src/rpc/handlers/bin.rs similarity index 98% rename from binaries/cuprated/src/rpc/bin.rs rename to binaries/cuprated/src/rpc/handlers/bin.rs index b9277c2..8ce8248 100644 --- a/binaries/cuprated/src/rpc/bin.rs +++ b/binaries/cuprated/src/rpc/handlers/bin.rs @@ -26,13 +26,13 @@ use cuprate_types::{ }; use crate::rpc::{ - helper, - request::{blockchain, txpool}, - shared, CupratedRpcHandler, + handlers::{helper, shared}, + service::{blockchain, txpool}, + CupratedRpcHandler, }; /// Map a [`BinRequest`] to the function that will lead to a [`BinResponse`]. -pub(super) async fn map_request( +pub async fn map_request( state: CupratedRpcHandler, request: BinRequest, ) -> Result { diff --git a/binaries/cuprated/src/rpc/helper.rs b/binaries/cuprated/src/rpc/handlers/helper.rs similarity index 97% rename from binaries/cuprated/src/rpc/helper.rs rename to binaries/cuprated/src/rpc/handlers/helper.rs index cad3382..1ddd076 100644 --- a/binaries/cuprated/src/rpc/helper.rs +++ b/binaries/cuprated/src/rpc/handlers/helper.rs @@ -3,7 +3,7 @@ //! Many of the handlers have bodies with only small differences, //! the identical code is extracted and reused here in these functions. //! -//! These build on-top of [`crate::rpc::request`] functions. +//! These build on-top of [`crate::rpc::service`] functions. use anyhow::{anyhow, Error}; @@ -17,9 +17,9 @@ use cuprate_rpc_types::{ }; use cuprate_types::HardFork; -use crate::{ - rpc::request::{blockchain, blockchain_context}, - rpc::CupratedRpcHandler, +use crate::rpc::{ + service::{blockchain, blockchain_context}, + CupratedRpcHandler, }; /// Map some data into a [`BlockHeader`]. diff --git a/binaries/cuprated/src/rpc/json.rs b/binaries/cuprated/src/rpc/handlers/json_rpc.rs similarity index 99% rename from binaries/cuprated/src/rpc/json.rs rename to binaries/cuprated/src/rpc/handlers/json_rpc.rs index 03b7c0b..cb6da7f 100644 --- a/binaries/cuprated/src/rpc/json.rs +++ b/binaries/cuprated/src/rpc/handlers/json_rpc.rs @@ -58,19 +58,18 @@ use cuprate_types::{ }; use crate::{ - constants::{UNSUPPORTED_RPC_CALL, VERSION_BUILD}, + constants::VERSION_BUILD, rpc::{ - helper, - request::{address_book, blockchain, blockchain_context, blockchain_manager, txpool}, - shared, CupratedRpcHandler, + constants::{FIELD_NOT_SUPPORTED, UNSUPPORTED_RPC_CALL}, + handlers::{helper, shared}, + service::{address_book, blockchain, blockchain_context, blockchain_manager, txpool}, + CupratedRpcHandler, }, statics::START_INSTANT_UNIX, }; -use super::constants::FIELD_NOT_SUPPORTED; - /// Map a [`JsonRpcRequest`] to the function that will lead to a [`JsonRpcResponse`]. -pub(super) async fn map_request( +pub async fn map_request( state: CupratedRpcHandler, request: JsonRpcRequest, ) -> Result { diff --git a/binaries/cuprated/src/rpc/other.rs b/binaries/cuprated/src/rpc/handlers/other_json.rs similarity index 99% rename from binaries/cuprated/src/rpc/other.rs rename to binaries/cuprated/src/rpc/handlers/other_json.rs index 45a279c..38cc1ea 100644 --- a/binaries/cuprated/src/rpc/other.rs +++ b/binaries/cuprated/src/rpc/handlers/other_json.rs @@ -43,19 +43,17 @@ use cuprate_types::{ use monero_serai::transaction::{Input, Timelock, Transaction}; use crate::{ - constants::UNSUPPORTED_RPC_CALL, rpc::{ - helper, - request::{blockchain, blockchain_context, blockchain_manager, txpool}, - shared, CupratedRpcHandler, + constants::UNSUPPORTED_RPC_CALL, + handlers::{helper, shared}, + service::{address_book, blockchain, blockchain_context, blockchain_manager, txpool}, + CupratedRpcHandler, }, statics::START_INSTANT_UNIX, }; -use super::request::address_book; - /// Map a [`OtherRequest`] to the function that will lead to a [`OtherResponse`]. -pub(super) async fn map_request( +pub async fn map_request( state: CupratedRpcHandler, request: OtherRequest, ) -> Result { diff --git a/binaries/cuprated/src/rpc/shared.rs b/binaries/cuprated/src/rpc/handlers/shared.rs similarity index 98% rename from binaries/cuprated/src/rpc/shared.rs rename to binaries/cuprated/src/rpc/handlers/shared.rs index 6db30b8..81c6f72 100644 --- a/binaries/cuprated/src/rpc/shared.rs +++ b/binaries/cuprated/src/rpc/handlers/shared.rs @@ -23,8 +23,8 @@ use cuprate_rpc_types::{ }; use crate::rpc::{ - helper, - request::{blockchain, txpool}, + handlers::helper, + service::{blockchain, txpool}, CupratedRpcHandler, }; diff --git a/binaries/cuprated/src/rpc/handler.rs b/binaries/cuprated/src/rpc/rpc_handler.rs similarity index 96% rename from binaries/cuprated/src/rpc/handler.rs rename to binaries/cuprated/src/rpc/rpc_handler.rs index d52976f..23bf848 100644 --- a/binaries/cuprated/src/rpc/handler.rs +++ b/binaries/cuprated/src/rpc/rpc_handler.rs @@ -19,7 +19,7 @@ use cuprate_rpc_types::{ }; use cuprate_txpool::service::TxpoolReadHandle; -use crate::rpc::{bin, json, other}; +use crate::rpc::handlers; /// TODO: use real type when public. #[derive(Clone)] @@ -217,7 +217,7 @@ impl Service for CupratedRpcHandler { fn call(&mut self, request: JsonRpcRequest) -> Self::Future { let state = self.clone(); - Box::pin(json::map_request(state, request)) + Box::pin(handlers::json_rpc::map_request(state, request)) } } @@ -232,7 +232,7 @@ impl Service for CupratedRpcHandler { fn call(&mut self, request: BinRequest) -> Self::Future { let state = self.clone(); - Box::pin(bin::map_request(state, request)) + Box::pin(handlers::bin::map_request(state, request)) } } @@ -247,6 +247,6 @@ impl Service for CupratedRpcHandler { fn call(&mut self, request: OtherRequest) -> Self::Future { let state = self.clone(); - Box::pin(other::map_request(state, request)) + Box::pin(handlers::other_json::map_request(state, request)) } } diff --git a/binaries/cuprated/src/rpc/request.rs b/binaries/cuprated/src/rpc/service.rs similarity index 88% rename from binaries/cuprated/src/rpc/request.rs rename to binaries/cuprated/src/rpc/service.rs index d1d9a21..c85df33 100644 --- a/binaries/cuprated/src/rpc/request.rs +++ b/binaries/cuprated/src/rpc/service.rs @@ -1,4 +1,4 @@ -//! Convenience functions for requests/responses. +//! Convenience functions for Cuprate's various [`tower::Service`] requests/responses. //! //! This module implements many methods for //! [`CupratedRpcHandler`](crate::rpc::CupratedRpcHandler) diff --git a/binaries/cuprated/src/rpc/request/address_book.rs b/binaries/cuprated/src/rpc/service/address_book.rs similarity index 94% rename from binaries/cuprated/src/rpc/request/address_book.rs rename to binaries/cuprated/src/rpc/service/address_book.rs index 77841df..c38fc7e 100644 --- a/binaries/cuprated/src/rpc/request/address_book.rs +++ b/binaries/cuprated/src/rpc/service/address_book.rs @@ -17,7 +17,7 @@ use cuprate_rpc_types::misc::ConnectionInfo; // FIXME: use `anyhow::Error` over `tower::BoxError` in address book. /// [`AddressBookRequest::PeerlistSize`] -pub(crate) async fn peerlist_size( +pub async fn peerlist_size( address_book: &mut impl AddressBook, ) -> Result<(u64, u64), Error> { let AddressBookResponse::PeerlistSize { white, grey } = address_book @@ -35,7 +35,7 @@ pub(crate) async fn peerlist_size( } /// [`AddressBookRequest::ConnectionInfo`] -pub(crate) async fn connection_info( +pub async fn connection_info( address_book: &mut impl AddressBook, ) -> Result, Error> { let AddressBookResponse::ConnectionInfo(vec) = address_book @@ -92,7 +92,7 @@ pub(crate) async fn connection_info( } /// [`AddressBookRequest::ConnectionCount`] -pub(crate) async fn connection_count( +pub async fn connection_count( address_book: &mut impl AddressBook, ) -> Result<(u64, u64), Error> { let AddressBookResponse::ConnectionCount { incoming, outgoing } = address_book @@ -110,7 +110,7 @@ pub(crate) async fn connection_count( } /// [`AddressBookRequest::SetBan`] -pub(crate) async fn set_ban( +pub async fn set_ban( address_book: &mut impl AddressBook, set_ban: cuprate_p2p_core::types::SetBan, ) -> Result<(), Error> { @@ -129,7 +129,7 @@ pub(crate) async fn set_ban( } /// [`AddressBookRequest::GetBan`] -pub(crate) async fn get_ban( +pub async fn get_ban( address_book: &mut impl AddressBook, peer: Z::Addr, ) -> Result, Error> { @@ -148,7 +148,7 @@ pub(crate) async fn get_ban( } /// [`AddressBookRequest::GetBans`] -pub(crate) async fn get_bans( +pub async fn get_bans( address_book: &mut impl AddressBook, ) -> Result>, Error> { let AddressBookResponse::GetBans(bans) = address_book @@ -166,7 +166,7 @@ pub(crate) async fn get_bans( } /// [`AddressBookRequest::Peerlist`] -pub(crate) async fn peerlist( +pub async fn peerlist( address_book: &mut impl AddressBook, ) -> Result<(Vec, Vec), Error> { let AddressBookResponse::Peerlist(peerlist) = address_book diff --git a/binaries/cuprated/src/rpc/request/blockchain.rs b/binaries/cuprated/src/rpc/service/blockchain.rs similarity index 90% rename from binaries/cuprated/src/rpc/request/blockchain.rs rename to binaries/cuprated/src/rpc/service/blockchain.rs index 3e37a48..46d8415 100644 --- a/binaries/cuprated/src/rpc/request/blockchain.rs +++ b/binaries/cuprated/src/rpc/service/blockchain.rs @@ -22,7 +22,7 @@ use cuprate_types::{ }; /// [`BlockchainReadRequest::Block`]. -pub(crate) async fn block( +pub async fn block( blockchain_read: &mut BlockchainReadHandle, height: u64, ) -> Result { @@ -41,7 +41,7 @@ pub(crate) async fn block( } /// [`BlockchainReadRequest::BlockByHash`]. -pub(crate) async fn block_by_hash( +pub async fn block_by_hash( blockchain_read: &mut BlockchainReadHandle, hash: [u8; 32], ) -> Result { @@ -58,7 +58,7 @@ pub(crate) async fn block_by_hash( } /// [`BlockchainReadRequest::BlockExtendedHeader`]. -pub(crate) async fn block_extended_header( +pub async fn block_extended_header( blockchain_read: &mut BlockchainReadHandle, height: u64, ) -> Result { @@ -77,7 +77,7 @@ pub(crate) async fn block_extended_header( } /// [`BlockchainReadRequest::BlockHash`]. -pub(crate) async fn block_hash( +pub async fn block_hash( blockchain_read: &mut BlockchainReadHandle, height: u64, chain: Chain, @@ -98,7 +98,7 @@ pub(crate) async fn block_hash( } /// [`BlockchainReadRequest::FindBlock`]. -pub(crate) async fn find_block( +pub async fn find_block( blockchain_read: &mut BlockchainReadHandle, block_hash: [u8; 32], ) -> Result, Error> { @@ -115,7 +115,7 @@ pub(crate) async fn find_block( } /// [`BlockchainReadRequest::FilterUnknownHashes`]. -pub(crate) async fn filter_unknown_hashes( +pub async fn filter_unknown_hashes( blockchain_read: &mut BlockchainReadHandle, block_hashes: HashSet<[u8; 32]>, ) -> Result, Error> { @@ -132,7 +132,7 @@ pub(crate) async fn filter_unknown_hashes( } /// [`BlockchainReadRequest::BlockExtendedHeaderInRange`] -pub(crate) async fn block_extended_header_in_range( +pub async fn block_extended_header_in_range( blockchain_read: &mut BlockchainReadHandle, range: Range, chain: Chain, @@ -152,7 +152,7 @@ pub(crate) async fn block_extended_header_in_range( } /// [`BlockchainReadRequest::ChainHeight`]. -pub(crate) async fn chain_height( +pub async fn chain_height( blockchain_read: &mut BlockchainReadHandle, ) -> Result<(u64, [u8; 32]), Error> { let BlockchainResponse::ChainHeight(height, hash) = blockchain_read @@ -168,7 +168,7 @@ pub(crate) async fn chain_height( } /// [`BlockchainReadRequest::GeneratedCoins`]. -pub(crate) async fn generated_coins( +pub async fn generated_coins( blockchain_read: &mut BlockchainReadHandle, block_height: u64, ) -> Result { @@ -187,7 +187,7 @@ pub(crate) async fn generated_coins( } /// [`BlockchainReadRequest::Outputs`] -pub(crate) async fn outputs( +pub async fn outputs( blockchain_read: &mut BlockchainReadHandle, outputs: HashMap>, ) -> Result>, Error> { @@ -204,7 +204,7 @@ pub(crate) async fn outputs( } /// [`BlockchainReadRequest::NumberOutputsWithAmount`] -pub(crate) async fn number_outputs_with_amount( +pub async fn number_outputs_with_amount( blockchain_read: &mut BlockchainReadHandle, output_amounts: Vec, ) -> Result, Error> { @@ -223,7 +223,7 @@ pub(crate) async fn number_outputs_with_amount( } /// [`BlockchainReadRequest::KeyImagesSpent`] -pub(crate) async fn key_images_spent( +pub async fn key_images_spent( blockchain_read: &mut BlockchainReadHandle, key_images: Vec<[u8; 32]>, ) -> Result, Error> { @@ -240,7 +240,7 @@ pub(crate) async fn key_images_spent( } /// [`BlockchainReadRequest::CompactChainHistory`] -pub(crate) async fn compact_chain_history( +pub async fn compact_chain_history( blockchain_read: &mut BlockchainReadHandle, ) -> Result<(Vec<[u8; 32]>, u128), Error> { let BlockchainResponse::CompactChainHistory { @@ -259,7 +259,7 @@ pub(crate) async fn compact_chain_history( } /// [`BlockchainReadRequest::FindFirstUnknown`] -pub(crate) async fn find_first_unknown( +pub async fn find_first_unknown( blockchain_read: &mut BlockchainReadHandle, hashes: Vec<[u8; 32]>, ) -> Result, Error> { @@ -276,9 +276,7 @@ pub(crate) async fn find_first_unknown( } /// [`BlockchainReadRequest::TotalTxCount`] -pub(crate) async fn total_tx_count( - blockchain_read: &mut BlockchainReadHandle, -) -> Result { +pub async fn total_tx_count(blockchain_read: &mut BlockchainReadHandle) -> Result { let BlockchainResponse::TotalTxCount(tx_count) = blockchain_read .ready() .await? @@ -292,7 +290,7 @@ pub(crate) async fn total_tx_count( } /// [`BlockchainReadRequest::DatabaseSize`] -pub(crate) async fn database_size( +pub async fn database_size( blockchain_read: &mut BlockchainReadHandle, ) -> Result<(u64, u64), Error> { let BlockchainResponse::DatabaseSize { @@ -311,7 +309,7 @@ pub(crate) async fn database_size( } /// [`BlockchainReadRequest::OutputDistribution`] -pub(crate) async fn output_distribution( +pub async fn output_distribution( blockchain_read: &mut BlockchainReadHandle, input: OutputDistributionInput, ) -> Result, Error> { @@ -328,7 +326,7 @@ pub(crate) async fn output_distribution( } /// [`BlockchainReadRequest::OutputHistogram`] -pub(crate) async fn output_histogram( +pub async fn output_histogram( blockchain_read: &mut BlockchainReadHandle, input: OutputHistogramInput, ) -> Result, Error> { @@ -345,7 +343,7 @@ pub(crate) async fn output_histogram( } /// [`BlockchainReadRequest::CoinbaseTxSum`] -pub(crate) async fn coinbase_tx_sum( +pub async fn coinbase_tx_sum( blockchain_read: &mut BlockchainReadHandle, height: u64, count: u64, @@ -366,7 +364,7 @@ pub(crate) async fn coinbase_tx_sum( } /// [`BlockchainReadRequest::AltChains`] -pub(crate) async fn alt_chains( +pub async fn alt_chains( blockchain_read: &mut BlockchainReadHandle, ) -> Result, Error> { let BlockchainResponse::AltChains(vec) = blockchain_read @@ -382,9 +380,7 @@ pub(crate) async fn alt_chains( } /// [`BlockchainReadRequest::AltChainCount`] -pub(crate) async fn alt_chain_count( - blockchain_read: &mut BlockchainReadHandle, -) -> Result { +pub async fn alt_chain_count(blockchain_read: &mut BlockchainReadHandle) -> Result { let BlockchainResponse::AltChainCount(count) = blockchain_read .ready() .await? @@ -398,7 +394,7 @@ pub(crate) async fn alt_chain_count( } /// [`BlockchainReadRequest::Transactions`]. -pub(crate) async fn transactions( +pub async fn transactions( blockchain_read: &mut BlockchainReadHandle, tx_hashes: HashSet<[u8; 32]>, ) -> Result<(Vec, Vec<[u8; 32]>), Error> { @@ -415,9 +411,7 @@ pub(crate) async fn transactions( } /// [`BlockchainReadRequest::TotalRctOutputs`]. -pub(crate) async fn total_rct_outputs( - blockchain_read: &mut BlockchainReadHandle, -) -> Result { +pub async fn total_rct_outputs(blockchain_read: &mut BlockchainReadHandle) -> Result { let BlockchainResponse::TotalRctOutputs(n) = blockchain_read .ready() .await? @@ -431,7 +425,7 @@ pub(crate) async fn total_rct_outputs( } /// [`BlockchainReadRequest::BlockCompleteEntries`]. -pub(crate) async fn block_complete_entries( +pub async fn block_complete_entries( blockchain_read: &mut BlockchainReadHandle, block_hashes: Vec<[u8; 32]>, ) -> Result<(Vec, Vec<[u8; 32]>, usize), Error> { @@ -452,7 +446,7 @@ pub(crate) async fn block_complete_entries( } /// [`BlockchainReadRequest::BlockCompleteEntriesByHeight`]. -pub(crate) async fn block_complete_entries_by_height( +pub async fn block_complete_entries_by_height( blockchain_read: &mut BlockchainReadHandle, block_heights: Vec, ) -> Result, Error> { @@ -471,7 +465,7 @@ pub(crate) async fn block_complete_entries_by_height( } /// [`BlockchainReadRequest::TxOutputIndexes`]. -pub(crate) async fn tx_output_indexes( +pub async fn tx_output_indexes( blockchain_read: &mut BlockchainReadHandle, tx_hash: [u8; 32], ) -> Result, Error> { diff --git a/binaries/cuprated/src/rpc/request/blockchain_context.rs b/binaries/cuprated/src/rpc/service/blockchain_context.rs similarity index 95% rename from binaries/cuprated/src/rpc/request/blockchain_context.rs rename to binaries/cuprated/src/rpc/service/blockchain_context.rs index f2fc97f..77cc019 100644 --- a/binaries/cuprated/src/rpc/request/blockchain_context.rs +++ b/binaries/cuprated/src/rpc/service/blockchain_context.rs @@ -16,7 +16,7 @@ use cuprate_types::{ // FIXME: use `anyhow::Error` over `tower::BoxError` in blockchain context. /// [`BlockChainContextRequest::Context`]. -pub(crate) async fn context( +pub async fn context( blockchain_context: &mut BlockChainContextService, ) -> Result { let BlockChainContextResponse::Context(context) = blockchain_context @@ -34,7 +34,7 @@ pub(crate) async fn context( } /// [`BlockChainContextRequest::HardForkInfo`]. -pub(crate) async fn hard_fork_info( +pub async fn hard_fork_info( blockchain_context: &mut BlockChainContextService, hard_fork: HardFork, ) -> Result { @@ -53,7 +53,7 @@ pub(crate) async fn hard_fork_info( } /// [`BlockChainContextRequest::FeeEstimate`]. -pub(crate) async fn fee_estimate( +pub async fn fee_estimate( blockchain_context: &mut BlockChainContextService, grace_blocks: u64, ) -> Result { @@ -72,7 +72,7 @@ pub(crate) async fn fee_estimate( } /// [`BlockChainContextRequest::CalculatePow`] -pub(crate) async fn calculate_pow( +pub async fn calculate_pow( blockchain_context: &mut BlockChainContextService, hardfork: HardFork, block: Block, @@ -104,7 +104,7 @@ pub(crate) async fn calculate_pow( } /// [`BlockChainContextRequest::BatchGetDifficulties`] -pub(crate) async fn batch_get_difficulties( +pub async fn batch_get_difficulties( blockchain_context: &mut BlockChainContextService, difficulties: Vec<(u64, HardFork)>, ) -> Result, Error> { diff --git a/binaries/cuprated/src/rpc/request/blockchain_manager.rs b/binaries/cuprated/src/rpc/service/blockchain_manager.rs similarity index 85% rename from binaries/cuprated/src/rpc/request/blockchain_manager.rs rename to binaries/cuprated/src/rpc/service/blockchain_manager.rs index 0e7d3c2..fa10279 100644 --- a/binaries/cuprated/src/rpc/request/blockchain_manager.rs +++ b/binaries/cuprated/src/rpc/service/blockchain_manager.rs @@ -10,12 +10,12 @@ use cuprate_p2p_core::{types::ConnectionId, NetworkZone}; use cuprate_pruning::PruningSeed; use cuprate_rpc_types::misc::Span; -use crate::rpc::handler::{ +use crate::rpc::rpc_handler::{ BlockchainManagerHandle, BlockchainManagerRequest, BlockchainManagerResponse, }; /// [`BlockchainManagerRequest::PopBlocks`] -pub(crate) async fn pop_blocks( +pub async fn pop_blocks( blockchain_manager: &mut BlockchainManagerHandle, amount: u64, ) -> Result { @@ -34,9 +34,7 @@ pub(crate) async fn pop_blocks( } /// [`BlockchainManagerRequest::Prune`] -pub(crate) async fn prune( - blockchain_manager: &mut BlockchainManagerHandle, -) -> Result { +pub async fn prune(blockchain_manager: &mut BlockchainManagerHandle) -> Result { let BlockchainManagerResponse::Prune(seed) = blockchain_manager .ready() .await? @@ -50,9 +48,7 @@ pub(crate) async fn prune( } /// [`BlockchainManagerRequest::Pruned`] -pub(crate) async fn pruned( - blockchain_manager: &mut BlockchainManagerHandle, -) -> Result { +pub async fn pruned(blockchain_manager: &mut BlockchainManagerHandle) -> Result { let BlockchainManagerResponse::Pruned(pruned) = blockchain_manager .ready() .await? @@ -66,7 +62,7 @@ pub(crate) async fn pruned( } /// [`BlockchainManagerRequest::RelayBlock`] -pub(crate) async fn relay_block( +pub async fn relay_block( blockchain_manager: &mut BlockchainManagerHandle, block: Box, ) -> Result<(), Error> { @@ -83,9 +79,7 @@ pub(crate) async fn relay_block( } /// [`BlockchainManagerRequest::Syncing`] -pub(crate) async fn syncing( - blockchain_manager: &mut BlockchainManagerHandle, -) -> Result { +pub async fn syncing(blockchain_manager: &mut BlockchainManagerHandle) -> Result { let BlockchainManagerResponse::Syncing(syncing) = blockchain_manager .ready() .await? @@ -99,9 +93,7 @@ pub(crate) async fn syncing( } /// [`BlockchainManagerRequest::Synced`] -pub(crate) async fn synced( - blockchain_manager: &mut BlockchainManagerHandle, -) -> Result { +pub async fn synced(blockchain_manager: &mut BlockchainManagerHandle) -> Result { let BlockchainManagerResponse::Synced(syncing) = blockchain_manager .ready() .await? @@ -115,7 +107,7 @@ pub(crate) async fn synced( } /// [`BlockchainManagerRequest::Target`] -pub(crate) async fn target( +pub async fn target( blockchain_manager: &mut BlockchainManagerHandle, ) -> Result { let BlockchainManagerResponse::Target(target) = blockchain_manager @@ -131,9 +123,7 @@ pub(crate) async fn target( } /// [`BlockchainManagerRequest::TargetHeight`] -pub(crate) async fn target_height( - blockchain_manager: &mut BlockchainManagerHandle, -) -> Result { +pub async fn target_height(blockchain_manager: &mut BlockchainManagerHandle) -> Result { let BlockchainManagerResponse::TargetHeight { height } = blockchain_manager .ready() .await? @@ -147,7 +137,7 @@ pub(crate) async fn target_height( } /// [`BlockchainManagerRequest::GenerateBlocks`] -pub(crate) async fn generate_blocks( +pub async fn generate_blocks( blockchain_manager: &mut BlockchainManagerHandle, amount_of_blocks: u64, prev_block: Option<[u8; 32]>, @@ -172,7 +162,7 @@ pub(crate) async fn generate_blocks( } // [`BlockchainManagerRequest::Spans`] -pub(crate) async fn spans( +pub async fn spans( blockchain_manager: &mut BlockchainManagerHandle, ) -> Result, Error> { // let BlockchainManagerResponse::Spans(vec) = blockchain_manager @@ -205,7 +195,7 @@ pub(crate) async fn spans( } /// [`BlockchainManagerRequest::NextNeededPruningSeed`] -pub(crate) async fn next_needed_pruning_seed( +pub async fn next_needed_pruning_seed( blockchain_manager: &mut BlockchainManagerHandle, ) -> Result { let BlockchainManagerResponse::NextNeededPruningSeed(seed) = blockchain_manager @@ -221,7 +211,7 @@ pub(crate) async fn next_needed_pruning_seed( } /// [`BlockchainManagerRequest::CreateBlockTemplate`] -pub(crate) async fn create_block_template( +pub async fn create_block_template( blockchain_manager: &mut BlockchainManagerHandle, prev_block: [u8; 32], account_public_address: String, @@ -244,7 +234,7 @@ pub(crate) async fn create_block_template( } /// [`BlockchainManagerRequest::Sync`] -pub(crate) async fn sync(blockchain_manager: &mut BlockchainManagerHandle) -> Result<(), Error> { +pub async fn sync(blockchain_manager: &mut BlockchainManagerHandle) -> Result<(), Error> { let BlockchainManagerResponse::Ok = blockchain_manager .ready() .await? @@ -258,7 +248,7 @@ pub(crate) async fn sync(blockchain_manager: &mut BlockchainManagerHandle) -> Re } /// [`BlockchainManagerRequest::Stop`] -pub(crate) async fn stop(blockchain_manager: &mut BlockchainManagerHandle) -> Result<(), Error> { +pub async fn stop(blockchain_manager: &mut BlockchainManagerHandle) -> Result<(), Error> { let BlockchainManagerResponse::Ok = blockchain_manager .ready() .await? diff --git a/binaries/cuprated/src/rpc/request/txpool.rs b/binaries/cuprated/src/rpc/service/txpool.rs similarity index 88% rename from binaries/cuprated/src/rpc/request/txpool.rs rename to binaries/cuprated/src/rpc/service/txpool.rs index 007660b..e77f89b 100644 --- a/binaries/cuprated/src/rpc/request/txpool.rs +++ b/binaries/cuprated/src/rpc/service/txpool.rs @@ -23,7 +23,7 @@ use cuprate_types::{ // FIXME: use `anyhow::Error` over `tower::BoxError` in txpool. /// [`TxpoolReadRequest::Backlog`] -pub(crate) async fn backlog(txpool_read: &mut TxpoolReadHandle) -> Result, Error> { +pub async fn backlog(txpool_read: &mut TxpoolReadHandle) -> Result, Error> { let TxpoolReadResponse::Backlog(tx_entries) = txpool_read .ready() .await @@ -39,7 +39,7 @@ pub(crate) async fn backlog(txpool_read: &mut TxpoolReadHandle) -> Result Result { @@ -60,7 +60,7 @@ pub(crate) async fn size( } /// TODO -pub(crate) async fn pool_info( +pub async fn pool_info( txpool_read: &mut TxpoolReadHandle, include_sensitive_txs: bool, max_tx_count: usize, @@ -85,7 +85,7 @@ pub(crate) async fn pool_info( } /// TODO -pub(crate) async fn txs_by_hash( +pub async fn txs_by_hash( txpool_read: &mut TxpoolReadHandle, tx_hashes: Vec<[u8; 32]>, include_sensitive_txs: bool, @@ -108,7 +108,7 @@ pub(crate) async fn txs_by_hash( } /// TODO -pub(crate) async fn key_images_spent( +pub async fn key_images_spent( txpool_read: &mut TxpoolReadHandle, key_images: Vec<[u8; 32]>, include_sensitive_txs: bool, @@ -131,7 +131,7 @@ pub(crate) async fn key_images_spent( } /// TODO -pub(crate) async fn pool( +pub async fn pool( txpool_read: &mut TxpoolReadHandle, include_sensitive_txs: bool, ) -> Result<(Vec, Vec), Error> { @@ -158,7 +158,7 @@ pub(crate) async fn pool( } /// TODO -pub(crate) async fn pool_stats( +pub async fn pool_stats( txpool_read: &mut TxpoolReadHandle, include_sensitive_txs: bool, ) -> Result { @@ -179,25 +179,19 @@ pub(crate) async fn pool_stats( } /// TODO -pub(crate) async fn flush( - txpool_manager: &mut Infallible, - tx_hashes: Vec<[u8; 32]>, -) -> Result<(), Error> { +pub async fn flush(txpool_manager: &mut Infallible, tx_hashes: Vec<[u8; 32]>) -> Result<(), Error> { todo!(); Ok(()) } /// TODO -pub(crate) async fn relay( - txpool_manager: &mut Infallible, - tx_hashes: Vec<[u8; 32]>, -) -> Result<(), Error> { +pub async fn relay(txpool_manager: &mut Infallible, tx_hashes: Vec<[u8; 32]>) -> Result<(), Error> { todo!(); Ok(()) } /// TODO -pub(crate) async fn check_maybe_relay_local( +pub async fn check_maybe_relay_local( txpool_manager: &mut Infallible, tx: Transaction, relay: bool, diff --git a/rpc/interface/src/route/mod.rs b/rpc/interface/src/route/mod.rs index 7ff9ab8..76fbdfc 100644 --- a/rpc/interface/src/route/mod.rs +++ b/rpc/interface/src/route/mod.rs @@ -6,4 +6,4 @@ pub(crate) mod bin; pub(crate) mod fallback; pub(crate) mod json_rpc; -pub(crate) mod other; +pub(crate) mod other_json; diff --git a/rpc/interface/src/route/other.rs b/rpc/interface/src/route/other_json.rs similarity index 100% rename from rpc/interface/src/route/other.rs rename to rpc/interface/src/route/other_json.rs diff --git a/rpc/interface/src/router_builder.rs b/rpc/interface/src/router_builder.rs index d18a694..a7a14a8 100644 --- a/rpc/interface/src/router_builder.rs +++ b/rpc/interface/src/router_builder.rs @@ -4,7 +4,7 @@ use axum::Router; use crate::{ - route::{bin, fallback, json_rpc, other}, + route::{bin, fallback, json_rpc, other_json}, rpc_handler::RpcHandler, }; @@ -140,36 +140,36 @@ generate_router_builder! { json_rpc => "/json_rpc" => json_rpc::json_rpc => (get, post), // Other JSON routes. - other_get_height => "/get_height" => other::get_height => (get, post), - other_getheight => "/getheight" => other::get_height => (get, post), - other_get_transactions => "/get_transactions" => other::get_transactions => (get, post), - other_gettransactions => "/gettransactions" => other::get_transactions => (get, post), - other_get_alt_blocks_hashes => "/get_alt_blocks_hashes" => other::get_alt_blocks_hashes => (get, post), - other_is_key_image_spent => "/is_key_image_spent" => other::is_key_image_spent => (get, post), - other_send_raw_transaction => "/send_raw_transaction" => other::send_raw_transaction => (get, post), - other_sendrawtransaction => "/sendrawtransaction" => other::send_raw_transaction => (get, post), - other_start_mining => "/start_mining" => other::start_mining => (get, post), - other_stop_mining => "/stop_mining" => other::stop_mining => (get, post), - other_mining_status => "/mining_status" => other::mining_status => (get, post), - other_save_bc => "/save_bc" => other::save_bc => (get, post), - other_get_peer_list => "/get_peer_list" => other::get_peer_list => (get, post), - other_get_public_nodes => "/get_public_nodes" => other::get_public_nodes => (get, post), - other_set_log_hash_rate => "/set_log_hash_rate" => other::set_log_hash_rate => (get, post), - other_set_log_level => "/set_log_level" => other::set_log_level => (get, post), - other_set_log_categories => "/set_log_categories" => other::set_log_categories => (get, post), - other_get_transaction_pool => "/get_transaction_pool" => other::get_transaction_pool => (get, post), - other_get_transaction_pool_hashes => "/get_transaction_pool_hashes" => other::get_transaction_pool_hashes => (get, post), - other_get_transaction_pool_stats => "/get_transaction_pool_stats" => other::get_transaction_pool_stats => (get, post), - other_set_bootstrap_daemon => "/set_bootstrap_daemon" => other::set_bootstrap_daemon => (get, post), - other_stop_daemon => "/stop_daemon" => other::stop_daemon => (get, post), - other_get_net_stats => "/get_net_stats" => other::get_net_stats => (get, post), - other_get_limit => "/get_limit" => other::get_limit => (get, post), - other_set_limit => "/set_limit" => other::set_limit => (get, post), - other_out_peers => "/out_peers" => other::out_peers => (get, post), - other_in_peers => "/in_peers" => other::in_peers => (get, post), - other_get_outs => "/get_outs" => other::get_outs => (get, post), - other_update => "/update" => other::update => (get, post), - other_pop_blocks => "/pop_blocks" => other::pop_blocks => (get, post), + other_get_height => "/get_height" => other_json::get_height => (get, post), + other_getheight => "/getheight" => other_json::get_height => (get, post), + other_get_transactions => "/get_transactions" => other_json::get_transactions => (get, post), + other_gettransactions => "/gettransactions" => other_json::get_transactions => (get, post), + other_get_alt_blocks_hashes => "/get_alt_blocks_hashes" => other_json::get_alt_blocks_hashes => (get, post), + other_is_key_image_spent => "/is_key_image_spent" => other_json::is_key_image_spent => (get, post), + other_send_raw_transaction => "/send_raw_transaction" => other_json::send_raw_transaction => (get, post), + other_sendrawtransaction => "/sendrawtransaction" => other_json::send_raw_transaction => (get, post), + other_start_mining => "/start_mining" => other_json::start_mining => (get, post), + other_stop_mining => "/stop_mining" => other_json::stop_mining => (get, post), + other_mining_status => "/mining_status" => other_json::mining_status => (get, post), + other_save_bc => "/save_bc" => other_json::save_bc => (get, post), + other_get_peer_list => "/get_peer_list" => other_json::get_peer_list => (get, post), + other_get_public_nodes => "/get_public_nodes" => other_json::get_public_nodes => (get, post), + other_set_log_hash_rate => "/set_log_hash_rate" => other_json::set_log_hash_rate => (get, post), + other_set_log_level => "/set_log_level" => other_json::set_log_level => (get, post), + other_set_log_categories => "/set_log_categories" => other_json::set_log_categories => (get, post), + other_get_transaction_pool => "/get_transaction_pool" => other_json::get_transaction_pool => (get, post), + other_get_transaction_pool_hashes => "/get_transaction_pool_hashes" => other_json::get_transaction_pool_hashes => (get, post), + other_get_transaction_pool_stats => "/get_transaction_pool_stats" => other_json::get_transaction_pool_stats => (get, post), + other_set_bootstrap_daemon => "/set_bootstrap_daemon" => other_json::set_bootstrap_daemon => (get, post), + other_stop_daemon => "/stop_daemon" => other_json::stop_daemon => (get, post), + other_get_net_stats => "/get_net_stats" => other_json::get_net_stats => (get, post), + other_get_limit => "/get_limit" => other_json::get_limit => (get, post), + other_set_limit => "/set_limit" => other_json::set_limit => (get, post), + other_out_peers => "/out_peers" => other_json::out_peers => (get, post), + other_in_peers => "/in_peers" => other_json::in_peers => (get, post), + other_get_outs => "/get_outs" => other_json::get_outs => (get, post), + other_update => "/update" => other_json::update => (get, post), + other_pop_blocks => "/pop_blocks" => other_json::pop_blocks => (get, post), // Binary routes. bin_get_blocks => "/get_blocks.bin" => bin::get_blocks => (get, post),