Skip to content

Commit f5df984

Browse files
i-m-adityaAditya Pandey
andauthored
feat: adding gasUsed in block header (#50)
Co-authored-by: Aditya Pandey <[email protected]>
1 parent be1f7d2 commit f5df984

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

crates/primitives/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ pub trait Block: Debug {
5858
/// Get gas limit
5959
fn gas_limit(&self) -> U256;
6060

61+
/// Get gas used
62+
fn gas_used(&self) -> U256;
63+
6164
/// Get base fee per gas
6265
fn base_fee_per_gas(&self) -> Option<U256>;
6366

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

298+
fn gas_used(&self) -> U256 {
299+
(*self).gas_used()
300+
}
301+
295302
fn base_fee_per_gas(&self) -> Option<U256> {
296303
(*self).base_fee_per_gas()
297304
}

crates/primitives/src/types/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ struct BlockHeader {
2222
/// gas limit
2323
#[serde(rename = "gasLimit")]
2424
gas_limit: U256,
25+
/// gas used
26+
#[serde(rename = "gasUsed")]
27+
gas_used: U256,
2528
/// base fee per gas
2629
#[serde(rename = "baseFeePerGas")]
2730
base_fee_per_gas: Option<U256>,
@@ -136,6 +139,10 @@ impl Block for BlockTrace {
136139
self.header.gas_limit
137140
}
138141

142+
fn gas_used(&self) -> U256 {
143+
self.header.gas_used
144+
}
145+
139146
fn base_fee_per_gas(&self) -> Option<U256> {
140147
self.header.base_fee_per_gas
141148
}
@@ -207,6 +214,10 @@ impl Block for ArchivedBlockTrace {
207214
self.header.gas_limit
208215
}
209216

217+
fn gas_used(&self) -> U256 {
218+
self.header.gas_used
219+
}
220+
210221
fn base_fee_per_gas(&self) -> Option<U256> {
211222
self.header.base_fee_per_gas.as_ref().copied()
212223
}

0 commit comments

Comments
 (0)