Skip to content

Commit 7b33786

Browse files
authored
Merge branch 'main' into evalir/readd-pecorino
2 parents 77748cb + 0dd5b37 commit 7b33786

File tree

5 files changed

+66
-24
lines changed

5 files changed

+66
-24
lines changed

crates/constants/src/types/environment.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,10 @@ impl SignetEnvironmentConstants {
4949
}
5050
}
5151

52-
impl FromStr for SignetEnvironmentConstants {
53-
type Err = ParseChainError;
52+
impl TryFrom<KnownChains> for SignetEnvironmentConstants {
53+
type Error = ParseChainError;
5454

55-
fn from_str(s: &str) -> Result<Self, Self::Err> {
56-
let chain: KnownChains = s.parse()?;
55+
fn try_from(chain: KnownChains) -> Result<Self, Self::Error> {
5756
match chain {
5857
KnownChains::Pecorino => Ok(Self::pecorino()),
5958
#[cfg(any(test, feature = "test-utils"))]
@@ -62,6 +61,14 @@ impl FromStr for SignetEnvironmentConstants {
6261
}
6362
}
6463

64+
impl FromStr for SignetEnvironmentConstants {
65+
type Err = ParseChainError;
66+
67+
fn from_str(s: &str) -> Result<Self, Self::Err> {
68+
s.parse::<KnownChains>()?.try_into()
69+
}
70+
}
71+
6572
#[cfg(test)]
6673
mod test {
6774
use super::*;

crates/constants/src/types/mod.rs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -221,11 +221,10 @@ impl SignetSystemConstants {
221221
}
222222
}
223223

224-
impl FromStr for SignetSystemConstants {
225-
type Err = ParseChainError;
224+
impl TryFrom<KnownChains> for SignetSystemConstants {
225+
type Error = ParseChainError;
226226

227-
fn from_str(s: &str) -> Result<Self, Self::Err> {
228-
let chain: KnownChains = s.parse()?;
227+
fn try_from(chain: KnownChains) -> Result<Self, Self::Error> {
229228
match chain {
230229
KnownChains::Pecorino => Ok(Self::pecorino()),
231230
#[cfg(any(test, feature = "test-utils"))]
@@ -234,6 +233,14 @@ impl FromStr for SignetSystemConstants {
234233
}
235234
}
236235

236+
impl FromStr for SignetSystemConstants {
237+
type Err = ParseChainError;
238+
239+
fn from_str(s: &str) -> Result<Self, Self::Err> {
240+
s.parse::<KnownChains>()?.try_into()
241+
}
242+
}
243+
237244
/// All constants pertaining to the Signet system.
238245
#[derive(Debug, Clone, PartialEq, Eq)]
239246
pub struct SignetConstants {
@@ -284,15 +291,22 @@ impl SignetConstants {
284291
}
285292
}
286293

287-
impl FromStr for SignetConstants {
288-
type Err = ParseChainError;
294+
impl TryFrom<KnownChains> for SignetConstants {
295+
type Error = ParseChainError;
289296

290-
fn from_str(s: &str) -> Result<Self, Self::Err> {
291-
let chain: KnownChains = s.parse()?;
297+
fn try_from(chain: KnownChains) -> Result<Self, Self::Error> {
292298
match chain {
293299
KnownChains::Pecorino => Ok(Self::pecorino()),
294300
#[cfg(any(test, feature = "test-utils"))]
295301
KnownChains::Test => Ok(Self::test()),
296302
}
297303
}
298304
}
305+
306+
impl FromStr for SignetConstants {
307+
type Err = ParseChainError;
308+
309+
fn from_str(s: &str) -> Result<Self, Self::Err> {
310+
s.parse::<KnownChains>()?.try_into()
311+
}
312+
}

crates/constants/src/types/rollup.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,22 @@ impl RollupConstants {
107107
}
108108
}
109109

110-
impl FromStr for RollupConstants {
111-
type Err = ParseChainError;
110+
impl TryFrom<KnownChains> for RollupConstants {
111+
type Error = ParseChainError;
112112

113-
fn from_str(s: &str) -> Result<Self, Self::Err> {
114-
let chain: KnownChains = s.parse()?;
113+
fn try_from(chain: KnownChains) -> Result<Self, Self::Error> {
115114
match chain {
116115
KnownChains::Pecorino => Ok(Self::pecorino()),
117116
#[cfg(any(test, feature = "test-utils"))]
118117
KnownChains::Test => Ok(Self::test()),
119118
}
120119
}
121120
}
121+
122+
impl FromStr for RollupConstants {
123+
type Err = ParseChainError;
124+
125+
fn from_str(s: &str) -> Result<Self, Self::Err> {
126+
s.parse::<KnownChains>()?.try_into()
127+
}
128+
}

crates/test-utils/src/specs/host_spec.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -411,18 +411,25 @@ impl HostBlockSpec {
411411
}
412412
}
413413

414-
impl FromStr for HostBlockSpec {
415-
type Err = ParseChainError;
414+
impl TryFrom<KnownChains> for HostBlockSpec {
415+
type Error = ParseChainError;
416416

417-
fn from_str(s: &str) -> Result<Self, Self::Err> {
418-
let chain: KnownChains = s.parse()?;
417+
fn try_from(chain: KnownChains) -> Result<Self, Self::Error> {
419418
match chain {
420419
KnownChains::Pecorino => Ok(Self::pecorino()),
421420
KnownChains::Test => Ok(Self::test()),
422421
}
423422
}
424423
}
425424

425+
impl FromStr for HostBlockSpec {
426+
type Err = ParseChainError;
427+
428+
fn from_str(s: &str) -> Result<Self, Self::Err> {
429+
s.parse::<KnownChains>()?.try_into()
430+
}
431+
}
432+
426433
fn to_receipt<T>(address: Address, t: &T) -> ReceiptEnvelope
427434
where
428435
for<'a> &'a T: Into<LogData>,

crates/test-utils/src/specs/ru_spec.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,21 @@ impl RuBlockSpec {
146146
}
147147
}
148148

149-
impl FromStr for RuBlockSpec {
150-
type Err = ParseChainError;
149+
impl TryFrom<KnownChains> for RuBlockSpec {
150+
type Error = ParseChainError;
151151

152-
fn from_str(s: &str) -> Result<Self, Self::Err> {
153-
let chain: KnownChains = s.parse()?;
152+
fn try_from(chain: KnownChains) -> Result<Self, Self::Error> {
154153
match chain {
155154
KnownChains::Pecorino => Ok(Self::pecorino()),
156155
KnownChains::Test => Ok(Self::test()),
157156
}
158157
}
159158
}
159+
160+
impl FromStr for RuBlockSpec {
161+
type Err = ParseChainError;
162+
163+
fn from_str(s: &str) -> Result<Self, Self::Err> {
164+
s.parse::<KnownChains>()?.try_into()
165+
}
166+
}

0 commit comments

Comments
 (0)