diff --git a/Cargo.lock b/Cargo.lock index 3ca5d6af..0bb4612a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -56,6 +56,12 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b" +[[package]] +name = "anyhow" +version = "1.0.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10f00e1f6e58a40e807377c75c6a7f97bf9044fab57816f2414e6f5f4499d7b8" + [[package]] name = "async-stream" version = "0.3.5" @@ -799,6 +805,7 @@ dependencies = [ name = "cuprate-rpc-interface" version = "0.0.0" dependencies = [ + "anyhow", "axum", "cuprate-epee-encoding", "cuprate-helper", @@ -809,7 +816,6 @@ dependencies = [ "paste", "serde", "serde_json", - "thiserror", "tokio", "tower", "ureq", @@ -910,6 +916,7 @@ dependencies = [ name = "cuprated" version = "0.1.0" dependencies = [ + "anyhow", "async-trait", "bitflags 2.5.0", "borsh", diff --git a/binaries/cuprated/Cargo.toml b/binaries/cuprated/Cargo.toml index 63a04317..a886c124 100644 --- a/binaries/cuprated/Cargo.toml +++ b/binaries/cuprated/Cargo.toml @@ -35,6 +35,7 @@ cuprate-rpc-interface = { path = "../../rpc/interface" } cuprate-rpc-types = { path = "../../rpc/types" } # TODO: after v1.0.0, remove unneeded dependencies. +anyhow = { workspace = true } async-trait = { workspace = true } bitflags = { workspace = true } borsh = { workspace = true } diff --git a/binaries/cuprated/src/rpc/bin.rs b/binaries/cuprated/src/rpc/bin.rs index a4bbabbb..60d92c12 100644 --- a/binaries/cuprated/src/rpc/bin.rs +++ b/binaries/cuprated/src/rpc/bin.rs @@ -1,4 +1,5 @@ -use cuprate_rpc_interface::RpcError; +use anyhow::Error; + use cuprate_rpc_types::{ bin::{ BinRequest, BinResponse, GetBlocksByHeightRequest, GetBlocksByHeightResponse, @@ -15,7 +16,7 @@ use crate::rpc::CupratedRpcHandlerState; pub(super) async fn map_request( state: CupratedRpcHandlerState, request: BinRequest, -) -> Result { +) -> Result { use BinRequest as Req; use BinResponse as Resp; @@ -37,48 +38,48 @@ pub(super) async fn map_request( async fn get_blocks( state: CupratedRpcHandlerState, request: GetBlocksRequest, -) -> Result { +) -> Result { todo!() } async fn get_blocks_by_height( state: CupratedRpcHandlerState, request: GetBlocksByHeightRequest, -) -> Result { +) -> Result { todo!() } async fn get_hashes( state: CupratedRpcHandlerState, request: GetHashesRequest, -) -> Result { +) -> Result { todo!() } async fn get_output_indexes( state: CupratedRpcHandlerState, request: GetOutputIndexesRequest, -) -> Result { +) -> Result { todo!() } async fn get_outs( state: CupratedRpcHandlerState, request: GetOutsRequest, -) -> Result { +) -> Result { todo!() } async fn get_transaction_pool_hashes( state: CupratedRpcHandlerState, request: GetTransactionPoolHashesRequest, -) -> Result { +) -> Result { todo!() } async fn get_output_distribution( state: CupratedRpcHandlerState, request: GetOutputDistributionRequest, -) -> Result { +) -> Result { todo!() } diff --git a/binaries/cuprated/src/rpc/handler.rs b/binaries/cuprated/src/rpc/handler.rs index ab15ff6b..8ba25eab 100644 --- a/binaries/cuprated/src/rpc/handler.rs +++ b/binaries/cuprated/src/rpc/handler.rs @@ -2,6 +2,7 @@ use std::task::{Context, Poll}; +use anyhow::Error; use futures::{channel::oneshot::channel, future::BoxFuture}; use serde::{Deserialize, Serialize}; use tower::Service; @@ -9,7 +10,7 @@ use tower::Service; use cuprate_blockchain::service::BlockchainReadHandle; use cuprate_helper::asynch::InfallibleOneshotReceiver; use cuprate_json_rpc::Id; -use cuprate_rpc_interface::{RpcError, RpcHandler}; +use cuprate_rpc_interface::RpcHandler; use cuprate_rpc_types::{ bin::{BinRequest, BinResponse}, json::{JsonRpcRequest, JsonRpcResponse}, @@ -58,8 +59,8 @@ impl RpcHandler for CupratedRpcHandler { impl Service for CupratedRpcHandler { type Response = JsonRpcResponse; - type Error = RpcError; - type Future = BoxFuture<'static, Result>; + type Error = Error; + type Future = BoxFuture<'static, Result>; fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll> { Poll::Ready(Ok(())) @@ -73,8 +74,8 @@ impl Service for CupratedRpcHandler { impl Service for CupratedRpcHandler { type Response = BinResponse; - type Error = RpcError; - type Future = BoxFuture<'static, Result>; + type Error = Error; + type Future = BoxFuture<'static, Result>; fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll> { Poll::Ready(Ok(())) @@ -88,8 +89,8 @@ impl Service for CupratedRpcHandler { impl Service for CupratedRpcHandler { type Response = OtherResponse; - type Error = RpcError; - type Future = BoxFuture<'static, Result>; + type Error = Error; + type Future = BoxFuture<'static, Result>; fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll> { Poll::Ready(Ok(())) diff --git a/binaries/cuprated/src/rpc/json.rs b/binaries/cuprated/src/rpc/json.rs index ece925e8..41398d48 100644 --- a/binaries/cuprated/src/rpc/json.rs +++ b/binaries/cuprated/src/rpc/json.rs @@ -1,8 +1,8 @@ use std::sync::Arc; +use anyhow::Error; use tower::ServiceExt; -use cuprate_rpc_interface::RpcError; use cuprate_rpc_types::json::{ AddAuxPowRequest, AddAuxPowResponse, BannedRequest, BannedResponse, CalcPowRequest, CalcPowResponse, FlushCacheRequest, FlushCacheResponse, FlushTransactionPoolRequest, @@ -29,7 +29,7 @@ use crate::rpc::CupratedRpcHandlerState; pub(super) async fn map_request( state: CupratedRpcHandlerState, request: JsonRpcRequest, -) -> Result { +) -> Result { use JsonRpcRequest as Req; use JsonRpcResponse as Resp; @@ -86,209 +86,209 @@ pub(super) async fn map_request( async fn get_block_count( state: CupratedRpcHandlerState, request: GetBlockCountRequest, -) -> Result { +) -> Result { todo!() } async fn on_get_block_hash( state: CupratedRpcHandlerState, request: OnGetBlockHashRequest, -) -> Result { +) -> Result { todo!() } async fn submit_block( state: CupratedRpcHandlerState, request: SubmitBlockRequest, -) -> Result { +) -> Result { todo!() } async fn generate_blocks( state: CupratedRpcHandlerState, request: GenerateBlocksRequest, -) -> Result { +) -> Result { todo!() } async fn get_last_block_header( state: CupratedRpcHandlerState, request: GetLastBlockHeaderRequest, -) -> Result { +) -> Result { todo!() } async fn get_block_header_by_hash( state: CupratedRpcHandlerState, request: GetBlockHeaderByHashRequest, -) -> Result { +) -> Result { todo!() } async fn get_block_header_by_height( state: CupratedRpcHandlerState, request: GetBlockHeaderByHeightRequest, -) -> Result { +) -> Result { todo!() } async fn get_block_headers_range( state: CupratedRpcHandlerState, request: GetBlockHeadersRangeRequest, -) -> Result { +) -> Result { todo!() } async fn get_block( state: CupratedRpcHandlerState, request: GetBlockRequest, -) -> Result { +) -> Result { todo!() } async fn get_connections( state: CupratedRpcHandlerState, request: GetConnectionsRequest, -) -> Result { +) -> Result { todo!() } async fn get_info( state: CupratedRpcHandlerState, request: GetInfoRequest, -) -> Result { +) -> Result { todo!() } async fn hard_fork_info( state: CupratedRpcHandlerState, request: HardForkInfoRequest, -) -> Result { +) -> Result { todo!() } async fn set_bans( state: CupratedRpcHandlerState, request: SetBansRequest, -) -> Result { +) -> Result { todo!() } async fn get_bans( state: CupratedRpcHandlerState, request: GetBansRequest, -) -> Result { +) -> Result { todo!() } async fn banned( state: CupratedRpcHandlerState, request: BannedRequest, -) -> Result { +) -> Result { todo!() } async fn flush_transaction_pool( state: CupratedRpcHandlerState, request: FlushTransactionPoolRequest, -) -> Result { +) -> Result { todo!() } async fn get_output_histogram( state: CupratedRpcHandlerState, request: GetOutputHistogramRequest, -) -> Result { +) -> Result { todo!() } async fn get_coinbase_tx_sum( state: CupratedRpcHandlerState, request: GetCoinbaseTxSumRequest, -) -> Result { +) -> Result { todo!() } async fn get_version( state: CupratedRpcHandlerState, request: GetVersionRequest, -) -> Result { +) -> Result { todo!() } async fn get_fee_estimate( state: CupratedRpcHandlerState, request: GetFeeEstimateRequest, -) -> Result { +) -> Result { todo!() } async fn get_alternate_chains( state: CupratedRpcHandlerState, request: GetAlternateChainsRequest, -) -> Result { +) -> Result { todo!() } async fn relay_tx( state: CupratedRpcHandlerState, request: RelayTxRequest, -) -> Result { +) -> Result { todo!() } async fn sync_info( state: CupratedRpcHandlerState, request: SyncInfoRequest, -) -> Result { +) -> Result { todo!() } async fn get_transaction_pool_backlog( state: CupratedRpcHandlerState, request: GetTransactionPoolBacklogRequest, -) -> Result { +) -> Result { todo!() } async fn get_miner_data( state: CupratedRpcHandlerState, request: GetMinerDataRequest, -) -> Result { +) -> Result { todo!() } async fn prune_blockchain( state: CupratedRpcHandlerState, request: PruneBlockchainRequest, -) -> Result { +) -> Result { todo!() } async fn calc_pow( state: CupratedRpcHandlerState, request: CalcPowRequest, -) -> Result { +) -> Result { todo!() } async fn flush_cache( state: CupratedRpcHandlerState, request: FlushCacheRequest, -) -> Result { +) -> Result { todo!() } async fn add_aux_pow( state: CupratedRpcHandlerState, request: AddAuxPowRequest, -) -> Result { +) -> Result { todo!() } async fn get_tx_ids_loose( state: CupratedRpcHandlerState, request: GetTxIdsLooseRequest, -) -> Result { +) -> Result { todo!() } diff --git a/binaries/cuprated/src/rpc/other.rs b/binaries/cuprated/src/rpc/other.rs index b23ebdf9..c0df3993 100644 --- a/binaries/cuprated/src/rpc/other.rs +++ b/binaries/cuprated/src/rpc/other.rs @@ -1,4 +1,5 @@ -use cuprate_rpc_interface::RpcError; +use anyhow::Error; + use cuprate_rpc_types::other::{ GetAltBlocksHashesRequest, GetAltBlocksHashesResponse, GetHeightRequest, GetHeightResponse, GetLimitRequest, GetLimitResponse, GetNetStatsRequest, GetNetStatsResponse, GetOutsRequest, @@ -22,7 +23,7 @@ use crate::rpc::CupratedRpcHandlerState; pub(super) async fn map_request( state: CupratedRpcHandlerState, request: OtherRequest, -) -> Result { +) -> Result { use OtherRequest as Req; use OtherResponse as Resp; @@ -72,188 +73,188 @@ pub(super) async fn map_request( async fn get_height( state: CupratedRpcHandlerState, request: GetHeightRequest, -) -> Result { +) -> Result { todo!() } async fn get_transactions( state: CupratedRpcHandlerState, request: GetTransactionsRequest, -) -> Result { +) -> Result { todo!() } async fn get_alt_blocks_hashes( state: CupratedRpcHandlerState, request: GetAltBlocksHashesRequest, -) -> Result { +) -> Result { todo!() } async fn is_key_image_spent( state: CupratedRpcHandlerState, request: IsKeyImageSpentRequest, -) -> Result { +) -> Result { todo!() } async fn send_raw_transaction( state: CupratedRpcHandlerState, request: SendRawTransactionRequest, -) -> Result { +) -> Result { todo!() } async fn start_mining( state: CupratedRpcHandlerState, request: StartMiningRequest, -) -> Result { +) -> Result { todo!() } async fn stop_mining( state: CupratedRpcHandlerState, request: StopMiningRequest, -) -> Result { +) -> Result { todo!() } async fn mining_status( state: CupratedRpcHandlerState, request: MiningStatusRequest, -) -> Result { +) -> Result { todo!() } async fn save_bc( state: CupratedRpcHandlerState, request: SaveBcRequest, -) -> Result { +) -> Result { todo!() } async fn get_peer_list( state: CupratedRpcHandlerState, request: GetPeerListRequest, -) -> Result { +) -> Result { todo!() } async fn set_log_hash_rate( state: CupratedRpcHandlerState, request: SetLogHashRateRequest, -) -> Result { +) -> Result { todo!() } async fn set_log_level( state: CupratedRpcHandlerState, request: SetLogLevelRequest, -) -> Result { +) -> Result { todo!() } async fn set_log_categories( state: CupratedRpcHandlerState, request: SetLogCategoriesRequest, -) -> Result { +) -> Result { todo!() } async fn set_bootstrap_daemon( state: CupratedRpcHandlerState, request: SetBootstrapDaemonRequest, -) -> Result { +) -> Result { todo!() } async fn get_transaction_pool( state: CupratedRpcHandlerState, request: GetTransactionPoolRequest, -) -> Result { +) -> Result { todo!() } async fn get_transaction_pool_stats( state: CupratedRpcHandlerState, request: GetTransactionPoolStatsRequest, -) -> Result { +) -> Result { todo!() } async fn stop_daemon( state: CupratedRpcHandlerState, request: StopDaemonRequest, -) -> Result { +) -> Result { todo!() } async fn get_limit( state: CupratedRpcHandlerState, request: GetLimitRequest, -) -> Result { +) -> Result { todo!() } async fn set_limit( state: CupratedRpcHandlerState, request: SetLimitRequest, -) -> Result { +) -> Result { todo!() } async fn out_peers( state: CupratedRpcHandlerState, request: OutPeersRequest, -) -> Result { +) -> Result { todo!() } async fn in_peers( state: CupratedRpcHandlerState, request: InPeersRequest, -) -> Result { +) -> Result { todo!() } async fn get_net_stats( state: CupratedRpcHandlerState, request: GetNetStatsRequest, -) -> Result { +) -> Result { todo!() } async fn get_outs( state: CupratedRpcHandlerState, request: GetOutsRequest, -) -> Result { +) -> Result { todo!() } async fn update( state: CupratedRpcHandlerState, request: UpdateRequest, -) -> Result { +) -> Result { todo!() } async fn pop_blocks( state: CupratedRpcHandlerState, request: PopBlocksRequest, -) -> Result { +) -> Result { todo!() } async fn get_transaction_pool_hashes( state: CupratedRpcHandlerState, request: GetTransactionPoolHashesRequest, -) -> Result { +) -> Result { todo!() } async fn get_public_nodes( state: CupratedRpcHandlerState, request: GetPublicNodesRequest, -) -> Result { +) -> Result { todo!() }