Skip to content

Commit

Permalink
Add RamOps
Browse files Browse the repository at this point in the history
  • Loading branch information
zolting committed Nov 18, 2024
1 parent dd4eaab commit a2717f2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
38 changes: 37 additions & 1 deletion blocks/antelope/src/ram_ops.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use common::blocks::insert_timestamp;
use common::structs::BlockTimestamp;
use substreams::pb::substreams::Clock;
use substreams_antelope::pb::{RamOp, TransactionTrace};
use substreams_antelope::Block;
use substreams_database_change::pb::database::{table_change, DatabaseChanges};

use crate::keys::ram_op_keys;
use crate::transactions::insert_transaction_metadata;
use crate::pb::antelope::RamOp as RawRamOp;
use crate::transactions::{insert_transaction_metadata, is_transaction_success};

pub fn namespace_to_string(namespace: i32) -> String {
match namespace {
Expand Down Expand Up @@ -95,3 +98,36 @@ pub fn insert_ram_op(tables: &mut DatabaseChanges, clock: &Clock, ram_op: &RamOp
insert_transaction_metadata(row, transaction);
insert_timestamp(row, clock, false, false);
}

pub fn collect_ram_ops(block: &Block, timestamp: &BlockTimestamp) -> Vec<RawRamOp> {
let mut ram_ops: Vec<RawRamOp> = 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 ram_op in transaction.ram_ops.iter() {
ram_ops.push(RawRamOp {
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,
operation: operation_to_string(ram_op.operation),
action_index: ram_op.action_index,
payer: ram_op.payer.clone(),
delta: ram_op.delta,
usage: ram_op.usage,
namespace: namespace_to_string(ram_op.namespace),
action: action_to_string(ram_op.action),
unique_key: ram_op.unique_key.clone(),
operation_code: ram_op.operation as u32,
namespace_code: ram_op.namespace as u32,
action_code: ram_op.action as u32,
});
}
}

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

use crate::{
actions::collect_actions, authority::collect_authority_vectors, blocks::collect_block, db_ops::collect_db_ops, feature_ops::collect_feature_ops, pb::antelope::Events, perm_ops::collect_perm_ops,
table_ops::collect_table_ops, transactions::collect_transactions,
ram_ops::collect_ram_ops, table_ops::collect_table_ops, transactions::collect_transactions,
};

#[substreams::handlers::map]
Expand All @@ -24,7 +24,7 @@ pub fn map_events(clock: Clock, block: Block) -> Result<Events, Error> {
accounts: authority_vectors.accounts,
keys: authority_vectors.keys,
waits: authority_vectors.waits,
ram_ops: vec![],
ram_ops: collect_ram_ops(&block, &timestamp),
authorizations: vec![],
auth_sequences: vec![],
account_ram_deltas: vec![],
Expand Down

0 comments on commit a2717f2

Please sign in to comment.