diff --git a/mnemonic-hash-checker/src/main.rs b/mnemonic-hash-checker/src/main.rs index f172472..dbff0ed 100644 --- a/mnemonic-hash-checker/src/main.rs +++ b/mnemonic-hash-checker/src/main.rs @@ -1,7 +1,7 @@ use std::net::SocketAddr; use std::sync::Arc; -use axum::{extract::Path, routing::get, Extension, Json, Router}; +use axum::{extract::{Path, State}, routing::get, Json, Router}; use color_eyre::eyre::Result; @@ -17,10 +17,6 @@ use tracing_subscriber::prelude::*; use tracing::{debug, info}; -struct State { - pool: Pool, -} - fn setup_registry() { let envfilter = EnvFilter::builder() .with_default_directive(LevelFilter::DEBUG.into()) @@ -48,12 +44,12 @@ async fn check_hash(hash: &str, pool: &Pool) -> Result { } // Note: Exposes *zero* information of potential errors to clients. -#[tracing::instrument(skip(hash, state))] +#[tracing::instrument(skip(hash, pool))] async fn check_hash_slug( Path(hash): Path, - Extension(state): Extension>, + State(pool): State>, ) -> Json> { - let result = check_hash(&hash, &state.pool).await; + let result = check_hash(&hash, &pool).await; if let Err(e) = &result { debug!(%e, "Error while performing lookup"); } @@ -77,12 +73,10 @@ async fn main() -> Result<()> { }); let pool = config.create_pool(Some(Runtime::Tokio1), NoTls)?; - let state = State { pool }; - let app = Router::new() .route("/check/:hash", get(check_hash_slug)) + .with_state(Arc::new(pool)) .layer(CatchPanicLayer::new()) - .layer(Extension(Arc::new(state))) .layer(TraceLayer::new_for_http()); info!("server go nyoom");