Skip to content

Commit

Permalink
Merge pull request #45 from Blobscan/blob-gas-fields
Browse files Browse the repository at this point in the history
feat: index blob gas fields
  • Loading branch information
PabloCastellano authored Aug 19, 2023
2 parents 1e2619c + 8e5a46a commit 9aaa590
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions src/clients/blobscan/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ use serde::{Deserialize, Serialize};
use crate::{clients::beacon::types::Blob as BeaconBlob, utils::web3::calculate_versioned_hash};

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct Block {
pub number: U64,
pub hash: H256,
pub timestamp: U256,
pub slot: u32,
pub blob_gas_used: U256,
pub excess_blob_gas: U256,
}

#[derive(Serialize, Deserialize, Debug)]
Expand All @@ -24,6 +27,8 @@ pub struct Transaction {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub to: Option<Address>,
pub block_number: U64,
pub gas_price: U256,
pub max_fee_per_blob_gas: U256,
}

#[derive(Serialize, Deserialize)]
Expand Down Expand Up @@ -99,6 +104,36 @@ impl<'a> TryFrom<(&'a EthersBlock<EthersTransaction>, u32)> for Block {
.with_context(|| format!("Missing block hash field in execution block {number}"))?,
timestamp: ethers_block.timestamp,
slot,
blob_gas_used: match ethers_block.other.get("blobGasUsed") {
Some(blob_gas_used) => {
let blob_gas_used = blob_gas_used.as_str().with_context(|| {
format!("Failed to convert `blobGasUsed` field in execution block {number}")
})?;

U256::from_str_radix(blob_gas_used, 16)?
}
None => {
return Err(anyhow::anyhow!(
"Missing `blobGasUsed` field in execution block {number}"
))
}
},
excess_blob_gas: match ethers_block.other.get("excessBlobGas") {
Some(excess_gas_gas) => {
let excess_blob_gas = excess_gas_gas.as_str().with_context(|| {
format!(
"Failed to convert excess blob gas field in execution block {number}"
)
})?;

U256::from_str_radix(excess_blob_gas, 16)?
}
None => {
return Err(anyhow::anyhow!(
"Missing `excessBlobGas` field in execution block {number}"
))
}
},
})
}
}
Expand All @@ -118,6 +153,28 @@ impl<'a> TryFrom<(&'a EthersTransaction, &'a EthersBlock<EthersTransaction>)> fo
hash,
from: ethers_tx.from,
to: ethers_tx.to,
gas_price: ethers_tx.gas_price.with_context(|| {
format!("Missing gas price field in transaction {hash}", hash = hash)
})?,
max_fee_per_blob_gas: match ethers_tx.other.get("maxFeePerBlobGas") {
Some(max_fee_per_blob_gas) => {
let max_fee_per_blob_gas =
max_fee_per_blob_gas.as_str().with_context(|| {
format!(
"Failed to convert `maxFeePerBlobGas` field in transaction {hash}",
hash = hash
)
})?;

U256::from_str_radix(max_fee_per_blob_gas, 16)?
}
None => {
return Err(anyhow::anyhow!(
"Missing `maxFeePerBlobGas` field in transaction {hash}",
hash = hash
))
}
},
})
}
}
Expand Down

0 comments on commit 9aaa590

Please sign in to comment.