Skip to content

Commit

Permalink
Seal trait and add comment
Browse files Browse the repository at this point in the history
  • Loading branch information
pgherveou committed Jan 13, 2025
1 parent 11872c9 commit e9027cc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
16 changes: 15 additions & 1 deletion substrate/frame/revive/src/evm/gas_encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,22 @@ where
.unwrap_or(0) as u128
}

mod private {
pub trait Sealed {}
impl Sealed for () {}
}

/// Encodes/Decodes EVM gas values.
pub trait GasEncoder<Balance> {
///
/// # Note
///
/// This is defined as a trait rather than standalone functions to allow
/// it to be added as an associated type to [`crate::Config`]. This way,
/// it can be invoked without requiring the implementation bounds to be
/// explicitly specified.
///
/// This trait is sealed and cannot be implemented by downstream crates.
pub trait GasEncoder<Balance>: private::Sealed {
/// Encodes all components (deposit limit, weight reference time, and proof size) into a single
/// gas value.
fn encode(gas_limit: U256, weight: Weight, deposit: Balance) -> U256;
Expand Down
3 changes: 2 additions & 1 deletion substrate/frame/revive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,8 @@ pub mod pallet {
#[pallet::constant]
type NativeToEthRatio: Get<u32>;

/// Encode and decode Ethereum gas values. See [`GasEncoder`].
/// Encode and decode Ethereum gas values.
/// Only valid value is `()`. See [`GasEncoder`].
#[pallet::no_default_bounds]
type EthGasEncoder: GasEncoder<BalanceOf<Self>>;
}
Expand Down

0 comments on commit e9027cc

Please sign in to comment.