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

chore: clean http server module #1499

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
4 changes: 2 additions & 2 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion crates/gateway/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ async-trait.workspace = true
axum.workspace = true
blockifier = { workspace = true, features = ["testing"] }
cairo-lang-starknet-classes.workspace = true
hyper.workspace = true
mempool_test_utils.workspace = true
papyrus_config.workspace = true
papyrus_network_types.workspace = true
Expand Down
7 changes: 0 additions & 7 deletions crates/gateway/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,6 @@ pub type StatelessTransactionValidatorResult<T> = Result<T, StatelessTransaction

pub type StatefulTransactionValidatorResult<T> = Result<T, GatewaySpecError>;

/// Errors originating from `[`Gateway::run`]` command, to be handled by infrastructure code.
#[derive(Debug, Error)]
pub enum GatewayRunError {
#[error(transparent)]
ServerStartupError(#[from] hyper::Error),
}

#[derive(Debug, Error)]
pub enum RPCStateReaderError {
#[error("Block not found for request {0}")]
Expand Down
3 changes: 2 additions & 1 deletion crates/http_server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ workspace = true

[dependencies]
axum.workspace = true
hyper.workspace = true
papyrus_config.workspace = true
serde.workspace = true
starknet_api.workspace = true
starknet_gateway.workspace = true
starknet_gateway_types.workspace = true
starknet_mempool_infra.workspace = true
thiserror.workspace = true
tracing.workspace = true
validator.workspace = true

Expand Down
7 changes: 7 additions & 0 deletions crates/http_server/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
use thiserror::Error;

/// Errors originating from `[`HttpServer::run`]` command.
#[derive(Debug, Error)]
pub enum HttpServerRunError {
#[error(transparent)]
ServerStartupError(#[from] hyper::Error),
}
17 changes: 4 additions & 13 deletions crates/http_server/src/http_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ use std::clone::Clone;
use std::net::SocketAddr;

use axum::extract::State;
use axum::routing::{get, post};
use axum::routing::post;
use axum::{async_trait, Json, Router};
use starknet_api::rpc_transaction::RpcTransaction;
use starknet_api::transaction::TransactionHash;
use starknet_gateway::errors::GatewayRunError;
use starknet_gateway_types::communication::SharedGatewayClient;
use starknet_gateway_types::errors::GatewaySpecError;
use starknet_gateway_types::gateway_types::GatewayInput;
Expand All @@ -16,6 +15,7 @@ use starknet_mempool_infra::errors::ComponentError;
use tracing::{error, info, instrument};

use crate::config::HttpServerConfig;
use crate::errors::HttpServerRunError;

#[cfg(test)]
#[path = "http_server_test.rs"]
Expand All @@ -39,8 +39,7 @@ impl HttpServer {
HttpServer { config, app_state }
}

// TODO(Tsabary/Lev): Rename "GatewayRunError" to "HttpServerRunError".
pub async fn run(&mut self) -> Result<(), GatewayRunError> {
pub async fn run(&mut self) -> Result<(), HttpServerRunError> {
// Parses the bind address from HttpServerConfig, returning an error for invalid addresses.
let HttpServerConfig { ip, port } = self.config;
let addr = SocketAddr::new(ip, port);
Expand All @@ -52,20 +51,12 @@ impl HttpServer {
}

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

// HttpServer handlers.

#[instrument]
async fn is_alive() -> HttpServerResult<String> {
unimplemented!("Future handling should be implemented here.");
}

#[instrument(skip(app_state))]
async fn add_tx(
State(app_state): State<AppState>,
Expand Down
Loading