Skip to content

Commit

Permalink
Add AccountRamDeltas + CreationTrees
Browse files Browse the repository at this point in the history
  • Loading branch information
zolting committed Nov 18, 2024
1 parent 6f7cebe commit 567eb94
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 4 deletions.
34 changes: 34 additions & 0 deletions blocks/antelope/src/account_ram_deltas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ use substreams_antelope::pb::{ActionTrace, TransactionTrace};
use substreams_database_change::pb::database::{table_change, DatabaseChanges};

use crate::keys::account_ram_delta_keys;
use crate::pb::antelope::AccountRamDelta as RawAccountRamDelta;
use crate::transactions::insert_transaction_metadata;
use crate::transactions::is_transaction_success;
use common::structs::BlockTimestamp;
use substreams_antelope::Block;

pub fn insert_account_ram_delta(tables: &mut DatabaseChanges, clock: &Clock, action: &ActionTrace, transaction: &TransactionTrace, account_ram_delta: &AccountRamDelta, index: &u32) {
// transaction
Expand All @@ -30,3 +34,33 @@ pub fn insert_account_ram_delta(tables: &mut DatabaseChanges, clock: &Clock, act
insert_transaction_metadata(row, transaction);
insert_timestamp(row, clock, false, false);
}

pub fn collect_account_ram_deltas(block: &Block, timestamp: &BlockTimestamp) -> Vec<RawAccountRamDelta> {
let mut account_ram_deltas: Vec<RawAccountRamDelta> = vec![];

for transaction in block.transaction_traces() {
let tx_hash = &transaction.id;
let tx_success = is_transaction_success(transaction.receipt.clone().unwrap_or_default().status);

for action_trace in transaction.action_traces.iter() {
let action_index = action_trace.execution_index;

for (index, delta) in action_trace.account_ram_deltas.iter().enumerate() {
account_ram_deltas.push(RawAccountRamDelta {
block_time: Some(timestamp.time.clone()),
block_number: timestamp.number,
block_hash: timestamp.hash.clone(),
block_date: timestamp.date.clone(),
tx_hash: tx_hash.clone(),
tx_success,
action_index,
index: index as u32,
account: delta.account.clone(),
delta: delta.delta,
});
}
}
}

account_ram_deltas
}
28 changes: 28 additions & 0 deletions blocks/antelope/src/creation_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ use substreams::pb::substreams::Clock;
use substreams_antelope::pb::{CreationFlatNode, TransactionTrace};
use substreams_database_change::pb::database::{table_change, DatabaseChanges};

use crate::pb::antelope::CreationTree as RawCreationTree;
use crate::transactions::is_transaction_success;
use crate::{keys::creation_tree_keys, transactions::insert_transaction_metadata};
use common::structs::BlockTimestamp;
use substreams_antelope::Block;

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;
Expand All @@ -17,3 +21,27 @@ pub fn insert_creation_tree(tables: &mut DatabaseChanges, clock: &Clock, transac
insert_transaction_metadata(row, transaction);
insert_timestamp(row, clock, false, false);
}

pub fn collect_creation_trees(block: &Block, timestamp: &BlockTimestamp) -> Vec<RawCreationTree> {
let mut creation_trees: Vec<RawCreationTree> = vec![];

for transaction in block.transaction_traces() {
let tx_hash = &transaction.id;
let tx_success = is_transaction_success(transaction.receipt.clone().unwrap_or_default().status);

for creation_flat_node in transaction.creation_tree.iter() {
creation_trees.push(RawCreationTree {
block_time: Some(timestamp.time.clone()),
block_number: timestamp.number,
block_hash: timestamp.hash.clone(),
block_date: timestamp.date.clone(),
tx_hash: tx_hash.clone(),
tx_success,
creator_action_index: creation_flat_node.creator_action_index,
execution_action_index: creation_flat_node.execution_action_index,
});
}
}

creation_trees
}
9 changes: 5 additions & 4 deletions blocks/antelope/src/sinks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ use substreams::pb::substreams::Clock;
use substreams_antelope::pb::Block;

use crate::{
actions::collect_actions, auth_sequences::collect_auth_sequences, authority::collect_authority_vectors, authorizations::collect_authorizations, blocks::collect_block, db_ops::collect_db_ops,
feature_ops::collect_feature_ops, pb::antelope::Events, perm_ops::collect_perm_ops, ram_ops::collect_ram_ops, table_ops::collect_table_ops, transactions::collect_transactions,
account_ram_deltas::collect_account_ram_deltas, actions::collect_actions, auth_sequences::collect_auth_sequences, authority::collect_authority_vectors, authorizations::collect_authorizations,
blocks::collect_block, creation_tree::collect_creation_trees, db_ops::collect_db_ops, feature_ops::collect_feature_ops, pb::antelope::Events, perm_ops::collect_perm_ops, ram_ops::collect_ram_ops,
table_ops::collect_table_ops, transactions::collect_transactions,
};

#[substreams::handlers::map]
Expand All @@ -27,7 +28,7 @@ pub fn map_events(clock: Clock, block: Block) -> Result<Events, Error> {
ram_ops: collect_ram_ops(&block, &timestamp),
authorizations: collect_authorizations(&block, &timestamp),
auth_sequences: collect_auth_sequences(&block, &timestamp),
account_ram_deltas: vec![],
creation_trees: vec![],
account_ram_deltas: collect_account_ram_deltas(&block, &timestamp),
creation_trees: collect_creation_trees(&block, &timestamp),
})
}

0 comments on commit 567eb94

Please sign in to comment.