Skip to content

Commit f93ca34

Browse files
authored
feat: constants from chain_name env var (#72)
1 parent f22abd3 commit f93ca34

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ name = "init4-bin-base"
44
description = "Internal utilities for binaries produced by the init4 team"
55
keywords = ["init4", "bin", "base"]
66

7-
version = "0.12.4"
7+
version = "0.12.5"
88
edition = "2021"
99
rust-version = "1.83"
1010
authors = ["init4", "James Prestwich", "evalir"]

src/utils/calc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ impl SlotCalculator {
263263
}
264264

265265
impl FromEnv for SlotCalculator {
266-
type Error = FromEnvErr<ParseIntError>;
266+
type Error = ParseIntError;
267267

268268
fn inventory() -> Vec<&'static EnvItemInfo> {
269269
vec![

src/utils/from_env.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use signet_constants::{
2-
HostConstants, RollupConstants, SignetConstants, SignetEnvironmentConstants,
2+
HostConstants, ParseChainError, RollupConstants, SignetConstants, SignetEnvironmentConstants,
33
SignetSystemConstants,
44
};
55
use std::{convert::Infallible, env::VarError, num::ParseIntError, str::FromStr};
@@ -670,6 +670,23 @@ impl FromEnvVar for tracing::Level {
670670
}
671671
}
672672

673+
impl FromEnv for SignetSystemConstants {
674+
type Error = ParseChainError;
675+
676+
fn inventory() -> Vec<&'static EnvItemInfo> {
677+
vec![&EnvItemInfo {
678+
var: "CHAIN_NAME",
679+
description:
680+
"The name of the chain. If set, the other environment variables are ignored.",
681+
optional: true,
682+
}]
683+
}
684+
685+
fn from_env() -> Result<Self, FromEnvErr<Self::Error>> {
686+
SignetSystemConstants::from_env_var("CHAIN_NAME")
687+
}
688+
}
689+
673690
#[cfg(test)]
674691
mod test {
675692
use std::{borrow::Cow, time::Duration};

0 commit comments

Comments
 (0)