From b562dfcd0a315012dc2dfc504ed2a1d4903db6e6 Mon Sep 17 00:00:00 2001 From: Denis Carriere Date: Tue, 6 Aug 2024 15:38:07 -0400 Subject: [PATCH] update block_keys primary key --- README.md | 10 +++++-- blocks/evm/src/blocks.rs | 2 +- blocks/evm/src/transactions.rs | 4 +-- common/src/keys.rs | 53 +++++++++++++--------------------- 4 files changed, 30 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index 24cf01d..9d45c05 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ - [ ] Arbitrum Nova (L2 on ETH using AnyTrust protocol) - [ ] ~~Optimism (OP)~~ - [ ] [opBNB](https://docs.bnbchain.org/bnb-opbnb/) - - [ ] ~~Blast~~ + - [ ] 🕔 Blast - [x] Mode - [x] Zora - [ ] [~~Boba~~](https://boba.network/) @@ -75,18 +75,22 @@ - **ZK Rollup (EVM)** - [ ] Scroll - [x] Linea - - [ ] ~~[Fuse](https://www.fuse.io/)~~ (L2 on Polygon) + - [ ] 🕔 [Fuse](https://www.fuse.io/) (L2 on Polygon) - [ ] [zkBNB](https://docs.bnbchain.org/zkbnb/) - [ ] [Polygon zkEVM](https://polygon.technology/polygon-zkevm) - [ ] [Astar zkEVM](https://astar.network/) (L2) - [ ] zKatana Testnet - **Polkadot's Parachain** - - [ ] Moonbeam + - [ ] 🕔 [Moonbeam](https://moonbeam.network/) - [ ] Moonriver - [ ] [Astar](https://astar.network/) (L1) - **Tezos Smart Rollups** - [ ] Etherlink +## Legend + +- 🕔 Upcoming full protocol support + ## SQL ```sql diff --git a/blocks/evm/src/blocks.rs b/blocks/evm/src/blocks.rs index a5c514b..84c5586 100644 --- a/blocks/evm/src/blocks.rs +++ b/blocks/evm/src/blocks.rs @@ -34,7 +34,7 @@ pub fn insert_blocks(tables: &mut DatabaseChanges, clock: &Clock, block: &Block) let blob_gas_used = optional_u64_to_string(header.blob_gas_used); // uint64 // blocks - let keys = blocks_keys(&clock); + let keys = blocks_keys(&clock, true); let row = tables .push_change_composite("blocks", keys, 0, table_change::Operation::Create) .change("parent_hash", ("", parent_hash.as_str())) diff --git a/blocks/evm/src/transactions.rs b/blocks/evm/src/transactions.rs index 8bc2858..0673f39 100644 --- a/blocks/evm/src/transactions.rs +++ b/blocks/evm/src/transactions.rs @@ -66,8 +66,8 @@ pub fn insert_transaction(tables: &mut DatabaseChanges, clock: &Clock, transacti let type_code = transaction.r#type; let max_fee_per_gas = optional_bigint_to_string(transaction.max_fee_per_gas.clone()); // UInt256 let max_priority_fee_per_gas = optional_bigint_to_string(transaction.max_priority_fee_per_gas.clone()); // UInt256 - let return_data = bytes_to_hex(transaction.return_data.clone()); - let public_key = bytes_to_hex(transaction.public_key.clone()); + let return_data = bytes_to_hex(transaction.return_data.clone()); // TO-CHECK: empty on ETH + let public_key = bytes_to_hex(transaction.public_key.clone()); // TO-CHECK: empty on ETH let begin_ordinal = transaction.begin_ordinal; let end_ordinal = transaction.end_ordinal; let success = is_transaction_success(transaction.status); diff --git a/common/src/keys.rs b/common/src/keys.rs index 622a819..514febf 100644 --- a/common/src/keys.rs +++ b/common/src/keys.rs @@ -4,52 +4,39 @@ use substreams::pb::substreams::Clock; use crate::utils::block_time_to_date; -pub fn blocks_keys(clock: &Clock) -> HashMap { +pub fn blocks_keys(clock: &Clock, is_block: bool) -> HashMap { let timestamp = clock.clone().timestamp.unwrap(); let block_date = block_time_to_date(×tamp.to_string()).to_string(); let block_number = clock.number.to_string(); - - HashMap::from([("date".to_string(), block_date), ("number".to_string(), block_number)]) + let prefix = if is_block { "" } else { "block_" }; + let block_date_key = format!("{}date", prefix); + let block_number_key = format!("{}number", prefix); + HashMap::from([(block_date_key, block_date), (block_number_key, block_number)]) } pub fn transaction_keys(clock: &Clock, hash: &String) -> HashMap { - let timestamp = clock.clone().timestamp.unwrap(); - let block_date = block_time_to_date(×tamp.to_string()).to_string(); - - HashMap::from([("block_date".to_string(), block_date), ("hash".to_string(), hash.to_string())]) + let mut keys = blocks_keys(clock, false); + keys.insert("hash".to_string(), hash.to_string()); + keys } pub fn logs_keys(clock: &Clock, tx_hash: &String, index: &u32) -> HashMap { - let timestamp = clock.clone().timestamp.unwrap(); - let block_date = block_time_to_date(×tamp.to_string()).to_string(); - - HashMap::from([ - ("block_date".to_string(), block_date), - ("tx_hash".to_string(), tx_hash.to_string()), - ("index".to_string(), index.to_string()), - ]) + let mut keys = blocks_keys(clock, false); + keys.insert("tx_hash".to_string(), tx_hash.to_string()); + keys.insert("index".to_string(), index.to_string()); + keys } pub fn block_ordinal_keys(clock: &Clock, ordinal: &u64) -> HashMap { - let timestamp = clock.clone().timestamp.unwrap(); - let block_date = block_time_to_date(×tamp.to_string()).to_string(); - let block_number = clock.number.to_string(); - - HashMap::from([ - ("block_date".to_string(), block_date), - ("block_number".to_string(), block_number), - ("ordinal".to_string(), ordinal.to_string()), - ]) + let mut keys = blocks_keys(clock, false); + keys.insert("ordinal".to_string(), ordinal.to_string()); + keys } pub fn traces_keys(clock: &Clock, tx_hash: &String, tx_index: &u32, index: &u32) -> HashMap { - let timestamp = clock.clone().timestamp.unwrap(); - let block_date = block_time_to_date(×tamp.to_string()).to_string(); - - HashMap::from([ - ("block_date".to_string(), block_date), - ("tx_hash".to_string(), tx_hash.to_string()), - ("tx_index".to_string(), tx_index.to_string()), - ("index".to_string(), index.to_string()), - ]) + let mut keys = blocks_keys(clock, false); + keys.insert("tx_hash".to_string(), tx_hash.to_string()); + keys.insert("tx_index".to_string(), tx_index.to_string()); + keys.insert("index".to_string(), index.to_string()); + keys }