diff --git a/rpc/interface/README.md b/rpc/interface/README.md index 2d3faa7..59d9f04 100644 --- a/rpc/interface/README.md +++ b/rpc/interface/README.md @@ -85,7 +85,13 @@ use cuprate_rpc_types::{ json::{JsonRpcRequest, JsonRpcResponse, GetBlockCountResponse}, other::{OtherRequest, OtherResponse}, }; +<<<<<<< HEAD use cuprate_rpc_interface::{RouterBuilder, RpcHandlerDummy, Request}; +||||||| 0941f68 +use cuprate_rpc_interface::{RouterBuilder, RpcHandlerDummy, RpcRequest}; +======= +use cuprate_rpc_interface::{RouterBuilder, RpcHandlerDummy}; +>>>>>>> main // Send a `/get_height` request. This endpoint has no inputs. async fn get_height(port: u16) -> OtherResponse { diff --git a/rpc/interface/src/lib.rs b/rpc/interface/src/lib.rs index f3e2988..ebea493 100644 --- a/rpc/interface/src/lib.rs +++ b/rpc/interface/src/lib.rs @@ -7,8 +7,6 @@ mod rpc_error; mod rpc_handler; #[cfg(feature = "dummy")] mod rpc_handler_dummy; -// mod rpc_request; -// mod rpc_response; mod rpc_service; pub use router_builder::RouterBuilder; @@ -16,8 +14,6 @@ pub use rpc_error::RpcError; pub use rpc_handler::RpcHandler; #[cfg(feature = "dummy")] pub use rpc_handler_dummy::RpcHandlerDummy; -// pub use rpc_request::RpcRequest; -// pub use rpc_response::RpcResponse; pub use rpc_service::RpcService; // false-positive: used in `README.md`'s doc-test. diff --git a/rpc/interface/src/rpc_handler.rs b/rpc/interface/src/rpc_handler.rs index f4c9fb5..1299ec4 100644 --- a/rpc/interface/src/rpc_handler.rs +++ b/rpc/interface/src/rpc_handler.rs @@ -15,12 +15,12 @@ use crate::RpcService; /// This trait represents a type that can turn `Request`s into `Response`s. /// /// Implementors of this trait must be: -/// - A [`tower::Service`]s that use [`JsonRpcRequest`] & [`JsonRpcResponse`] -/// - A [`tower::Service`]s that use [`BinRequest`] & [`BinResponse`] -/// - A [`tower::Service`]s that use [`OtherRequest`] & [`OtherResponse`] +/// - A [`tower::Service`] that uses [`JsonRpcRequest`] & [`JsonRpcResponse`] +/// - A [`tower::Service`] that uses [`BinRequest`] & [`BinResponse`] +/// - A [`tower::Service`] that uses [`OtherRequest`] & [`OtherResponse`] /// /// In other words, an [`RpcHandler`] is a type that implements [`tower::Service`] 3 times, -/// one for each endpoint enum type found in [`cuprate_rpc_types`]. +/// one for each request/response enum type found in [`cuprate_rpc_types`]. /// /// The error type must always be [`RpcError`](crate::RpcError). /// @@ -30,7 +30,7 @@ use crate::RpcService; /// Your [`RpcHandler`] must reply to `Request`s with the correct /// `Response` or else this crate will panic during routing functions. /// -/// For example, upon a [`JsonRpcRequest::GetBlockCount`] must be replied with +/// For example, a [`JsonRpcRequest::GetBlockCount`] must be replied with /// [`JsonRpcResponse::GetBlockCount`]. If anything else is returned, /// this crate may panic. pub trait RpcHandler: diff --git a/rpc/interface/src/rpc_request.rs b/rpc/interface/src/rpc_request.rs deleted file mode 100644 index acac6dd..0000000 --- a/rpc/interface/src/rpc_request.rs +++ /dev/null @@ -1,33 +0,0 @@ -//! RPC requests. - -//---------------------------------------------------------------------------------------------------- Import -#[cfg(feature = "serde")] -use serde::{Deserialize, Serialize}; - -use cuprate_rpc_types::{bin::BinRequest, json::JsonRpcRequest, other::OtherRequest}; - -//---------------------------------------------------------------------------------------------------- RpcRequest -/// All possible RPC requests. -/// -/// This enum encapsulates all possible RPC requests: -/// - JSON RPC 2.0 requests -/// - Binary requests -/// - Other JSON requests -/// -/// It is the `Request` type required to be used in an [`RpcHandler`](crate::RpcHandler). -#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] -#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))] -pub enum RpcRequest { - /// JSON-RPC 2.0 requests. - JsonRpc(JsonRpcRequest), - /// Binary requests. - Binary(BinRequest), - /// Other JSON requests. - Other(OtherRequest), -} - -//---------------------------------------------------------------------------------------------------- Tests -#[cfg(test)] -mod test { - // use super::*; -} diff --git a/rpc/interface/src/rpc_response.rs b/rpc/interface/src/rpc_response.rs deleted file mode 100644 index 23a0729..0000000 --- a/rpc/interface/src/rpc_response.rs +++ /dev/null @@ -1,34 +0,0 @@ -//! RPC responses. - -//---------------------------------------------------------------------------------------------------- Import -#[cfg(feature = "serde")] -use serde::{Deserialize, Serialize}; - -use cuprate_rpc_types::{bin::BinResponse, json::JsonRpcResponse, other::OtherResponse}; - -//---------------------------------------------------------------------------------------------------- RpcResponse -/// All possible RPC responses. -/// -/// This enum encapsulates all possible RPC responses: -/// - JSON RPC 2.0 responses -/// - Binary responses -/// - Other JSON responses -/// -/// It is the `Response` type required to be used in an [`RpcHandler`](crate::RpcHandler). -#[derive(Clone, PartialEq, Eq)] -#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))] -#[allow(clippy::large_enum_variant)] // FIXME: maybe don't wrap internally with an enum? -pub enum RpcResponse { - /// JSON RPC 2.0 responses. - JsonRpc(JsonRpcResponse), - /// Binary responses. - Binary(BinResponse), - /// Other JSON responses. - Other(OtherResponse), -} - -//---------------------------------------------------------------------------------------------------- Tests -#[cfg(test)] -mod test { - // use super::*; -} diff --git a/rpc/interface/src/rpc_service.rs b/rpc/interface/src/rpc_service.rs index cd25003..db84830 100644 --- a/rpc/interface/src/rpc_service.rs +++ b/rpc/interface/src/rpc_service.rs @@ -19,6 +19,9 @@ use crate::rpc_error::RpcError; /// /// The error type is always [`RpcError`]. /// +/// There is a blanket implementation that implements this +/// trait on types that implement `tower::Service` correctly. +/// /// See [`RpcHandler`](crate::RpcHandler) for more information. pub trait RpcService: Clone