2024-09-30 05:49:46 +03:00
|
|
|
pub mod net_utils;
|
|
|
|
|
pub mod process;
|
|
|
|
|
pub mod types;
|
|
|
|
|
|
2024-12-20 11:02:12 +02:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
2025-04-16 16:17:53 +03:00
|
|
|
use common::rpc_primitives::{
|
2024-09-30 05:49:46 +03:00
|
|
|
errors::{RpcError, RpcErrorKind},
|
|
|
|
|
RpcPollingConfig,
|
|
|
|
|
};
|
2025-04-16 16:17:53 +03:00
|
|
|
use node_core::{config::NodeConfig, NodeCore};
|
2024-09-30 05:49:46 +03:00
|
|
|
use serde::Serialize;
|
|
|
|
|
use serde_json::Value;
|
|
|
|
|
|
|
|
|
|
pub use net_utils::*;
|
2024-12-20 11:02:12 +02:00
|
|
|
use tokio::sync::Mutex;
|
2024-09-30 05:49:46 +03:00
|
|
|
|
|
|
|
|
use self::types::err_rpc::RpcErr;
|
|
|
|
|
|
|
|
|
|
//ToDo: Add necessary fields
|
|
|
|
|
pub struct JsonHandler {
|
|
|
|
|
pub polling_config: RpcPollingConfig,
|
2024-12-20 11:02:12 +02:00
|
|
|
pub node_core_config: NodeConfig,
|
|
|
|
|
pub node_chain_store: Arc<Mutex<NodeCore>>,
|
2024-09-30 05:49:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn respond<T: Serialize>(val: T) -> Result<Value, RpcErr> {
|
|
|
|
|
Ok(serde_json::to_value(val)?)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn rpc_error_responce_inverter(err: RpcError) -> RpcError {
|
|
|
|
|
let mut content: Option<Value> = None;
|
|
|
|
|
if err.error_struct.is_some() {
|
|
|
|
|
content = match err.error_struct.clone().unwrap() {
|
|
|
|
|
RpcErrorKind::HandlerError(val) | RpcErrorKind::InternalError(val) => Some(val),
|
|
|
|
|
RpcErrorKind::RequestValidationError(vall) => Some(serde_json::to_value(vall).unwrap()),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
RpcError {
|
|
|
|
|
error_struct: None,
|
|
|
|
|
code: err.code,
|
|
|
|
|
message: err.message,
|
|
|
|
|
data: content,
|
|
|
|
|
}
|
|
|
|
|
}
|