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-03-04 18:42:33 +03:00
|
|
|
#[cfg(feature = "standalone")]
|
|
|
|
|
use sequencer_core::mock::{MockBlockSettlementClient, MockIndexerClient};
|
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;
|
|
|
|
|
|
2026-03-04 18:42:33 +03:00
|
|
|
pub mod net_utils;
|
|
|
|
|
pub mod process;
|
|
|
|
|
pub mod types;
|
|
|
|
|
|
|
|
|
|
#[cfg(feature = "standalone")]
|
|
|
|
|
pub type JsonHandlerWithMockClients = JsonHandler<MockBlockSettlementClient, MockIndexerClient>;
|
|
|
|
|
|
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>,
|
2026-02-24 19:41:01 +03:00
|
|
|
max_block_size: usize,
|
2024-09-30 05:49:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn respond<T: Serialize>(val: T) -> Result<Value, RpcErr> {
|
|
|
|
|
Ok(serde_json::to_value(val)?)
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-03 23:21:08 +03:00
|
|
|
#[must_use]
|
2024-09-30 05:49:46 +03:00
|
|
|
pub fn rpc_error_responce_inverter(err: RpcError) -> RpcError {
|
2026-03-09 18:27:56 +03:00
|
|
|
let content = err.error_struct.map(|error| match error {
|
|
|
|
|
RpcErrorKind::HandlerError(val) | RpcErrorKind::InternalError(val) => val,
|
|
|
|
|
RpcErrorKind::RequestValidationError(vall) => serde_json::to_value(vall).unwrap(),
|
|
|
|
|
});
|
2024-09-30 05:49:46 +03:00
|
|
|
RpcError {
|
|
|
|
|
error_struct: None,
|
|
|
|
|
code: err.code,
|
|
|
|
|
message: err.message,
|
|
|
|
|
data: content,
|
|
|
|
|
}
|
|
|
|
|
}
|