Skip to content

Commit

Permalink
ApiRpcResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
canonbrother committed Nov 25, 2024
1 parent 1b58ee9 commit cbf76d4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
14 changes: 14 additions & 0 deletions lib/ain-ocean/src/api/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@ impl<T> Response<T> {
}
}

#[derive(Debug, Serialize)]
pub struct ApiRpcResponse<T> {
result: T,
// TODO: map error and id from rpc
// error: T,
// id: T,
}

impl<T> ApiRpcResponse<T> {
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.
Expand Down
6 changes: 3 additions & 3 deletions lib/ain-ocean/src/api/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -54,12 +54,12 @@ fn method_whitelist(method: &str) -> Result<()> {
async fn rpc(
Extension(ctx): Extension<Arc<AppContext>>,
Json(body): Json<RpcDto>,
) -> Result<Response<serde_json::Value>> {
) -> Result<ApiRpcResponse<serde_json::Value>> {
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<AppContext>) -> Router {
Expand Down

0 comments on commit cbf76d4

Please sign in to comment.