streamingfast / substreams-explorers

Apache License 2.0
7 stars 4 forks source link

Ethereum Explorer #1

Closed enoldev closed 1 year ago

enoldev commented 1 year ago

Currently, there are three modules: map_block_meta, map_filter_transaction and map_contract_events.

I've included most of the information in the README.md, but I'd like to add a section in the docs with a step-by-step guide of the source code.

enoldev commented 1 year ago
maoueh commented 1 year ago

Here for example a re-write of map_contract_events with only:

#[substreams::handlers::map]
fn map_contract_events(contract_address: String, blk: Block) -> Result<Events, Error> {
    // Not working today, needs to update `substreams-rs` to enable the conversion out of the box
    let address = Hex::decode(&contract_address)
        .with_context(|| anyhow!("invalid param address {}", contract_address))?;

    Ok(Events {
        events: blk
            .logs()
            .filter(|log_view| log_view.address() == address)
            .map(|log_view| Event {
                address: Hex::encode(log_view.address()),
                topics: log_view.log.topics.iter().map(Hex::encode).collect(),
                tx_hash: Hex::encode(log_view.receipt.transaction.hash),
            })
            .collect(),
    })
}