Skip to content

Commit

Permalink
feat: add functionality to create all components
Browse files Browse the repository at this point in the history
commit-id:bb128e01
  • Loading branch information
lev-starkware committed Jun 24, 2024
1 parent 682e7c1 commit 7f40a03
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions crates/gateway/src/gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,13 @@ fn process_tx(
account: Account { sender_address: get_sender_address(&tx), ..Default::default() },
})
}

pub fn create_gateway(config: GatewayConfig, client: Option<SharedMempoolClient>) -> Gateway {
if client.is_none() {
panic!("SharedMempoolClient is required to create Gateway.");
}

let state_reader_factory: Arc<dyn StateReaderFactory> =
Arc::new(crate::state_reader_test_utils::local_test_state_reader_factory());
Gateway::new(config, state_reader_factory, client.unwrap())
}
3 changes: 3 additions & 0 deletions crates/mempool_node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ workspace = true
clap.workspace = true
const_format.workspace = true
starknet_gateway = { path = "../gateway", version = "0.0" }
starknet_mempool_infra = { path = "../mempool_infra", version = "0.0" }
starknet_mempool = { path = "../mempool", version = "0.0" }
starknet_mempool_types = { path = "../mempool_types", version = "0.0" }
serde.workspace = true
papyrus_config.workspace = true
tokio.workspace = true
Expand Down
22 changes: 22 additions & 0 deletions crates/mempool_node/src/components.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use starknet_gateway::gateway::{create_gateway, Gateway};
use starknet_mempool::mempool::Mempool;

use crate::com_clients::CommClients;
use crate::config::MempoolNodeConfig;

pub struct Components {
pub gateway: Option<Gateway>,
pub mempool: Option<Mempool>,
}

pub fn create_components(config: &MempoolNodeConfig, clients: &CommClients) -> Components {
let mut components = Components { gateway: None, mempool: None };
if config.components.gateway_component.execute {
components.gateway =
Some(create_gateway(config.gateway_config.clone(), clients.mempool_client.clone()));
}
if config.components.mempool_component.execute {
components.mempool = Some(Mempool::empty());
}
components
}
3 changes: 3 additions & 0 deletions crates/mempool_node/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
pub mod com_clients;
pub mod communication;
pub mod components;
pub mod config;
pub mod version;

0 comments on commit 7f40a03

Please sign in to comment.