Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] block timestamp is None in logs from TransactionReceipts #945

Closed
lukeyyang opened this issue Jun 19, 2024 · 1 comment
Closed

[Bug] block timestamp is None in logs from TransactionReceipts #945

lukeyyang opened this issue Jun 19, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@lukeyyang
Copy link

Component

rpc

What version of Alloy are you on?

v0.1.1

Operating System

None

Describe the bug

#429 could be some related prior effort.

The TransactionReceipt contains Log which has an optional u64 block_timestamp. In practice, this value has always appeared to be None. Is this expected?

Note that the block timestamp is available within the block header.

Demo:

use alloy::providers::{Provider, ProviderBuilder, ReqwestProvider};
use alloy::rpc::types::eth::{Block, BlockId, TransactionReceipt};
use alloy::rpc::types::BlockTransactionsKind;
use std::sync::Arc;

async fn fetch_parse_receipts(
    client: Arc<ReqwestProvider>,
    block: &Block,
) -> Vec<TransactionReceipt> {
    let futures = block
        .transactions
        .hashes()
        .map(|tx| client.get_transaction_receipt(*tx));
    let receipts_calls = futures::future::join_all(futures)
        .await
        .into_iter()
        .collect::<Vec<_>>();

    receipts_calls
        .iter()
        .filter_map(|r| match r {
            Ok(Some(receipt)) => Some(receipt.clone()),
            _ => None,
        })
        .collect()
}

#[tokio::main]
async fn main() {
    tracing_subscriber::fmt().init();
    tracing::info!("Hello, world!");

    let http: Arc<ReqwestProvider> = Arc::new(
        ProviderBuilder::default()
            .on_http(reqwest::Url::parse("https://mainnet.gateway.tenderly.co").unwrap()),
    );
    let block = http
        .get_block(BlockId::latest(), BlockTransactionsKind::Full)
        .await
        .unwrap()
        .unwrap();
    tracing::info!(
        "Got block {:?} with timestamp {:?}",
        block.header.number,
        block.header.timestamp
    ); // expect to see a valid block_timestamp
    let receipts = fetch_parse_receipts(http.clone(), &block).await;
    for receipt in receipts {
        for log in receipt.inner.logs() {
            tracing::info!(
                "log for block number {:?} with timestamp {:?}",
                log.block_number,
                log.block_timestamp
            );
            // expect to see None for block_timestamp
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants