From f89e29eebabb40ce2404aea84beb6dee3220ae84 Mon Sep 17 00:00:00 2001 From: "hinto.janai" Date: Mon, 2 Sep 2024 17:47:23 -0400 Subject: [PATCH] fixes --- binaries/cuprated/src/rpc/bin.rs | 3 ++- binaries/cuprated/src/rpc/handler.rs | 26 +++++++++----------------- binaries/cuprated/src/rpc/json.rs | 5 ++++- binaries/cuprated/src/rpc/other.rs | 5 ++++- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/binaries/cuprated/src/rpc/bin.rs b/binaries/cuprated/src/rpc/bin.rs index bb99da76..547848f8 100644 --- a/binaries/cuprated/src/rpc/bin.rs +++ b/binaries/cuprated/src/rpc/bin.rs @@ -8,7 +8,7 @@ use cuprate_rpc_types::bin::{ use crate::rpc::CupratedRpcHandler; -async fn map_request(state: CupratedRpcHandler, request: BinRpcRequest) -> BinRpcResponse { +pub(super) async fn map_request(state: CupratedRpcHandler, request: BinRpcRequest) -> BinRpcResponse { use BinRpcRequest as Req; use BinRpcResponse as Resp; @@ -59,6 +59,7 @@ async fn get_transaction_pool_hashes( ) -> GetTransactionPoolHashesResponse { todo!() } + async fn get_output_distribution( state: CupratedRpcHandler, request: GetOutputDistributionRequest, diff --git a/binaries/cuprated/src/rpc/handler.rs b/binaries/cuprated/src/rpc/handler.rs index b2506159..760c3dbe 100644 --- a/binaries/cuprated/src/rpc/handler.rs +++ b/binaries/cuprated/src/rpc/handler.rs @@ -53,27 +53,19 @@ impl Service for CupratedRpcHandler { Poll::Ready(Ok(())) } + /// INVARIANT: + /// + /// We don't need to check for `self.is_restricted()` + /// here because `cuprate-rpc-interface` handles that. + /// + /// We can assume the request coming has the required permissions. fn call(&mut self, req: RpcRequest) -> Self::Future { - use cuprate_rpc_types::bin::BinRequest as BReq; - use cuprate_rpc_types::bin::BinResponse as BResp; - use cuprate_rpc_types::json::JsonRpcRequest as JReq; - use cuprate_rpc_types::json::JsonRpcResponse as JResp; - use cuprate_rpc_types::other::OtherRequest as OReq; - use cuprate_rpc_types::other::OtherResponse as OResp; - - // INVARIANT: - // - // We don't need to check for `self.is_restricted()` - // here because `cuprate-rpc-interface` handles that. - // - // We can assume the request coming has the required permissions. - let state = CupratedRpcHandler::clone(self); let resp = match req { - RpcRequest::JsonRpc(r) => json::map_request(r), // JSON-RPC 2.0 requests. - RpcRequest::Binary(r) => bin::map_request(r), // Binary requests. - RpcRequest::Other(o) => other::map_request(r), // JSON (but not JSON-RPC) requests. + RpcRequest::JsonRpc(r) => json::map_request(state, r), // JSON-RPC 2.0 requests. + RpcRequest::Binary(r) => bin::map_request(state, r), // Binary requests. + RpcRequest::Other(o) => other::map_request(state, r), // JSON (but not JSON-RPC) requests. }; let (tx, rx) = channel(); diff --git a/binaries/cuprated/src/rpc/json.rs b/binaries/cuprated/src/rpc/json.rs index 3286100f..14cbd256 100644 --- a/binaries/cuprated/src/rpc/json.rs +++ b/binaries/cuprated/src/rpc/json.rs @@ -22,7 +22,10 @@ use cuprate_rpc_types::json::{ use crate::rpc::CupratedRpcHandler; -async fn map_request(state: CupratedRpcHandler, request: JsonRpcRequest) -> JsonRpcResponse { +pub(super) async fn map_request( + state: CupratedRpcHandler, + request: JsonRpcRequest, +) -> JsonRpcResponse { use JsonRpcRequest as Req; use JsonRpcResponse as Resp; diff --git a/binaries/cuprated/src/rpc/other.rs b/binaries/cuprated/src/rpc/other.rs index f1bb8590..c570dfae 100644 --- a/binaries/cuprated/src/rpc/other.rs +++ b/binaries/cuprated/src/rpc/other.rs @@ -17,7 +17,10 @@ use cuprate_rpc_types::other::{ use crate::rpc::CupratedRpcHandler; -async fn map_request(state: CupratedRpcHandler, request: OtherRpcRequest) -> OtherRpcResponse { +pub(super) async fn map_request( + state: CupratedRpcHandler, + request: OtherRpcRequest, +) -> OtherRpcResponse { use OtherRpcRequest as Req; use OtherRpcResponse as Resp;