Skip to content

Commit

Permalink
feat(model): include tx_hash in TransactionRecord (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
rvcas authored Feb 2, 2022
1 parent 5d57a76 commit c8c9089
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
7 changes: 4 additions & 3 deletions src/mapper/crawl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,10 @@ impl EventWriter {
fn crawl_transaction(
&self,
tx: &TransactionBody,
tx_hash: &str,
aux_data: Option<&AuxiliaryData>,
) -> Result<(), Error> {
let record = self.to_transaction_record(tx, aux_data)?;
let record = self.to_transaction_record(tx, tx_hash, aux_data)?;

self.append_from(record.clone())?;

Expand Down Expand Up @@ -206,11 +207,11 @@ impl EventWriter {

let child = self.child_writer(EventContext {
tx_idx: Some(idx),
tx_hash: Some(tx_hash),
tx_hash: Some(tx_hash.to_owned()),
..EventContext::default()
});

child.crawl_transaction(tx, aux_data)?;
child.crawl_transaction(tx, &tx_hash, aux_data)?;
}

if self.config.include_block_end_events {
Expand Down
3 changes: 3 additions & 0 deletions src/mapper/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,13 @@ impl EventWriter {
pub fn to_transaction_record(
&self,
body: &TransactionBody,
tx_hash: &str,
aux_data: Option<&AuxiliaryData>,
) -> Result<TransactionRecord, Error> {
let mut record = TransactionRecord::default();

record.hash.push_str(tx_hash);

for component in body.iter() {
match component {
TransactionBodyComponent::Fee(x) => {
Expand Down
1 change: 1 addition & 0 deletions src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ impl From<MintRecord> for EventData {

#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct TransactionRecord {
pub hash: String,
pub fee: u64,
pub ttl: Option<u64>,
pub validity_interval_start: Option<u64>,
Expand Down
11 changes: 6 additions & 5 deletions src/sinks/terminal/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,24 @@ impl LogLine {
total_output,
fee,
ttl,
hash,
..
}) => LogLine {
prefix: "TX",
color: Color::DarkBlue,
content: format!(
"{{ total_output: {}, fee: {}, hash: {:?}, ttl: {:?} }}",
total_output, fee, &source.context.tx_hash, ttl
"{{ total_output: {}, fee: {}, hash: {}, ttl: {:?} }}",
total_output, fee, hash, ttl
),
source,
max_width,
},
EventData::TransactionEnd(TransactionRecord { .. }) => LogLine {
EventData::TransactionEnd(TransactionRecord { hash, .. }) => LogLine {
prefix: "ENDTX",
color: Color::DarkBlue,
content: format!(
"{{ hash: {:?} }}",
&source.context.tx_hash
"{{ hash: {} }}",
hash
),
source,
max_width,
Expand Down

0 comments on commit c8c9089

Please sign in to comment.