Skip to content

Commit

Permalink
update block_keys primary key
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisCarriere committed Aug 6, 2024
1 parent 61a5dce commit b562dfc
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 39 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion blocks/evm/src/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down
4 changes: 2 additions & 2 deletions blocks/evm/src/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
53 changes: 20 additions & 33 deletions common/src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,39 @@ use substreams::pb::substreams::Clock;

use crate::utils::block_time_to_date;

pub fn blocks_keys(clock: &Clock) -> HashMap<String, String> {
pub fn blocks_keys(clock: &Clock, is_block: bool) -> HashMap<String, String> {
let timestamp = clock.clone().timestamp.unwrap();
let block_date = block_time_to_date(&timestamp.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<String, String> {
let timestamp = clock.clone().timestamp.unwrap();
let block_date = block_time_to_date(&timestamp.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<String, String> {
let timestamp = clock.clone().timestamp.unwrap();
let block_date = block_time_to_date(&timestamp.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<String, String> {
let timestamp = clock.clone().timestamp.unwrap();
let block_date = block_time_to_date(&timestamp.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<String, String> {
let timestamp = clock.clone().timestamp.unwrap();
let block_date = block_time_to_date(&timestamp.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
}

0 comments on commit b562dfc

Please sign in to comment.