From 29fc3e61de9869dadc6cfeb4a9d22f354d4b58ab Mon Sep 17 00:00:00 2001 From: Eugene P Date: Thu, 10 Jan 2019 12:30:10 +0300 Subject: [PATCH] Implement fmt::Display for core::Hash --- core/src/core/hash.rs | 13 ++++++++++++- src/bin/tui/mining.rs | 13 +------------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/core/src/core/hash.rs b/core/src/core/hash.rs index 4f38c4031..76bd36d2f 100644 --- a/core/src/core/hash.rs +++ b/core/src/core/hash.rs @@ -47,7 +47,18 @@ impl fmt::Debug for Hash { impl fmt::Display for Hash { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt::Debug::fmt(self, f) + let hash_hex = self.to_hex(); + let len = hash_hex.len(); + const NUM_SHOW: usize = 8; + + let starting = &hash_hex[..NUM_SHOW]; + let ending = &hash_hex[(len - NUM_SHOW)..]; + + write!(f, + "{}...{}", + starting, + ending + ) } } diff --git a/src/bin/tui/mining.rs b/src/bin/tui/mining.rs index 61cac6b95..5cf6f1d49 100644 --- a/src/bin/tui/mining.rs +++ b/src/bin/tui/mining.rs @@ -137,18 +137,7 @@ impl TableViewItem for DiffBlock { match column { DiffColumn::Height => self.block_height.to_string(), - DiffColumn::Hash => { - // Prints part of the hash's hex - let hash_hex = self.block_hash.to_hex(); - let len = hash_hex.len(); - const NUM_SHOW: usize = 8; // Number of characters to show - - format!( - "{}...{}", - &hash_hex[..NUM_SHOW / 2], - &hash_hex[(len - NUM_SHOW)..] - ) - } + DiffColumn::Hash => self.block_hash.to_string(), DiffColumn::PoWType => pow_type, DiffColumn::Difficulty => self.difficulty.to_string(), DiffColumn::SecondaryScaling => self.secondary_scaling.to_string(),