Skip to content

Commit 3617014

Browse files
committed
relex generic for some Cfg functions
1 parent 6e69a27 commit 3617014

File tree

1 file changed

+44
-42
lines changed

1 file changed

+44
-42
lines changed

crates/context/src/cfg.rs

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -139,32 +139,7 @@ impl CfgEnv {
139139
}
140140
}
141141

142-
impl<SPEC: Into<SpecId> + Clone> CfgEnv<SPEC> {
143-
/// Returns the blob base fee update fraction from [CfgEnv::blob_base_fee_update_fraction].
144-
///
145-
/// If this field is not set, return the default value for the spec.
146-
///
147-
/// Default values for Cancun is [`primitives::eip4844::BLOB_BASE_FEE_UPDATE_FRACTION_CANCUN`]
148-
/// and for Prague is [`primitives::eip4844::BLOB_BASE_FEE_UPDATE_FRACTION_PRAGUE`].
149-
pub fn blob_base_fee_update_fraction(&mut self) -> u64 {
150-
self.blob_base_fee_update_fraction.unwrap_or_else(|| {
151-
let spec: SpecId = self.spec.clone().into();
152-
if spec.is_enabled_in(SpecId::PRAGUE) {
153-
primitives::eip4844::BLOB_BASE_FEE_UPDATE_FRACTION_PRAGUE
154-
} else {
155-
primitives::eip4844::BLOB_BASE_FEE_UPDATE_FRACTION_CANCUN
156-
}
157-
})
158-
}
159-
160-
/// Create new `CfgEnv` with default values and specified spec.
161-
/// It will create a new gas params based on mainnet spec.
162-
///
163-
/// Internally it will call [`CfgEnv::new_with_spec_and_gas_params`] with the mainnet gas params.
164-
pub fn new_with_spec(spec: SPEC) -> Self {
165-
Self::new_with_spec_and_gas_params(spec.clone(), GasParams::new_spec(spec.into()))
166-
}
167-
142+
impl<SPEC> CfgEnv<SPEC> {
168143
/// Create new `CfgEnv` with default values and specified spec.
169144
pub fn new_with_spec_and_gas_params(spec: SPEC, gas_params: GasParams) -> Self {
170145
Self {
@@ -218,27 +193,12 @@ impl<SPEC: Into<SpecId> + Clone> CfgEnv<SPEC> {
218193
self
219194
}
220195

221-
/// Sets the gas params for the `CfgEnv` to the mainnet gas params.
222-
///
223-
/// If spec gets changed, calling this function would use this spec to set the mainnetF gas params.
224-
pub fn with_mainnet_gas_params(mut self) -> Self {
225-
self.set_gas_params(GasParams::new_spec(self.spec.clone().into()));
226-
self
227-
}
228-
229196
/// Sets the spec for the `CfgEnv`.
230197
#[inline]
231198
pub fn set_spec(&mut self, spec: SPEC) {
232199
self.spec = spec;
233200
}
234201

235-
/// Sets the spec for the `CfgEnv` and the gas params to the mainnet gas params.
236-
#[inline]
237-
pub fn set_spec_and_mainnet_gas_params(&mut self, spec: SPEC) {
238-
self.set_spec(spec.clone());
239-
self.set_gas_params(GasParams::new_spec(spec.into()));
240-
}
241-
242202
/// Sets the gas params for the `CfgEnv`.
243203
#[inline]
244204
pub fn set_gas_params(&mut self, gas_params: GasParams) {
@@ -354,6 +314,48 @@ impl<SPEC: Into<SpecId> + Clone> CfgEnv<SPEC> {
354314
}
355315
}
356316

317+
impl<SPEC: Into<SpecId> + Clone> CfgEnv<SPEC> {
318+
/// Returns the blob base fee update fraction from [CfgEnv::blob_base_fee_update_fraction].
319+
///
320+
/// If this field is not set, return the default value for the spec.
321+
///
322+
/// Default values for Cancun is [`primitives::eip4844::BLOB_BASE_FEE_UPDATE_FRACTION_CANCUN`]
323+
/// and for Prague is [`primitives::eip4844::BLOB_BASE_FEE_UPDATE_FRACTION_PRAGUE`].
324+
pub fn blob_base_fee_update_fraction(&mut self) -> u64 {
325+
self.blob_base_fee_update_fraction.unwrap_or_else(|| {
326+
let spec: SpecId = self.spec.clone().into();
327+
if spec.is_enabled_in(SpecId::PRAGUE) {
328+
primitives::eip4844::BLOB_BASE_FEE_UPDATE_FRACTION_PRAGUE
329+
} else {
330+
primitives::eip4844::BLOB_BASE_FEE_UPDATE_FRACTION_CANCUN
331+
}
332+
})
333+
}
334+
335+
/// Create new `CfgEnv` with default values and specified spec.
336+
/// It will create a new gas params based on mainnet spec.
337+
///
338+
/// Internally it will call [`CfgEnv::new_with_spec_and_gas_params`] with the mainnet gas params.
339+
pub fn new_with_spec(spec: SPEC) -> Self {
340+
Self::new_with_spec_and_gas_params(spec.clone(), GasParams::new_spec(spec.into()))
341+
}
342+
343+
/// Sets the gas params for the `CfgEnv` to the mainnet gas params.
344+
///
345+
/// If spec gets changed, calling this function would use this spec to set the mainnetF gas params.
346+
pub fn with_mainnet_gas_params(mut self) -> Self {
347+
self.set_gas_params(GasParams::new_spec(self.spec.clone().into()));
348+
self
349+
}
350+
351+
/// Sets the spec for the `CfgEnv` and the gas params to the mainnet gas params.
352+
#[inline]
353+
pub fn set_spec_and_mainnet_gas_params(&mut self, spec: SPEC) {
354+
self.set_spec(spec.clone());
355+
self.set_gas_params(GasParams::new_spec(spec.into()));
356+
}
357+
}
358+
357359
impl<SPEC: Into<SpecId> + Clone> Cfg for CfgEnv<SPEC> {
358360
type Spec = SPEC;
359361

@@ -502,7 +504,7 @@ impl<SPEC: Into<SpecId> + Clone> Cfg for CfgEnv<SPEC> {
502504
}
503505
}
504506

505-
impl<SPEC: Default + Into<SpecId> + Clone> Default for CfgEnv<SPEC> {
507+
impl<SPEC: Default + Into<SpecId>> Default for CfgEnv<SPEC> {
506508
fn default() -> Self {
507509
Self::new_with_spec_and_gas_params(
508510
SPEC::default(),

0 commit comments

Comments
 (0)