Skip to content

Commit

Permalink
Merge pull request #13 from pinax-network/feature/creation_trees
Browse files Browse the repository at this point in the history
Antelope : Creation Flat Nodes
  • Loading branch information
DenisCarriere authored Sep 17, 2024
2 parents a8503ae + f16f46b commit e82d3e8
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ graph TD;
- [x] **Authority.Waits**
- [x] **RAM Operations**
- [x] **Table Operations**
- [ ] **Creation Tree**
- [x] **Creation Tree**
- [ ] ~~**Deferred Transactions**~~
- [x] **Actions**
- [x] **Authorization**
Expand Down
27 changes: 26 additions & 1 deletion blocks/antelope/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -434,4 +434,29 @@ CREATE TABLE IF NOT EXISTS account_ram_deltas
ENGINE = ReplacingMergeTree()
PRIMARY KEY (block_date, block_number)
ORDER BY (block_date, block_number, tx_hash, action_index, account)
COMMENT 'Antelope account RAM deltas';
COMMENT 'Antelope account RAM deltas';

CREATE TABLE IF NOT EXISTS creation_tree
(
-- clock --
block_time DateTime64(3, 'UTC'),
block_number UInt64,
block_hash String,
block_date Date,

-- transaction --
tx_hash String COMMENT 'Hash',
tx_index UInt64,
tx_status LowCardinality(String),
tx_status_code UInt8,
tx_success Bool,

-- transaction.creation_tree --
creator_action_index Int32,
execution_action_index UInt32
)
ENGINE = ReplacingMergeTree()
PRIMARY KEY (tx_hash, creator_action_index, execution_action_index)
ORDER BY (tx_hash, creator_action_index, execution_action_index)
COMMENT 'Antelope creation tree';

19 changes: 19 additions & 0 deletions blocks/antelope/src/creation_tree.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use common::blocks::insert_timestamp;
use substreams::pb::substreams::Clock;
use substreams_antelope::pb::{CreationFlatNode, TransactionTrace};
use substreams_database_change::pb::database::{table_change, DatabaseChanges};

use crate::{keys::creation_tree_keys, transactions::insert_transaction_metadata};

pub fn insert_creation_tree(tables: &mut DatabaseChanges, clock: &Clock, transaction: &TransactionTrace, creation_flat_node: &CreationFlatNode) {
let creator_action_index = creation_flat_node.creator_action_index;
let execution_action_index = creation_flat_node.execution_action_index;
let keys = creation_tree_keys(&transaction.id, &creator_action_index, &execution_action_index);
let row = tables
.push_change_composite("creation_tree", keys, 0, table_change::Operation::Create)
.change("creator_action_index", ("", creation_flat_node.creator_action_index.to_string().as_str()))
.change("execution_action_index", ("", creation_flat_node.execution_action_index.to_string().as_str()));

insert_transaction_metadata(row, transaction);
insert_timestamp(row, clock, false, false);
}
7 changes: 7 additions & 0 deletions blocks/antelope/src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ pub fn feature_ops_keys(clock: &Clock, tx_hash: &String, kind: &String, feature_
keys
}


pub fn creation_tree_keys(tx_hash: &String, creator_action_index: &i32, execution_action_index: &u32) -> HashMap<String, String> {
let mut keys = HashMap::new();
keys.insert("tx_hash".to_string(), tx_hash.to_string());
keys.insert("creator_action_index".to_string(), creator_action_index.to_string());
keys.insert("execution_action_index".to_string(), execution_action_index.to_string());

pub fn table_ops_keys(tx_hash: &String, index: &u32) -> HashMap<String, String> {
let mut keys = HashMap::new();
keys.insert("tx_hash".to_string(), tx_hash.to_string());
Expand Down
1 change: 1 addition & 0 deletions blocks/antelope/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ mod auth_sequences;
mod authority;
mod authorizations;
mod blocks;
mod creation_tree;
mod db_ops;
mod feature_ops;
mod keys;
Expand Down
8 changes: 4 additions & 4 deletions blocks/antelope/src/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use substreams_antelope::pb::{BlockHeader, TransactionTrace};
use substreams_database_change::pb::database::TableChange;
use substreams_database_change::pb::database::{table_change, DatabaseChanges};

use crate::creation_tree::insert_creation_tree;
use crate::feature_ops::insert_feature_op;
use crate::keys::transactions_keys;
use crate::table_ops::insert_table_op;
Expand Down Expand Up @@ -134,11 +135,10 @@ pub fn insert_transaction(tables: &mut DatabaseChanges, clock: &Clock, transacti
table_op_index += 1;
}

// TO-DO
// Tree of creation, rather than execution
// for creation_tree in transaction.creation_tree.iter() {
// insert_creation_tree(tables, clock, creation_tree, &block);
// }
for creation_flat_node in transaction.creation_tree.iter() {
insert_creation_tree(tables, clock, transaction, creation_flat_node);
}

// TO-DO??
// Exception leading to the failed dtrx trace.
Expand Down

0 comments on commit e82d3e8

Please sign in to comment.