-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Read blockchain timeouts from ENV (#317)
* read timeouts from ENV * update Rust version * new version for release Co-authored-by: sostrovskyi <sostrovskyi>
- Loading branch information
Showing
6 changed files
with
47 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use std::{env, ffi::OsStr, time::Duration}; | ||
|
||
fn parse_duration(raw_str: impl AsRef<str>) -> anyhow::Result<Duration> { | ||
raw_str | ||
.as_ref() | ||
.parse::<f64>() | ||
.map_err(anyhow::Error::from) | ||
.map(Duration::try_from_secs_f64)? | ||
.map_err(anyhow::Error::from) | ||
} | ||
|
||
/// Parses [`Duration`] from env var or returns default if env var isn't set | ||
/// | ||
/// Respects `Err` context in case of parsing/validation error | ||
pub fn env_var_as_duration_or( | ||
key: impl AsRef<OsStr>, | ||
default: Duration, | ||
) -> anyhow::Result<Duration> { | ||
match env::var(&key) { | ||
Err(_) => Ok(default), | ||
Ok(raw_str) => parse_duration(raw_str).map_err(|err| { | ||
err.context(format!( | ||
"env {} can't be parsed as Duration (try positive float)", | ||
key.as_ref().to_string_lossy() | ||
)) | ||
}), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod env; | ||
use crate::{blockchain::BlockchainContractAddress, config::Config}; | ||
|
||
#[derive(Debug, Clone)] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"version": "3.0.6" | ||
"version": "3.0.7" | ||
} |