Skip to content

Commit

Permalink
Merge pull request #53 from scroll-tech/master
Browse files Browse the repository at this point in the history
feat: adding gasUsed in block header (#50)
  • Loading branch information
i-m-aditya authored Sep 9, 2024
2 parents a68cbb6 + f5df984 commit 171c724
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
7 changes: 7 additions & 0 deletions crates/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ pub trait Block: Debug {
/// Get gas limit
fn gas_limit(&self) -> U256;

/// Get gas used
fn gas_used(&self) -> U256;

/// Get base fee per gas
fn base_fee_per_gas(&self) -> Option<U256>;

Expand Down Expand Up @@ -292,6 +295,10 @@ impl<T: Block> Block for &T {
(*self).gas_limit()
}

fn gas_used(&self) -> U256 {
(*self).gas_used()
}

fn base_fee_per_gas(&self) -> Option<U256> {
(*self).base_fee_per_gas()
}
Expand Down
11 changes: 11 additions & 0 deletions crates/primitives/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ struct BlockHeader {
/// gas limit
#[serde(rename = "gasLimit")]
gas_limit: U256,
/// gas used
#[serde(rename = "gasUsed")]
gas_used: U256,
/// base fee per gas
#[serde(rename = "baseFeePerGas")]
base_fee_per_gas: Option<U256>,
Expand Down Expand Up @@ -136,6 +139,10 @@ impl Block for BlockTrace {
self.header.gas_limit
}

fn gas_used(&self) -> U256 {
self.header.gas_used
}

fn base_fee_per_gas(&self) -> Option<U256> {
self.header.base_fee_per_gas
}
Expand Down Expand Up @@ -207,6 +214,10 @@ impl Block for ArchivedBlockTrace {
self.header.gas_limit
}

fn gas_used(&self) -> U256 {
self.header.gas_used
}

fn base_fee_per_gas(&self) -> Option<U256> {
self.header.base_fee_per_gas.as_ref().copied()
}
Expand Down

0 comments on commit 171c724

Please sign in to comment.