diff --git a/src/mapper/map.rs b/src/mapper/map.rs index 4a3edd1b..edcc8d43 100644 --- a/src/mapper/map.rs +++ b/src/mapper/map.rs @@ -174,6 +174,7 @@ impl EventWriter { OutputAssetRecord { policy: policy.to_hex(), asset: asset.to_hex(), + asset_ascii: String::from_utf8(asset.to_vec()).ok(), amount, } } diff --git a/src/model.rs b/src/model.rs index ec48b740..17c2c4e7 100644 --- a/src/model.rs +++ b/src/model.rs @@ -92,6 +92,7 @@ impl From for EventData { pub struct OutputAssetRecord { pub policy: String, pub asset: String, + pub asset_ascii: Option, pub amount: u64, } @@ -254,8 +255,6 @@ pub enum EventData { block_slot: u64, block_hash: String, }, - // // flow-control event to end the pipeline - // Finalize, } #[derive(Debug, Serialize, Deserialize)] diff --git a/src/sinks/terminal/format.rs b/src/sinks/terminal/format.rs index a8c77535..41b73e1f 100644 --- a/src/sinks/terminal/format.rs +++ b/src/sinks/terminal/format.rs @@ -2,9 +2,12 @@ use std::fmt::{Display, Write}; use crossterm::style::{Attribute, Color, Stylize}; -use crate::model::{ - BlockRecord, CIP25AssetRecord, Event, EventData, MetadataRecord, MintRecord, OutputAssetRecord, - TransactionRecord, TxInputRecord, TxOutputRecord, +use crate::{ + model::{ + BlockRecord, CIP25AssetRecord, Event, EventData, MetadataRecord, MintRecord, + OutputAssetRecord, TransactionRecord, TxInputRecord, TxOutputRecord, + }, + utils::Utils, }; pub struct LogLine { @@ -16,7 +19,7 @@ pub struct LogLine { } impl LogLine { - pub fn new(source: Event, max_width: usize) -> LogLine { + pub fn new(source: Event, max_width: usize, utils: &Utils) -> LogLine { match &source.data { EventData::Block(BlockRecord { era, @@ -110,6 +113,23 @@ impl LogLine { EventData::OutputAsset(OutputAssetRecord { policy, asset, + asset_ascii, + .. + }) if policy == &utils.well_known.adahandle_policy => LogLine { + prefix: "$HNDL", + color: Color::DarkGreen, + content: format!( + "{{ {} => {} }}", + asset_ascii.as_deref().unwrap_or(asset), + source.context.output_address.as_deref().unwrap_or_default(), + ), + source, + max_width, + }, + EventData::OutputAsset(OutputAssetRecord { + policy, + asset, + asset_ascii, amount, .. }) => LogLine { @@ -117,7 +137,7 @@ impl LogLine { color: Color::Green, content: format!( "{{ policy: {}, asset: {}, amount: {} }}", - policy, asset, amount + policy, asset_ascii.as_deref().unwrap_or(asset), amount ), source, max_width, @@ -288,7 +308,7 @@ impl Display for LogLine { .unwrap_or_else(|| "--".to_string()), ) .stylize() - .with(Color::DarkGrey) + .with(Color::Grey) .attribute(Attribute::Dim) .fmt(f)?; diff --git a/src/sinks/terminal/run.rs b/src/sinks/terminal/run.rs index 7a94528b..b83aea24 100644 --- a/src/sinks/terminal/run.rs +++ b/src/sinks/terminal/run.rs @@ -33,7 +33,7 @@ pub fn reducer_loop( utils.track_sink_progress(&evt); throttle.wait_turn(); - let line = LogLine::new(evt, width as usize); + let line = LogLine::new(evt, width as usize, &utils); stdout.execute(Print(line))?; } diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 85ba209f..0476e37b 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -63,6 +63,7 @@ pub struct ChainWellKnownInfo { pub shelley_known_hash: String, pub shelley_known_time: u64, pub address_hrp: String, + pub adahandle_policy: String, } impl ChainWellKnownInfo { @@ -82,6 +83,8 @@ impl ChainWellKnownInfo { .to_string(), shelley_known_time: 1596059091, address_hrp: "addr".to_string(), + adahandle_policy: "f0ff48bbb7bbe9d59a40f1ce90e9e9d0ff5002ec48f232b49ca0fb9a" + .to_string(), } } @@ -101,6 +104,8 @@ impl ChainWellKnownInfo { .to_string(), shelley_known_time: 1595967616, address_hrp: "addr_test".to_string(), + adahandle_policy: "8d18d786e92776c824607fd8e193ec535c79dc61ea2405ddf3b09fe3" + .to_string(), } }