From 0137c2fd027c5285855a3d0dfbf5158a47f35c91 Mon Sep 17 00:00:00 2001 From: Denis Carriere Date: Sat, 13 Jul 2024 12:37:32 +0200 Subject: [PATCH] add logs --- README.md | 4 ++-- blocks/evm/src/lib.rs | 54 ++++++++++++++++++++++++++++--------------- common/src/lib.rs | 6 ++--- 3 files changed, 41 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index c2b4aaf..3a6f8ca 100644 --- a/README.md +++ b/README.md @@ -15,10 +15,10 @@ ## Raw Data - [x] Blocks -- [ ] Creation Traces -- [ ] Logs +- [x] Logs - [ ] Transactions - [ ] Traces + - [ ] Creation Traces ## Data Visualization diff --git a/blocks/evm/src/lib.rs b/blocks/evm/src/lib.rs index 027aa3a..fd7c923 100644 --- a/blocks/evm/src/lib.rs +++ b/blocks/evm/src/lib.rs @@ -8,7 +8,7 @@ use substreams_ethereum::pb::eth::v2::Block; #[substreams::handlers::map] pub fn graph_out(clock: Clock, block: Block) -> Result { let mut tables = Tables::new(); - let header = block.header.unwrap(); + let header = block.clone().header.unwrap(); let timestamp = clock.timestamp.unwrap(); let block_time = timestamp.to_string(); let block_number = clock.number.to_string(); @@ -19,8 +19,8 @@ pub fn graph_out(clock: Clock, block: Block) -> Result { .create_row("blocks", &block_hash) .set("time", &block_time) .set_bigint("number", &block_number) - .set("date", block_date) - .set("hash", block_hash) + .set("date", &block_date) + .set("hash", &block_hash) .set("parent_hash", bytes_to_hex(header.parent_hash)) .set_bigint("nonce", &header.nonce.to_string()) .set("ommers_hash", bytes_to_hex(header.uncle_hash)) @@ -41,21 +41,39 @@ pub fn graph_out(clock: Clock, block: Block) -> Result { .set_bigint("base_fee_per_gas", &header.base_fee_per_gas.unwrap_or_default().with_decimal(0).to_string()) .set("parent_beacon_root", bytes_to_hex(header.parent_beacon_root)); - // block_time - // block_number - // block_hash - // contract_address - // topic0 - // topic1 - // topic2 - // topic3 - // data - // tx_hash - // index - // tx_index - // block_date - // tx_from - // tx_to + for log in block.logs() { + let log_index = log.index(); + let transaction = log.receipt.transaction; + let tx_hash = bytes_to_hex(transaction.hash.to_vec()); + let tx_index = transaction.index; + let tx_from = bytes_to_hex(transaction.from.to_vec()); + let tx_to = bytes_to_hex(transaction.to.to_vec()); + let contract_address = bytes_to_hex(log.address().to_vec()); + let topics = log.topics(); + let topic0 = bytes_to_hex(topics[0].clone()); + let topic1 = bytes_to_hex(topics[1].clone()); + let topic2 = bytes_to_hex(topics[2].clone()); + let topic3 = bytes_to_hex(topics[3].clone()); + let data = bytes_to_hex(log.data().to_vec()); + + tables + .create_row("logs", &log_index.to_string()) + .set("block_time", &block_time) + .set("block_number", &block_number) + .set("block_hash", &block_hash) + .set("contract_address", &contract_address) + .set("topic0", &topic0) + .set("topic1", &topic1) + .set("topic2", &topic2) + .set("topic3", &topic3) + .set("data", &data) + .set("tx_hash", &tx_hash) + .set_bigint("index", &log_index.to_string()) + .set_bigint("tx_index", &tx_index.to_string()) + .set("block_date", &block_date) + .set("tx_from", &tx_from) + .set("tx_to", &tx_to); + } Ok(tables.to_entity_changes()) } diff --git a/common/src/lib.rs b/common/src/lib.rs index c4f363f..3d9b91c 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -2,10 +2,10 @@ use substreams::Hex; // Timestamp to date conversion // ex: 2015-07-30T16:02:18Z => 2015-07-30 -pub fn block_time_to_date(block_time: &str) -> &str { +pub fn block_time_to_date(block_time: &str) -> String { match block_time.split('T').next() { - Some(date) => date, - None => "", + Some(date) => date.to_string(), + None => "".to_string(), } }