Skip to content

Commit

Permalink
webserver sleep till chain start
Browse files Browse the repository at this point in the history
  • Loading branch information
Gianmarco Fraccaroli committed Dec 18, 2023
1 parent 48955ac commit 2c72cd4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
12 changes: 11 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{
time::Duration,
};

use tokio::sync::RwLock;
use tokio::{sync::RwLock, time::sleep};

use axum::{
error_handling::HandleErrorLayer,
Expand Down Expand Up @@ -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();

Expand Down
6 changes: 0 additions & 6 deletions src/handler/faucet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ pub async fn faucet_settings(
pub async fn request_challenge(
State(mut state): State<FaucetState>,
) -> Result<Json<FaucetResponseDto>, 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)
Expand Down

0 comments on commit 2c72cd4

Please sign in to comment.