diff --git a/src/app.rs b/src/app.rs index e35a5bd..3e175ee 100644 --- a/src/app.rs +++ b/src/app.rs @@ -5,7 +5,7 @@ use std::{ time::Duration, }; -use tokio::sync::RwLock; +use tokio::{sync::RwLock, time::sleep}; use axum::{ error_handling::HandleErrorLayer, @@ -66,6 +66,16 @@ impl ApplicationServer { let pk = sk.ref_to(); let address = Address::from(&pk); + loop { + let current_timestamp = chrono::offset::Utc::now().timestamp(); + if current_timestamp > chain_start { + break; + } else { + tracing::info!("Sleeping until: {}", current_timestamp); + sleep(Duration::from_secs(60)).await; + } + }; + let url = Url::from_str(&rpc).expect("invalid RPC address"); let http_client = HttpClient::new(url).unwrap(); diff --git a/src/handler/faucet.rs b/src/handler/faucet.rs index d90f737..b1fe4b3 100644 --- a/src/handler/faucet.rs +++ b/src/handler/faucet.rs @@ -39,12 +39,6 @@ pub async fn faucet_settings( pub async fn request_challenge( State(mut state): State, ) -> Result, ApiError> { - let current_timestamp = chrono::offset::Utc::now().timestamp(); - - if current_timestamp < state.chain_start { - return Err(FaucetError::ChainNotStarted.into()); - } - let faucet_request = state .faucet_service .generate_faucet_request(state.auth_key)