Compare commits

..

No commits in common. "0625c2672a8dd670f52c8afae312eaad95a00b54" and "b74747d443d06c51da4dda75f7e06ed3369747ae" have entirely different histories.

2 changed files with 12 additions and 6 deletions

View File

@ -726,7 +726,7 @@ dependencies = [
] ]
[[package]] [[package]]
name = "mnemonic-hash-checker" name = "mnemonic-checker"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"axum", "axum",

View File

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