From 2c72cd44584aa0f9d4865f2d07e04c5158097620 Mon Sep 17 00:00:00 2001 From: Gianmarco Fraccaroli <> Date: Mon, 18 Dec 2023 15:37:57 +0100 Subject: [PATCH] webserver sleep till chain start --- src/app.rs | 12 +++++++++++- src/handler/faucet.rs | 6 ------ 2 files changed, 11 insertions(+), 7 deletions(-) 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)