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 26, 2024
1 parent f6bd8aa commit eaac21e
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Cargo.lock

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

12 changes: 11 additions & 1 deletion crates/gateway/src/gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ use starknet_mempool_types::mempool_types::{Account, MempoolInput};
use starknet_sierra_compile::compile::{compile_sierra_to_casm, CompilationUtilError};
use starknet_sierra_compile::utils::into_contract_class_for_compilation;

use crate::config::{GatewayConfig, GatewayNetworkConfig};
use crate::config::{GatewayConfig, GatewayNetworkConfig, RpcStateReaderConfig};
use crate::errors::{GatewayError, GatewayRunError};
use crate::rpc_state_reader::RpcStateReaderFactory;
use crate::starknet_api_test_utils::get_sender_address;
use crate::state_reader::StateReaderFactory;
use crate::stateful_transaction_validator::StatefulTransactionValidator;
Expand Down Expand Up @@ -167,3 +168,12 @@ fn compile_contract_class(declare_tx: &RPCDeclareTransaction) -> GatewayResult<C
)?;
Ok(class_info)
}

pub fn create_gateway(
config: GatewayConfig,
rpc_state_reader_config: RpcStateReaderConfig,
client: SharedMempoolClient,
) -> Gateway {
let state_reader_factory = Arc::new(RpcStateReaderFactory { config: rpc_state_reader_config });
Gateway::new(config, state_reader_factory, client)
}
2 changes: 2 additions & 0 deletions crates/mempool_node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ workspace = true
clap.workspace = true
const_format.workspace = true
starknet_gateway = { path = "../gateway", 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
30 changes: 30 additions & 0 deletions crates/mempool_node/src/components.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use starknet_gateway::gateway::{create_gateway, Gateway};
use starknet_mempool::mempool::Mempool;

use crate::communication::MempoolNodeClients;
use crate::config::MempoolNodeConfig;

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

pub fn create_components(config: &MempoolNodeConfig, clients: &MempoolNodeClients) -> Components {
let gateway_component = if config.components.gateway_component.execute {
let mempool_clent =
clients.get_mempool_client().expect("Mempool Client should be available");

Some(create_gateway(
config.gateway_config.clone(),
config.rpc_state_reader_config.clone(),
mempool_clent,
))
} else {
None
};

let mempool_component =
if config.components.mempool_component.execute { Some(Mempool::empty()) } else { None };

Components { gateway: gateway_component, mempool: mempool_component }
}
2 changes: 2 additions & 0 deletions crates/mempool_node/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
pub mod communication;
pub mod components;
pub mod config;
pub mod version;

0 comments on commit eaac21e

Please sign in to comment.