mirror of
https://github.com/Cuprate/cuprate.git
synced 2024-12-25 13:09:41 +00:00
Merge branch 'main' into rpc-handler
This commit is contained in:
commit
3965349f71
6 changed files with 14 additions and 76 deletions
|
@ -85,7 +85,13 @@ use cuprate_rpc_types::{
|
||||||
json::{JsonRpcRequest, JsonRpcResponse, GetBlockCountResponse},
|
json::{JsonRpcRequest, JsonRpcResponse, GetBlockCountResponse},
|
||||||
other::{OtherRequest, OtherResponse},
|
other::{OtherRequest, OtherResponse},
|
||||||
};
|
};
|
||||||
|
<<<<<<< HEAD
|
||||||
use cuprate_rpc_interface::{RouterBuilder, RpcHandlerDummy, Request};
|
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.
|
// Send a `/get_height` request. This endpoint has no inputs.
|
||||||
async fn get_height(port: u16) -> OtherResponse {
|
async fn get_height(port: u16) -> OtherResponse {
|
||||||
|
|
|
@ -7,8 +7,6 @@ mod rpc_error;
|
||||||
mod rpc_handler;
|
mod rpc_handler;
|
||||||
#[cfg(feature = "dummy")]
|
#[cfg(feature = "dummy")]
|
||||||
mod rpc_handler_dummy;
|
mod rpc_handler_dummy;
|
||||||
// mod rpc_request;
|
|
||||||
// mod rpc_response;
|
|
||||||
mod rpc_service;
|
mod rpc_service;
|
||||||
|
|
||||||
pub use router_builder::RouterBuilder;
|
pub use router_builder::RouterBuilder;
|
||||||
|
@ -16,8 +14,6 @@ pub use rpc_error::RpcError;
|
||||||
pub use rpc_handler::RpcHandler;
|
pub use rpc_handler::RpcHandler;
|
||||||
#[cfg(feature = "dummy")]
|
#[cfg(feature = "dummy")]
|
||||||
pub use rpc_handler_dummy::RpcHandlerDummy;
|
pub use rpc_handler_dummy::RpcHandlerDummy;
|
||||||
// pub use rpc_request::RpcRequest;
|
|
||||||
// pub use rpc_response::RpcResponse;
|
|
||||||
pub use rpc_service::RpcService;
|
pub use rpc_service::RpcService;
|
||||||
|
|
||||||
// false-positive: used in `README.md`'s doc-test.
|
// false-positive: used in `README.md`'s doc-test.
|
||||||
|
|
|
@ -15,12 +15,12 @@ use crate::RpcService;
|
||||||
/// This trait represents a type that can turn `Request`s into `Response`s.
|
/// This trait represents a type that can turn `Request`s into `Response`s.
|
||||||
///
|
///
|
||||||
/// Implementors of this trait must be:
|
/// Implementors of this trait must be:
|
||||||
/// - A [`tower::Service`]s that use [`JsonRpcRequest`] & [`JsonRpcResponse`]
|
/// - A [`tower::Service`] that uses [`JsonRpcRequest`] & [`JsonRpcResponse`]
|
||||||
/// - A [`tower::Service`]s that use [`BinRequest`] & [`BinResponse`]
|
/// - A [`tower::Service`] that uses [`BinRequest`] & [`BinResponse`]
|
||||||
/// - A [`tower::Service`]s that use [`OtherRequest`] & [`OtherResponse`]
|
/// - A [`tower::Service`] that uses [`OtherRequest`] & [`OtherResponse`]
|
||||||
///
|
///
|
||||||
/// In other words, an [`RpcHandler`] is a type that implements [`tower::Service`] 3 times,
|
/// 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).
|
/// 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
|
/// Your [`RpcHandler`] must reply to `Request`s with the correct
|
||||||
/// `Response` or else this crate will panic during routing functions.
|
/// `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,
|
/// [`JsonRpcResponse::GetBlockCount`]. If anything else is returned,
|
||||||
/// this crate may panic.
|
/// this crate may panic.
|
||||||
pub trait RpcHandler:
|
pub trait RpcHandler:
|
||||||
|
|
|
@ -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::*;
|
|
||||||
}
|
|
|
@ -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::*;
|
|
||||||
}
|
|
|
@ -19,6 +19,9 @@ use crate::rpc_error::RpcError;
|
||||||
///
|
///
|
||||||
/// The error type is always [`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.
|
/// See [`RpcHandler`](crate::RpcHandler) for more information.
|
||||||
pub trait RpcService<Request, Response>:
|
pub trait RpcService<Request, Response>:
|
||||||
Clone
|
Clone
|
||||||
|
|
Loading…
Reference in a new issue