Skip to content

Commit 6757e59

Browse files
committed
chore: simplify generics
1 parent 9a5a210 commit 6757e59

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed

crates/context/interface/src/result.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ impl<HaltReasonT> HaltReasonTrait for HaltReasonT where
1414

1515
#[derive(Debug, Clone, PartialEq, Eq)]
1616
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
17-
pub struct ResultAndState<HaltReasonT: HaltReasonTrait> {
17+
pub struct ResultAndState<HaltReasonT: HaltReasonTrait = HaltReason> {
1818
/// Status of execution
1919
pub result: ExecutionResult<HaltReasonT>,
2020
/// State that got updated
@@ -37,7 +37,7 @@ impl<HaltReasonT: HaltReasonTrait> ResultAndState<HaltReasonT> {
3737
/// Result of a transaction execution
3838
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
3939
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
40-
pub enum ExecutionResult<HaltReasonT: HaltReasonTrait> {
40+
pub enum ExecutionResult<HaltReasonT: HaltReasonTrait = HaltReason> {
4141
/// Returned successfully
4242
Success {
4343
reason: SuccessReason,
@@ -192,7 +192,7 @@ impl Output {
192192
/// Main EVM error
193193
#[derive(Debug, Clone, PartialEq, Eq)]
194194
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
195-
pub enum EVMError<DBError, TransactionError> {
195+
pub enum EVMError<DBError, TransactionError = InvalidTransaction> {
196196
/// Transaction validation error
197197
Transaction(TransactionError),
198198
/// Header validation error

crates/context/src/cfg.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::{vec, vec::Vec};
88
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
99
#[derive(Clone, Debug, Eq, PartialEq)]
1010
#[non_exhaustive]
11-
pub struct CfgEnv<SPEC: Into<SpecId> = SpecId> {
11+
pub struct CfgEnv<SPEC = SpecId> {
1212
/// Chain ID of the EVM
1313
///
1414
/// `chain_id` will be compared to the transaction's Chain ID.
@@ -77,7 +77,14 @@ pub struct CfgEnv<SPEC: Into<SpecId> = SpecId> {
7777
pub disable_base_fee: bool,
7878
}
7979

80-
impl<SPEC: Into<SpecId>> CfgEnv<SPEC> {
80+
impl CfgEnv {
81+
/// Creates new `CfgEnv` with default values.
82+
pub fn new() -> Self {
83+
Self::default()
84+
}
85+
}
86+
87+
impl<SPEC> CfgEnv<SPEC> {
8188
pub fn with_chain_id(mut self, chain_id: u64) -> Self {
8289
self.chain_id = chain_id;
8390
self
@@ -196,12 +203,12 @@ impl<SPEC: Into<SpecId> + Copy> Cfg for CfgEnv<SPEC> {
196203
}
197204
}
198205

199-
impl Default for CfgEnv {
206+
impl<SPEC: Default> Default for CfgEnv<SPEC> {
200207
fn default() -> Self {
201208
Self {
202209
chain_id: 1,
203210
limit_contract_code_size: None,
204-
spec: SpecId::PRAGUE,
211+
spec: Default::default(),
205212
disable_nonce_check: false,
206213
blob_target_and_max_count: vec![(SpecId::CANCUN, 3, 6), (SpecId::PRAGUE, 6, 9)],
207214
#[cfg(feature = "memory_limit")]
@@ -226,7 +233,7 @@ mod test {
226233

227234
#[test]
228235
fn blob_max_and_target_count() {
229-
let cfg = CfgEnv::default();
236+
let cfg: CfgEnv = Default::default();
230237
assert_eq!(cfg.blob_max_count(SpecId::BERLIN), (6));
231238
assert_eq!(cfg.blob_max_count(SpecId::CANCUN), (6));
232239
assert_eq!(cfg.blob_max_count(SpecId::PRAGUE), (9));

crates/optimism/src/api/into_optimism.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl DefaultOp
5252
fn default_op() -> Self {
5353
Context::default()
5454
.with_tx(OpTransaction::default())
55-
.with_cfg(CfgEnv::default().with_spec(OpSpec::Op(OpSpecId::BEDROCK)))
55+
.with_cfg(CfgEnv::new().with_spec(OpSpec::Op(OpSpecId::BEDROCK)))
5656
.with_chain(L1BlockInfo::default())
5757
}
5858
}

crates/optimism/src/context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl Default for OpContext {
3838
Self(
3939
Context::default()
4040
.with_tx(OpTransaction::default())
41-
.with_cfg(CfgEnv::default().with_spec(OpSpec::Op(OpSpecId::BEDROCK)))
41+
.with_cfg(CfgEnv::new().with_spec(OpSpec::Op(OpSpecId::BEDROCK)))
4242
.with_chain(L1BlockInfo::default()),
4343
)
4444
}
@@ -55,7 +55,7 @@ impl OpContext {
5555
> {
5656
Context::default()
5757
.with_tx(OpTransaction::default())
58-
.with_cfg(CfgEnv::default().with_spec(OpSpec::Op(OpSpecId::BEDROCK)))
58+
.with_cfg(CfgEnv::new().with_spec(OpSpec::Op(OpSpecId::BEDROCK)))
5959
.with_chain(L1BlockInfo::default())
6060
}
6161
}

0 commit comments

Comments
 (0)