mirror of
https://github.com/logos-blockchain/lssa.git
synced 2026-01-02 13:23:10 +00:00
46 lines
1.1 KiB
Rust
46 lines
1.1 KiB
Rust
pub mod net_utils;
|
|
pub mod process;
|
|
pub mod types;
|
|
|
|
use std::sync::Arc;
|
|
|
|
use common::rpc_primitives::{
|
|
errors::{RpcError, RpcErrorKind},
|
|
RpcPollingConfig,
|
|
};
|
|
use node_core::{config::NodeConfig, NodeCore};
|
|
use serde::Serialize;
|
|
use serde_json::Value;
|
|
|
|
pub use net_utils::*;
|
|
use tokio::sync::Mutex;
|
|
|
|
use self::types::err_rpc::RpcErr;
|
|
|
|
//ToDo: Add necessary fields
|
|
pub struct JsonHandler {
|
|
pub polling_config: RpcPollingConfig,
|
|
pub node_core_config: NodeConfig,
|
|
pub node_chain_store: Arc<Mutex<NodeCore>>,
|
|
}
|
|
|
|
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,
|
|
}
|
|
}
|