starknet_devnet_server/api/
mod.rs

1pub mod serde_helpers;
2
3use std::sync::Arc;
4
5use starknet_core::starknet::Starknet;
6use starknet_core::starknet::starknet_config::StarknetConfig;
7use tokio::sync::Mutex;
8use tracing::error;
9
10use crate::ServerConfig;
11use crate::dump_util::DumpEvent;
12use crate::subscribe::SocketCollection;
13
14mod account_helpers;
15mod endpoints;
16mod endpoints_ws;
17pub mod error;
18pub mod json_rpc_handler;
19pub mod models;
20pub(crate) mod origin_forwarder;
21#[cfg(test)]
22mod spec_reader;
23mod write_endpoints;
24
25pub use json_rpc_handler::JsonRpcHandler;
26pub const RPC_SPEC_VERSION: &str = "0.10.0";
27
28use error::ApiError;
29
30/// Data that can be shared between threads with read write lock access
31/// Whatever needs to be accessed as information outside of Starknet could be added to this struct
32#[derive(Clone)]
33pub struct Api {
34    pub config: Arc<StarknetConfig>,
35    pub server_config: Arc<ServerConfig>,
36    pub starknet: Arc<Mutex<Starknet>>,
37    pub dumpable_events: Arc<Mutex<Vec<DumpEvent>>>,
38    pub sockets: Arc<Mutex<SocketCollection>>,
39}
40
41impl Api {
42    pub fn new(starknet: Starknet, server_config: ServerConfig) -> Self {
43        Self {
44            config: Arc::new(starknet.config.clone()),
45            server_config: Arc::new(server_config),
46            starknet: Arc::new(Mutex::new(starknet)),
47            dumpable_events: Default::default(),
48            sockets: Arc::new(Mutex::new(SocketCollection::default())),
49        }
50    }
51}