From ce6838bd6fa3c3d78972a2414d0b1d2d2577599c Mon Sep 17 00:00:00 2001 From: "hinto.janai" Date: Tue, 17 Dec 2024 18:39:05 -0500 Subject: [PATCH] restricted json-rpc error --- rpc/interface/src/route/bin.rs | 11 ++++++----- rpc/interface/src/route/json_rpc.rs | 21 ++++++++------------- rpc/interface/src/route/other.rs | 7 +++---- 3 files changed, 17 insertions(+), 22 deletions(-) diff --git a/rpc/interface/src/route/bin.rs b/rpc/interface/src/route/bin.rs index 1e3b2021..12c4e578 100644 --- a/rpc/interface/src/route/bin.rs +++ b/rpc/interface/src/route/bin.rs @@ -71,12 +71,13 @@ macro_rules! generate_endpoints_inner { ($variant:ident, $handler:ident, $request:expr_2021) => { paste::paste! { { - // INVARIANT: - // The handler functions in `cuprated` depend on this line existing, - // the functions themselves do not check if they are being called - // from an (un)restricted context. + // Check if restricted. // - // This line must be here or all methods will be allowed to be called freely. + // INVARIANT: + // The RPC handler functions in `cuprated` depend on this line existing, + // the functions themselves do not check if they are being called + // from an (un)restricted context. This line must be here or all + // methods will be allowed to be called freely. if [<$variant Request>]::IS_RESTRICTED && $handler.is_restricted() { // TODO: mimic `monerod` behavior. return Err(StatusCode::FORBIDDEN); diff --git a/rpc/interface/src/route/json_rpc.rs b/rpc/interface/src/route/json_rpc.rs index 1ef57223..9d814c2e 100644 --- a/rpc/interface/src/route/json_rpc.rs +++ b/rpc/interface/src/route/json_rpc.rs @@ -39,21 +39,16 @@ pub(crate) async fn json_rpc( // the requested method is only for non-restricted RPC. // // INVARIANT: - // The handler functions in `cuprated` depend on this line existing, + // The RPC handler functions in `cuprated` depend on this line existing, // the functions themselves do not check if they are being called - // from an (un)restricted context. - // - // This line must be here or all methods will be allowed to be called freely. + // from an (un)restricted context. This line must be here or all + // methods will be allowed to be called freely. if request.body.is_restricted() && handler.is_restricted() { - let error_object = ErrorObject { - code: ErrorCode::ServerError(-1 /* TODO */), - message: Cow::Borrowed("Restricted. TODO: mimic monerod message"), - data: None, - }; - - let response = Response::err(id, error_object); - - return Ok(Json(response)); + // The error when a restricted JSON-RPC method is called as per: + // + // - + // - + return Ok(Json(Response::method_not_found(id))); } // Send request. diff --git a/rpc/interface/src/route/other.rs b/rpc/interface/src/route/other.rs index 2b7c14bf..3a804a6f 100644 --- a/rpc/interface/src/route/other.rs +++ b/rpc/interface/src/route/other.rs @@ -77,11 +77,10 @@ macro_rules! generate_endpoints_inner { // Check if restricted. // // INVARIANT: - // The handler functions in `cuprated` depend on this line existing, + // The RPC handler functions in `cuprated` depend on this line existing, // the functions themselves do not check if they are being called - // from an (un)restricted context. - // - // This line must be here or all methods will be allowed to be called freely. + // from an (un)restricted context. This line must be here or all + // methods will be allowed to be called freely. if [<$variant Request>]::IS_RESTRICTED && $handler.is_restricted() { // TODO: mimic `monerod` behavior. return Err(StatusCode::FORBIDDEN);