Skip to content

Commit

Permalink
fix: accept generic header in meta builder (#30)
Browse files Browse the repository at this point in the history
* fix: `with_block` with generic header

* fix: accept generic header in builder
  • Loading branch information
yash-atreya authored Nov 9, 2024
1 parent 20005c0 commit 4ea5f75
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
13 changes: 13 additions & 0 deletions src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,19 @@ mod tests {

const ENDPOINT: Option<&str> = option_env!("ETH_RPC_URL");

#[tokio::test(flavor = "multi_thread")]
async fn test_builder() {
let Some(endpoint) = ENDPOINT else { return };
let provider = get_http_provider(endpoint);

let any_rpc_block = provider
.get_block(BlockId::latest(), alloy_rpc_types::BlockTransactionsKind::Hashes)
.await
.unwrap()
.unwrap();
let _meta = BlockchainDbMeta::default().with_block(&any_rpc_block.inner);
}

#[tokio::test(flavor = "multi_thread")]
async fn shared_backend() {
let Some(endpoint) = ENDPOINT else { return };
Expand Down
7 changes: 5 additions & 2 deletions src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,10 @@ impl BlockchainDbMeta {
}

/// Sets the [BlockEnv] of this instance using the provided [alloy_rpc_types::Block]
pub fn with_block<T: TransactionResponse>(mut self, block: &alloy_rpc_types::Block<T>) -> Self {
pub fn with_block<T: TransactionResponse, H: BlockHeader>(
mut self,
block: &alloy_rpc_types::Block<T, H>,
) -> Self {
self.block_env = BlockEnv {
number: U256::from(block.header.number()),
coinbase: block.header.beneficiary(),
Expand All @@ -158,7 +161,7 @@ impl BlockchainDbMeta {
gas_limit: U256::from(block.header.gas_limit()),
prevrandao: block.header.mix_hash(),
blob_excess_gas_and_price: Some(BlobExcessGasAndPrice::new(
block.header.excess_blob_gas.unwrap_or_default(),
block.header.excess_blob_gas().unwrap_or_default(),
)),
};

Expand Down

0 comments on commit 4ea5f75

Please sign in to comment.