From cbf76d49f3bcc798ed7684e1067903a4a8f75416 Mon Sep 17 00:00:00 2001 From: canonbrother Date: Mon, 25 Nov 2024 17:05:31 +0800 Subject: [PATCH] ApiRpcResponse --- lib/ain-ocean/src/api/response.rs | 14 ++++++++++++++ lib/ain-ocean/src/api/rpc.rs | 6 +++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/ain-ocean/src/api/response.rs b/lib/ain-ocean/src/api/response.rs index ead721a2781..a8726210108 100644 --- a/lib/ain-ocean/src/api/response.rs +++ b/lib/ain-ocean/src/api/response.rs @@ -12,6 +12,20 @@ impl Response { } } +#[derive(Debug, Serialize)] +pub struct ApiRpcResponse { + result: T, + // TODO: map error and id from rpc + // error: T, + // id: T, +} + +impl ApiRpcResponse { + pub fn new(result: T) -> Self { + Self { result } + } +} + /// ApiPagedResponse indicates that this response of data array slice is part of a sorted list of items. /// Items are part of a larger sorted list and the slice indicates a window within the large sorted list. /// Each ApiPagedResponse holds the data array and the "token" for next part of the slice. diff --git a/lib/ain-ocean/src/api/rpc.rs b/lib/ain-ocean/src/api/rpc.rs index 809f0853ec1..0bebb6836a7 100644 --- a/lib/ain-ocean/src/api/rpc.rs +++ b/lib/ain-ocean/src/api/rpc.rs @@ -5,7 +5,7 @@ use axum::{routing::post, Extension, Json, Router}; use defichain_rpc::RpcApi; use serde::{Deserialize, Serialize}; -use super::{response::Response, AppContext}; +use super::{response::ApiRpcResponse, AppContext}; use crate::{ error::{ApiError, Error}, Result, @@ -54,12 +54,12 @@ fn method_whitelist(method: &str) -> Result<()> { async fn rpc( Extension(ctx): Extension>, Json(body): Json, -) -> Result> { +) -> Result> { method_whitelist(&body.method)?; let res: serde_json::Value = ctx.client.call(&body.method, &body.params).await?; - Ok(Response::new(res)) + Ok(ApiRpcResponse::new(res)) } pub fn router(ctx: Arc) -> Router {