2024-09-30 05:49:46 +03:00
|
|
|
pub mod net_utils;
|
|
|
|
|
pub mod process;
|
|
|
|
|
pub mod types;
|
|
|
|
|
|
2024-11-28 22:05:14 +02:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
2025-11-18 19:31:03 +03:00
|
|
|
use common::{
|
2025-11-20 15:34:44 +03:00
|
|
|
rpc_primitives::errors::{RpcError, RpcErrorKind},
|
2026-01-29 22:20:42 +03:00
|
|
|
transaction::NSSATransaction,
|
2024-09-30 05:49:46 +03:00
|
|
|
};
|
2025-11-18 19:31:03 +03:00
|
|
|
use mempool::MemPoolHandle;
|
2025-11-26 00:27:20 +03:00
|
|
|
pub use net_utils::*;
|
2026-01-29 22:20:42 +03:00
|
|
|
use sequencer_core::{
|
|
|
|
|
SequencerCore,
|
|
|
|
|
block_settlement_client::{BlockSettlementClient, BlockSettlementClientTrait},
|
|
|
|
|
indexer_client::{IndexerClient, IndexerClientTrait},
|
|
|
|
|
};
|
2024-09-30 05:49:46 +03:00
|
|
|
use serde::Serialize;
|
|
|
|
|
use serde_json::Value;
|
2024-11-28 22:05:14 +02:00
|
|
|
use tokio::sync::Mutex;
|
2024-09-30 05:49:46 +03:00
|
|
|
|
|
|
|
|
use self::types::err_rpc::RpcErr;
|
|
|
|
|
|
2025-11-26 00:27:20 +03:00
|
|
|
// ToDo: Add necessary fields
|
2026-01-29 22:20:42 +03:00
|
|
|
pub struct JsonHandler<
|
|
|
|
|
BC: BlockSettlementClientTrait = BlockSettlementClient,
|
|
|
|
|
IC: IndexerClientTrait = IndexerClient,
|
|
|
|
|
> {
|
|
|
|
|
sequencer_state: Arc<Mutex<SequencerCore<BC, IC>>>,
|
|
|
|
|
mempool_handle: MemPoolHandle<NSSATransaction>,
|
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,
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-02-17 18:33:29 -03:00
|
|
|
|
|
|
|
|
#[cfg(feature = "standalone")]
|
|
|
|
|
use sequencer_core::mock::{MockBlockSettlementClient, MockIndexerClient};
|
|
|
|
|
|
|
|
|
|
#[cfg(feature = "standalone")]
|
|
|
|
|
pub type JsonHandlerWithMockClients = JsonHandler<MockBlockSettlementClient, MockIndexerClient>;
|