Skip to content

Commit

Permalink
filter out onblock trx
Browse files Browse the repository at this point in the history
  • Loading branch information
YaroShkvorets committed Dec 18, 2023
1 parent 75ec07c commit db597c1
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 17 deletions.
7 changes: 5 additions & 2 deletions antelope.trxstats/proto/v1/antelope.trxstats.proto
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ message Transaction {
string trx_id = 2;
uint64 block_num = 4;
google.protobuf.Timestamp block_time = 5;
int32 status = 6;
uint32 action_count = 10;
int32 cpu = 11;
uint32 net = 12;
int32 elapsed = 11;
uint32 net_usage = 12;
uint32 cpu_usage_micro_seconds = 13;
uint32 net_usage_words = 14;
}
7 changes: 5 additions & 2 deletions antelope.trxstats/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ CREATE TABLE
"trx_id" VARCHAR(64) PRIMARY KEY,
"block_num" BIGINT,
"block_time" TIMESTAMP,
"status" INT,
"action_count" INT,
"cpu" INT,
"net" INT
"elapsed" INT,
"net_usage" INT,
"cpu_usage_micro_seconds" INT,
"net_usage_words" INT
);
27 changes: 18 additions & 9 deletions antelope.trxstats/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,19 @@ fn map_trxs(block: Block) -> Result<Transactions, Error> {
Ok(Transactions {
transactions: block
.all_transaction_traces()
.map(|trx| Transaction {
trx_id: trx.id.clone(),
block_num: trx.block_num,
block_time: trx.block_time.clone(),
action_count: trx.action_traces.len() as u32,
cpu: trx.elapsed as i32,
net: trx.net_usage as u32,
.filter_map(|trx| match trx.index {
0 => None, // skip eosio::onblock trxs
_ => Some(Transaction {
trx_id: trx.id.clone(),
block_num: trx.block_num,
block_time: trx.block_time.clone(),
action_count: trx.action_traces.len() as u32,
elapsed: trx.elapsed as i32,
net_usage: trx.net_usage as u32,
cpu_usage_micro_seconds: trx.receipt.clone().unwrap_or_default().cpu_usage_micro_seconds,
net_usage_words: trx.receipt.clone().unwrap_or_default().net_usage_words,
status: trx.receipt.clone().unwrap_or_default().status,
}),
})
.collect(),
})
Expand All @@ -34,8 +40,11 @@ fn db_out(trxs: Transactions) -> Result<DatabaseChanges, substreams::errors::Err
.set("block_time", trx.block_time.unwrap())
.set("block_num", trx.block_num)
.set("action_count", trx.action_count)
.set("cpu", trx.cpu)
.set("net", trx.net);
.set("elapsed", trx.elapsed)
.set("net_usage", trx.net_usage)
.set("cpu_usage_micro_seconds", trx.cpu_usage_micro_seconds)
.set("net_usage_words", trx.net_usage_words)
.set("status", trx.status);
});

Ok(tables.to_database_changes())
Expand Down
10 changes: 8 additions & 2 deletions antelope.trxstats/src/pb/antelope.trxstats.v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,17 @@ pub struct Transaction {
pub block_num: u64,
#[prost(message, optional, tag="5")]
pub block_time: ::core::option::Option<::prost_types::Timestamp>,
#[prost(int32, tag="6")]
pub status: i32,
#[prost(uint32, tag="10")]
pub action_count: u32,
#[prost(int32, tag="11")]
pub cpu: i32,
pub elapsed: i32,
#[prost(uint32, tag="12")]
pub net: u32,
pub net_usage: u32,
#[prost(uint32, tag="13")]
pub cpu_usage_micro_seconds: u32,
#[prost(uint32, tag="14")]
pub net_usage_words: u32,
}
// @@protoc_insertion_point(module)
2 changes: 0 additions & 2 deletions antelope.trxstats/substreams.sql.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,3 @@ sink:
engine: postgres
postgraphile_frontend:
enabled: true

network: eos

0 comments on commit db597c1

Please sign in to comment.