Skip to content

Commit

Permalink
fix: const fns
Browse files Browse the repository at this point in the history
  • Loading branch information
prestwich committed Dec 26, 2023
1 parent 356efb4 commit ee68856
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion crates/consensus/src/pure/eip4844.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::constants::eip4844::{
/// See also [the EIP-4844 helpers](https://eips.ethereum.org/EIPS/eip-4844#helpers
/// (`calc_excess_blob_gas`).
#[inline]
pub fn calc_excess_blob_gas(parent_excess_blob_gas: u64, parent_blob_gas_used: u64) -> u64 {
pub const fn calc_excess_blob_gas(parent_excess_blob_gas: u64, parent_blob_gas_used: u64) -> u64 {
(parent_excess_blob_gas + parent_blob_gas_used).saturating_sub(TARGET_DATA_GAS_PER_BLOCK)
}

Expand Down
8 changes: 4 additions & 4 deletions crates/consensus/src/transaction/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub enum TxKind {

impl TxKind {
/// Returns the address of the contract that will be called or will receive the transfer.
pub fn to(self) -> Option<Address> {
pub const fn to(self) -> Option<Address> {
match self {
TxKind::Create => None,
TxKind::Call(to) => Some(to),
Expand All @@ -23,19 +23,19 @@ impl TxKind {

/// Returns true if the transaction is a contract creation.
#[inline]
pub fn is_create(self) -> bool {
pub const fn is_create(self) -> bool {
matches!(self, TxKind::Create)
}

/// Returns true if the transaction is a contract call.
#[inline]
pub fn is_call(self) -> bool {
pub const fn is_call(self) -> bool {
matches!(self, TxKind::Call(_))
}

/// Calculates a heuristic for the in-memory size of the [TransactionKind].
#[inline]
pub(crate) fn size(self) -> usize {
pub(crate) const fn size(self) -> usize {
std::mem::size_of::<Self>()
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/consensus/src/transaction/eip1559.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub struct TxEip1559 {

impl TxEip1559 {
/// Returns the effective gas price for the given `base_fee`.
pub fn effective_gas_price(&self, base_fee: Option<u64>) -> u128 {
pub const fn effective_gas_price(&self, base_fee: Option<u64>) -> u128 {
match base_fee {
None => self.max_fee_per_gas,
Some(base_fee) => {
Expand Down Expand Up @@ -163,7 +163,7 @@ impl TxEip1559 {
}

/// Get transaction type
pub(crate) fn tx_type(&self) -> TxType {
pub(crate) const fn tx_type(&self) -> TxType {
TxType::Eip1559
}

Expand Down
2 changes: 1 addition & 1 deletion crates/consensus/src/transaction/eip2930.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ impl TxEip2930 {
}

/// Get transaction type.
pub fn tx_type(&self) -> TxType {
pub const fn tx_type(&self) -> TxType {
TxType::Eip2930
}

Expand Down
2 changes: 1 addition & 1 deletion crates/consensus/src/transaction/envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl From<Signed<TxEip1559>> for TxEnvelope {

impl TxEnvelope {
/// Return the [`TxType`] of the inner txn.
pub fn tx_type(&self) -> TxType {
pub const fn tx_type(&self) -> TxType {
match self {
TxEnvelope::Legacy(_) | TxEnvelope::TaggedLegacy(_) => TxType::Legacy,
TxEnvelope::Eip2930(_) => TxType::Eip2930,
Expand Down

0 comments on commit ee68856

Please sign in to comment.