Skip to content

Commit

Permalink
feat: implementing ComponentRunner for the gateway
Browse files Browse the repository at this point in the history
commit-id:f9f21462
  • Loading branch information
lev-starkware committed Jul 4, 2024
1 parent 0075bb3 commit b943062
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
9 changes: 4 additions & 5 deletions crates/gateway/src/gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl Gateway {
Gateway { config, app_state }
}

pub async fn run(self) -> Result<(), GatewayRunError> {
pub async fn run(&mut self) -> Result<(), GatewayRunError> {
// Parses the bind address from GatewayConfig, returning an error for invalid addresses.
let GatewayNetworkConfig { ip, port } = self.config.network_config;
let addr = SocketAddr::new(ip, port);
Expand All @@ -67,11 +67,11 @@ impl Gateway {
Ok(axum::Server::bind(&addr).serve(app.into_make_service()).await?)
}

pub fn app(self) -> Router {
pub fn app(&self) -> Router {
Router::new()
.route("/is_alive", get(is_alive))
.route("/add_tx", post(add_tx))
.with_state(self.app_state)
.with_state(self.app_state.clone())
}
}

Expand Down Expand Up @@ -146,8 +146,7 @@ pub fn create_gateway(
#[async_trait]
impl ComponentRunner for Gateway {
async fn start(&mut self) -> Result<(), ComponentStartError> {
// TODO(Lev, 23/07/2024): Implement the real logic.
println!("Gateway::start()");
Ok(())
self.run().await.map_err(|_| ComponentStartError::InternalComponentError)
}
}
2 changes: 1 addition & 1 deletion crates/tests-integration/src/integration_test_setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl IntegrationTestSetup {
channel::<MempoolRequestAndResponseSender>(MEMPOOL_INVOCATIONS_QUEUE_SIZE);
// Build and run gateway; initialize a gateway client.
let gateway_mempool_client = MempoolClientImpl::new(tx_mempool.clone());
let gateway =
let mut gateway =
create_gateway(Arc::new(gateway_mempool_client), n_initialized_account_contracts).await;
let GatewayNetworkConfig { ip, port } = gateway.config.network_config;
let gateway_client = GatewayClient::new(SocketAddr::from((ip, port)));
Expand Down

0 comments on commit b943062

Please sign in to comment.