Skip to content

Commit

Permalink
add logs
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisCarriere committed Jul 13, 2024
1 parent 1acd5d1 commit 0137c2f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 23 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
## Raw Data

- [x] Blocks
- [ ] Creation Traces
- [ ] Logs
- [x] Logs
- [ ] Transactions
- [ ] Traces
- [ ] Creation Traces

## Data Visualization

Expand Down
54 changes: 36 additions & 18 deletions blocks/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use substreams_ethereum::pb::eth::v2::Block;
#[substreams::handlers::map]
pub fn graph_out(clock: Clock, block: Block) -> Result<EntityChanges, Error> {
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();
Expand All @@ -19,8 +19,8 @@ pub fn graph_out(clock: Clock, block: Block) -> Result<EntityChanges, Error> {
.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))
Expand All @@ -41,21 +41,39 @@ pub fn graph_out(clock: Clock, block: Block) -> Result<EntityChanges, Error> {
.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())
}
6 changes: 3 additions & 3 deletions common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
}

Expand Down

0 comments on commit 0137c2f

Please sign in to comment.