cuprated: update error type

This commit is contained in:
hinto.janai 2024-09-06 20:09:42 -04:00
parent aac1a31bed
commit 6b16fb5688
No known key found for this signature in database
GPG key ID: D47CE05FA175A499
6 changed files with 89 additions and 78 deletions

9
Cargo.lock generated
View file

@ -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",

View file

@ -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 }

View file

@ -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<BinResponse, RpcError> {
) -> Result<BinResponse, Error> {
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<GetBlocksResponse, RpcError> {
) -> Result<GetBlocksResponse, Error> {
todo!()
}
async fn get_blocks_by_height(
state: CupratedRpcHandlerState,
request: GetBlocksByHeightRequest,
) -> Result<GetBlocksByHeightResponse, RpcError> {
) -> Result<GetBlocksByHeightResponse, Error> {
todo!()
}
async fn get_hashes(
state: CupratedRpcHandlerState,
request: GetHashesRequest,
) -> Result<GetHashesResponse, RpcError> {
) -> Result<GetHashesResponse, Error> {
todo!()
}
async fn get_output_indexes(
state: CupratedRpcHandlerState,
request: GetOutputIndexesRequest,
) -> Result<GetOutputIndexesResponse, RpcError> {
) -> Result<GetOutputIndexesResponse, Error> {
todo!()
}
async fn get_outs(
state: CupratedRpcHandlerState,
request: GetOutsRequest,
) -> Result<GetOutsResponse, RpcError> {
) -> Result<GetOutsResponse, Error> {
todo!()
}
async fn get_transaction_pool_hashes(
state: CupratedRpcHandlerState,
request: GetTransactionPoolHashesRequest,
) -> Result<GetTransactionPoolHashesResponse, RpcError> {
) -> Result<GetTransactionPoolHashesResponse, Error> {
todo!()
}
async fn get_output_distribution(
state: CupratedRpcHandlerState,
request: GetOutputDistributionRequest,
) -> Result<GetOutputDistributionResponse, RpcError> {
) -> Result<GetOutputDistributionResponse, Error> {
todo!()
}

View file

@ -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<JsonRpcRequest> for CupratedRpcHandler {
type Response = JsonRpcResponse;
type Error = RpcError;
type Future = BoxFuture<'static, Result<JsonRpcResponse, RpcError>>;
type Error = Error;
type Future = BoxFuture<'static, Result<JsonRpcResponse, Error>>;
fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
Poll::Ready(Ok(()))
@ -73,8 +74,8 @@ impl Service<JsonRpcRequest> for CupratedRpcHandler {
impl Service<BinRequest> for CupratedRpcHandler {
type Response = BinResponse;
type Error = RpcError;
type Future = BoxFuture<'static, Result<BinResponse, RpcError>>;
type Error = Error;
type Future = BoxFuture<'static, Result<BinResponse, Error>>;
fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
Poll::Ready(Ok(()))
@ -88,8 +89,8 @@ impl Service<BinRequest> for CupratedRpcHandler {
impl Service<OtherRequest> for CupratedRpcHandler {
type Response = OtherResponse;
type Error = RpcError;
type Future = BoxFuture<'static, Result<OtherResponse, RpcError>>;
type Error = Error;
type Future = BoxFuture<'static, Result<OtherResponse, Error>>;
fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
Poll::Ready(Ok(()))

View file

@ -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<JsonRpcResponse, RpcError> {
) -> Result<JsonRpcResponse, Error> {
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<GetBlockCountResponse, RpcError> {
) -> Result<GetBlockCountResponse, Error> {
todo!()
}
async fn on_get_block_hash(
state: CupratedRpcHandlerState,
request: OnGetBlockHashRequest,
) -> Result<OnGetBlockHashResponse, RpcError> {
) -> Result<OnGetBlockHashResponse, Error> {
todo!()
}
async fn submit_block(
state: CupratedRpcHandlerState,
request: SubmitBlockRequest,
) -> Result<SubmitBlockResponse, RpcError> {
) -> Result<SubmitBlockResponse, Error> {
todo!()
}
async fn generate_blocks(
state: CupratedRpcHandlerState,
request: GenerateBlocksRequest,
) -> Result<GenerateBlocksResponse, RpcError> {
) -> Result<GenerateBlocksResponse, Error> {
todo!()
}
async fn get_last_block_header(
state: CupratedRpcHandlerState,
request: GetLastBlockHeaderRequest,
) -> Result<GetLastBlockHeaderResponse, RpcError> {
) -> Result<GetLastBlockHeaderResponse, Error> {
todo!()
}
async fn get_block_header_by_hash(
state: CupratedRpcHandlerState,
request: GetBlockHeaderByHashRequest,
) -> Result<GetBlockHeaderByHashResponse, RpcError> {
) -> Result<GetBlockHeaderByHashResponse, Error> {
todo!()
}
async fn get_block_header_by_height(
state: CupratedRpcHandlerState,
request: GetBlockHeaderByHeightRequest,
) -> Result<GetBlockHeaderByHeightResponse, RpcError> {
) -> Result<GetBlockHeaderByHeightResponse, Error> {
todo!()
}
async fn get_block_headers_range(
state: CupratedRpcHandlerState,
request: GetBlockHeadersRangeRequest,
) -> Result<GetBlockHeadersRangeResponse, RpcError> {
) -> Result<GetBlockHeadersRangeResponse, Error> {
todo!()
}
async fn get_block(
state: CupratedRpcHandlerState,
request: GetBlockRequest,
) -> Result<GetBlockResponse, RpcError> {
) -> Result<GetBlockResponse, Error> {
todo!()
}
async fn get_connections(
state: CupratedRpcHandlerState,
request: GetConnectionsRequest,
) -> Result<GetConnectionsResponse, RpcError> {
) -> Result<GetConnectionsResponse, Error> {
todo!()
}
async fn get_info(
state: CupratedRpcHandlerState,
request: GetInfoRequest,
) -> Result<GetInfoResponse, RpcError> {
) -> Result<GetInfoResponse, Error> {
todo!()
}
async fn hard_fork_info(
state: CupratedRpcHandlerState,
request: HardForkInfoRequest,
) -> Result<HardForkInfoResponse, RpcError> {
) -> Result<HardForkInfoResponse, Error> {
todo!()
}
async fn set_bans(
state: CupratedRpcHandlerState,
request: SetBansRequest,
) -> Result<SetBansResponse, RpcError> {
) -> Result<SetBansResponse, Error> {
todo!()
}
async fn get_bans(
state: CupratedRpcHandlerState,
request: GetBansRequest,
) -> Result<GetBansResponse, RpcError> {
) -> Result<GetBansResponse, Error> {
todo!()
}
async fn banned(
state: CupratedRpcHandlerState,
request: BannedRequest,
) -> Result<BannedResponse, RpcError> {
) -> Result<BannedResponse, Error> {
todo!()
}
async fn flush_transaction_pool(
state: CupratedRpcHandlerState,
request: FlushTransactionPoolRequest,
) -> Result<FlushTransactionPoolResponse, RpcError> {
) -> Result<FlushTransactionPoolResponse, Error> {
todo!()
}
async fn get_output_histogram(
state: CupratedRpcHandlerState,
request: GetOutputHistogramRequest,
) -> Result<GetOutputHistogramResponse, RpcError> {
) -> Result<GetOutputHistogramResponse, Error> {
todo!()
}
async fn get_coinbase_tx_sum(
state: CupratedRpcHandlerState,
request: GetCoinbaseTxSumRequest,
) -> Result<GetCoinbaseTxSumResponse, RpcError> {
) -> Result<GetCoinbaseTxSumResponse, Error> {
todo!()
}
async fn get_version(
state: CupratedRpcHandlerState,
request: GetVersionRequest,
) -> Result<GetVersionResponse, RpcError> {
) -> Result<GetVersionResponse, Error> {
todo!()
}
async fn get_fee_estimate(
state: CupratedRpcHandlerState,
request: GetFeeEstimateRequest,
) -> Result<GetFeeEstimateResponse, RpcError> {
) -> Result<GetFeeEstimateResponse, Error> {
todo!()
}
async fn get_alternate_chains(
state: CupratedRpcHandlerState,
request: GetAlternateChainsRequest,
) -> Result<GetAlternateChainsResponse, RpcError> {
) -> Result<GetAlternateChainsResponse, Error> {
todo!()
}
async fn relay_tx(
state: CupratedRpcHandlerState,
request: RelayTxRequest,
) -> Result<RelayTxResponse, RpcError> {
) -> Result<RelayTxResponse, Error> {
todo!()
}
async fn sync_info(
state: CupratedRpcHandlerState,
request: SyncInfoRequest,
) -> Result<SyncInfoResponse, RpcError> {
) -> Result<SyncInfoResponse, Error> {
todo!()
}
async fn get_transaction_pool_backlog(
state: CupratedRpcHandlerState,
request: GetTransactionPoolBacklogRequest,
) -> Result<GetTransactionPoolBacklogResponse, RpcError> {
) -> Result<GetTransactionPoolBacklogResponse, Error> {
todo!()
}
async fn get_miner_data(
state: CupratedRpcHandlerState,
request: GetMinerDataRequest,
) -> Result<GetMinerDataResponse, RpcError> {
) -> Result<GetMinerDataResponse, Error> {
todo!()
}
async fn prune_blockchain(
state: CupratedRpcHandlerState,
request: PruneBlockchainRequest,
) -> Result<PruneBlockchainResponse, RpcError> {
) -> Result<PruneBlockchainResponse, Error> {
todo!()
}
async fn calc_pow(
state: CupratedRpcHandlerState,
request: CalcPowRequest,
) -> Result<CalcPowResponse, RpcError> {
) -> Result<CalcPowResponse, Error> {
todo!()
}
async fn flush_cache(
state: CupratedRpcHandlerState,
request: FlushCacheRequest,
) -> Result<FlushCacheResponse, RpcError> {
) -> Result<FlushCacheResponse, Error> {
todo!()
}
async fn add_aux_pow(
state: CupratedRpcHandlerState,
request: AddAuxPowRequest,
) -> Result<AddAuxPowResponse, RpcError> {
) -> Result<AddAuxPowResponse, Error> {
todo!()
}
async fn get_tx_ids_loose(
state: CupratedRpcHandlerState,
request: GetTxIdsLooseRequest,
) -> Result<GetTxIdsLooseResponse, RpcError> {
) -> Result<GetTxIdsLooseResponse, Error> {
todo!()
}

View file

@ -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<OtherResponse, RpcError> {
) -> Result<OtherResponse, Error> {
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<GetHeightResponse, RpcError> {
) -> Result<GetHeightResponse, Error> {
todo!()
}
async fn get_transactions(
state: CupratedRpcHandlerState,
request: GetTransactionsRequest,
) -> Result<GetTransactionsResponse, RpcError> {
) -> Result<GetTransactionsResponse, Error> {
todo!()
}
async fn get_alt_blocks_hashes(
state: CupratedRpcHandlerState,
request: GetAltBlocksHashesRequest,
) -> Result<GetAltBlocksHashesResponse, RpcError> {
) -> Result<GetAltBlocksHashesResponse, Error> {
todo!()
}
async fn is_key_image_spent(
state: CupratedRpcHandlerState,
request: IsKeyImageSpentRequest,
) -> Result<IsKeyImageSpentResponse, RpcError> {
) -> Result<IsKeyImageSpentResponse, Error> {
todo!()
}
async fn send_raw_transaction(
state: CupratedRpcHandlerState,
request: SendRawTransactionRequest,
) -> Result<SendRawTransactionResponse, RpcError> {
) -> Result<SendRawTransactionResponse, Error> {
todo!()
}
async fn start_mining(
state: CupratedRpcHandlerState,
request: StartMiningRequest,
) -> Result<StartMiningResponse, RpcError> {
) -> Result<StartMiningResponse, Error> {
todo!()
}
async fn stop_mining(
state: CupratedRpcHandlerState,
request: StopMiningRequest,
) -> Result<StopMiningResponse, RpcError> {
) -> Result<StopMiningResponse, Error> {
todo!()
}
async fn mining_status(
state: CupratedRpcHandlerState,
request: MiningStatusRequest,
) -> Result<MiningStatusResponse, RpcError> {
) -> Result<MiningStatusResponse, Error> {
todo!()
}
async fn save_bc(
state: CupratedRpcHandlerState,
request: SaveBcRequest,
) -> Result<SaveBcResponse, RpcError> {
) -> Result<SaveBcResponse, Error> {
todo!()
}
async fn get_peer_list(
state: CupratedRpcHandlerState,
request: GetPeerListRequest,
) -> Result<GetPeerListResponse, RpcError> {
) -> Result<GetPeerListResponse, Error> {
todo!()
}
async fn set_log_hash_rate(
state: CupratedRpcHandlerState,
request: SetLogHashRateRequest,
) -> Result<SetLogHashRateResponse, RpcError> {
) -> Result<SetLogHashRateResponse, Error> {
todo!()
}
async fn set_log_level(
state: CupratedRpcHandlerState,
request: SetLogLevelRequest,
) -> Result<SetLogLevelResponse, RpcError> {
) -> Result<SetLogLevelResponse, Error> {
todo!()
}
async fn set_log_categories(
state: CupratedRpcHandlerState,
request: SetLogCategoriesRequest,
) -> Result<SetLogCategoriesResponse, RpcError> {
) -> Result<SetLogCategoriesResponse, Error> {
todo!()
}
async fn set_bootstrap_daemon(
state: CupratedRpcHandlerState,
request: SetBootstrapDaemonRequest,
) -> Result<SetBootstrapDaemonResponse, RpcError> {
) -> Result<SetBootstrapDaemonResponse, Error> {
todo!()
}
async fn get_transaction_pool(
state: CupratedRpcHandlerState,
request: GetTransactionPoolRequest,
) -> Result<GetTransactionPoolResponse, RpcError> {
) -> Result<GetTransactionPoolResponse, Error> {
todo!()
}
async fn get_transaction_pool_stats(
state: CupratedRpcHandlerState,
request: GetTransactionPoolStatsRequest,
) -> Result<GetTransactionPoolStatsResponse, RpcError> {
) -> Result<GetTransactionPoolStatsResponse, Error> {
todo!()
}
async fn stop_daemon(
state: CupratedRpcHandlerState,
request: StopDaemonRequest,
) -> Result<StopDaemonResponse, RpcError> {
) -> Result<StopDaemonResponse, Error> {
todo!()
}
async fn get_limit(
state: CupratedRpcHandlerState,
request: GetLimitRequest,
) -> Result<GetLimitResponse, RpcError> {
) -> Result<GetLimitResponse, Error> {
todo!()
}
async fn set_limit(
state: CupratedRpcHandlerState,
request: SetLimitRequest,
) -> Result<SetLimitResponse, RpcError> {
) -> Result<SetLimitResponse, Error> {
todo!()
}
async fn out_peers(
state: CupratedRpcHandlerState,
request: OutPeersRequest,
) -> Result<OutPeersResponse, RpcError> {
) -> Result<OutPeersResponse, Error> {
todo!()
}
async fn in_peers(
state: CupratedRpcHandlerState,
request: InPeersRequest,
) -> Result<InPeersResponse, RpcError> {
) -> Result<InPeersResponse, Error> {
todo!()
}
async fn get_net_stats(
state: CupratedRpcHandlerState,
request: GetNetStatsRequest,
) -> Result<GetNetStatsResponse, RpcError> {
) -> Result<GetNetStatsResponse, Error> {
todo!()
}
async fn get_outs(
state: CupratedRpcHandlerState,
request: GetOutsRequest,
) -> Result<GetOutsResponse, RpcError> {
) -> Result<GetOutsResponse, Error> {
todo!()
}
async fn update(
state: CupratedRpcHandlerState,
request: UpdateRequest,
) -> Result<UpdateResponse, RpcError> {
) -> Result<UpdateResponse, Error> {
todo!()
}
async fn pop_blocks(
state: CupratedRpcHandlerState,
request: PopBlocksRequest,
) -> Result<PopBlocksResponse, RpcError> {
) -> Result<PopBlocksResponse, Error> {
todo!()
}
async fn get_transaction_pool_hashes(
state: CupratedRpcHandlerState,
request: GetTransactionPoolHashesRequest,
) -> Result<GetTransactionPoolHashesResponse, RpcError> {
) -> Result<GetTransactionPoolHashesResponse, Error> {
todo!()
}
async fn get_public_nodes(
state: CupratedRpcHandlerState,
request: GetPublicNodesRequest,
) -> Result<GetPublicNodesResponse, RpcError> {
) -> Result<GetPublicNodesResponse, Error> {
todo!()
}