referrerpolicy=no-referrer-when-downgrade
pallet_revive::evm

Trait GasEncoder

Source
pub trait GasEncoder<Balance>: Sealed {
    // Required methods
    fn encode(gas_limit: U256, weight: Weight, deposit: Balance) -> U256;
    fn decode(gas: U256) -> Option<(Weight, Balance)>;

    // Provided method
    fn as_encoded_values(weight: Weight, deposit: Balance) -> (Weight, Balance) { ... }
}
Expand description

Encodes/Decodes EVM gas values.

§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.

Required Methods§

Source

fn encode(gas_limit: U256, weight: Weight, deposit: Balance) -> U256

Encodes all components (deposit limit, weight reference time, and proof size) into a single gas value.

Source

fn decode(gas: U256) -> Option<(Weight, Balance)>

Decodes the weight and deposit from the encoded gas value. Returns None if the gas value is invalid

Provided Methods§

Source

fn as_encoded_values(weight: Weight, deposit: Balance) -> (Weight, Balance)

Returns the encoded values of the specified weight and deposit.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<Balance> GasEncoder<Balance> for ()
where Balance: Zero + One + CheckedShl + Into<u128>,

Source§

fn encode(gas_limit: U256, weight: Weight, deposit: Balance) -> U256

The encoding follows the pattern g...grrppdd, where:

  • dd: log2 Deposit value, encoded in the lowest 2 digits.
  • pp: log2 Proof size, encoded in the next 2 digits.
  • rr: log2 Reference time, encoded in the next 2 digits.
  • g...g: Gas limit, encoded in the highest digits.
§Note
  • The deposit value is maxed by 2^99 for u128 balance, and 2^63 for u64 balance.
Source§

fn decode(gas: U256) -> Option<(Weight, Balance)>

Implementors§