Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implementing ComponentRunner for the gateway #355

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}
5 changes: 3 additions & 2 deletions crates/tests-integration/src/integration_test_setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub struct IntegrationTestSetup {
}

impl IntegrationTestSetup {
pub async fn new(n_accounts: u16) -> Self {
pub async fn new(n_initialized_account_contracts: u16) -> Self {
let handle = Handle::current();
let task_executor = TokioExecutor::new(handle);

Expand All @@ -41,7 +41,8 @@ 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 = create_gateway(Arc::new(gateway_mempool_client), n_accounts).await;
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)));
let gateway_handle = task_executor.spawn_with_handle(async move {
Expand Down
Loading