From 07b3f5613f8436121d3d2b2c144c2f77d3baf722 Mon Sep 17 00:00:00 2001 From: Santiago Carmuega Date: Thu, 13 Jan 2022 18:41:17 -0300 Subject: [PATCH] feat: Add slot, hash and number to block start event --- src/framework.rs | 3 +++ src/mapper/crawl.rs | 8 ++++---- src/mapper/map.rs | 5 ++++- src/sinks/terminal/format.rs | 9 +++++++-- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/framework.rs b/src/framework.rs index d88b8075..e0f7ade2 100644 --- a/src/framework.rs +++ b/src/framework.rs @@ -165,6 +165,9 @@ pub enum EventData { body_size: usize, issuer_vkey: String, tx_count: usize, + slot: u64, + hash: String, + number: u64, }, Transaction(TransactionRecord), TxInput(TxInputRecord), diff --git a/src/mapper/crawl.rs b/src/mapper/crawl.rs index 7e45879a..83843a5f 100644 --- a/src/mapper/crawl.rs +++ b/src/mapper/crawl.rs @@ -176,8 +176,8 @@ impl EventWriter { Ok(()) } - fn crawl_block(&self, block: &Block) -> Result<(), Error> { - let data = self.to_block_event(block)?; + fn crawl_block(&self, block: &Block, hash: &[u8]) -> Result<(), Error> { + let data = self.to_block_event(block, hash)?; self.append(data)?; for (idx, tx) in block.transaction_bodies.iter().enumerate() { @@ -211,13 +211,13 @@ impl EventWriter { let hash = crypto::hash_block_header(&block.header)?; let child = self.child_writer(EventContext { - block_hash: Some(hex::encode(hash)), + block_hash: Some(hex::encode(&hash)), block_number: Some(block.header.header_body.block_number), slot: Some(block.header.header_body.slot), timestamp: self.compute_timestamp(block.header.header_body.slot), ..EventContext::default() }); - child.crawl_block(block) + child.crawl_block(block, &hash) } } diff --git a/src/mapper/map.rs b/src/mapper/map.rs index 5dc50737..de7db179 100644 --- a/src/mapper/map.rs +++ b/src/mapper/map.rs @@ -349,11 +349,14 @@ impl EventWriter { Ok(record) } - pub fn to_block_event(&self, source: &Block) -> Result { + pub fn to_block_event(&self, source: &Block, hash: &[u8]) -> Result { Ok(EventData::Block { body_size: source.header.header_body.block_body_size as usize, issuer_vkey: source.header.header_body.issuer_vkey.to_hex(), tx_count: source.transaction_bodies.len(), + hash: hex::encode(hash), + number: source.header.header_body.block_number, + slot: source.header.header_body.slot, }) } } diff --git a/src/sinks/terminal/format.rs b/src/sinks/terminal/format.rs index 57c656bf..48917cf9 100644 --- a/src/sinks/terminal/format.rs +++ b/src/sinks/terminal/format.rs @@ -22,14 +22,19 @@ impl LogLine { body_size, issuer_vkey, tx_count, + slot, + hash, + number, .. } => { LogLine { prefix: "BLOCK", color: Color::Magenta, content: format!( - "{{ hash: {}, body size: {}, tx_count: {}, issuer vkey: {}, timestamp: {} }}", - &source.context.block_hash.as_ref().unwrap_or(&"".to_string()), + "{{ slot: {}, hash: {}, number: {}, body size: {}, tx_count: {}, issuer vkey: {}, timestamp: {} }}", + slot, + hash, + number, body_size, tx_count, issuer_vkey,