Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/utils/calc.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::utils::from_env::FromEnv;
use signet_constants::KnownChains;
use std::str::FromStr;

/// A slot calculator, which can calculate slot numbers, windows, and offsets
/// for a given chain.
Expand Down Expand Up @@ -273,6 +275,22 @@ impl SlotCalculator {
}
}

impl From<KnownChains> for SlotCalculator {
fn from(value: KnownChains) -> Self {
match value {
KnownChains::Pecorino => SlotCalculator::pecorino_host(),
}
}
}

impl FromStr for SlotCalculator {
type Err = signet_constants::ParseChainError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(SlotCalculator::from(KnownChains::from_str(s)?))
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down