From f5ae49f07186bab3b2db47fa1227fc681ffc90f5 Mon Sep 17 00:00:00 2001 From: Eugene P Date: Thu, 10 Jan 2019 06:28:15 +0300 Subject: [PATCH 1/7] Print block hash in TUI partially --- src/bin/tui/mining.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/bin/tui/mining.rs b/src/bin/tui/mining.rs index 5cf6f1d49..b2efcbb2b 100644 --- a/src/bin/tui/mining.rs +++ b/src/bin/tui/mining.rs @@ -137,7 +137,13 @@ impl TableViewItem for DiffBlock { match column { DiffColumn::Height => self.block_height.to_string(), - DiffColumn::Hash => self.block_hash.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::PoWType => pow_type, DiffColumn::Difficulty => self.difficulty.to_string(), DiffColumn::SecondaryScaling => self.secondary_scaling.to_string(), From 282a5ce980dc47439ad713025e80102bd01136bc Mon Sep 17 00:00:00 2001 From: Eugene P Date: Thu, 10 Jan 2019 06:28:28 +0300 Subject: [PATCH 2/7] rustfmt --- src/bin/tui/mining.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/bin/tui/mining.rs b/src/bin/tui/mining.rs index b2efcbb2b..61cac6b95 100644 --- a/src/bin/tui/mining.rs +++ b/src/bin/tui/mining.rs @@ -137,13 +137,18 @@ impl TableViewItem for DiffBlock { match column { DiffColumn::Height => self.block_height.to_string(), - DiffColumn::Hash => { // Prints part of the hash's hex + 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)..]) - }, + format!( + "{}...{}", + &hash_hex[..NUM_SHOW / 2], + &hash_hex[(len - NUM_SHOW)..] + ) + } DiffColumn::PoWType => pow_type, DiffColumn::Difficulty => self.difficulty.to_string(), DiffColumn::SecondaryScaling => self.secondary_scaling.to_string(), From 29fc3e61de9869dadc6cfeb4a9d22f354d4b58ab Mon Sep 17 00:00:00 2001 From: Eugene P Date: Thu, 10 Jan 2019 12:30:10 +0300 Subject: [PATCH 3/7] 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(), From b4e4992a5c25aaae7faebffc85f8fc8eccb7b2cf Mon Sep 17 00:00:00 2001 From: Eugene P Date: Thu, 10 Jan 2019 12:30:21 +0300 Subject: [PATCH 4/7] rustfmt --- core/src/core/hash.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/core/src/core/hash.rs b/core/src/core/hash.rs index 76bd36d2f..61a27baaf 100644 --- a/core/src/core/hash.rs +++ b/core/src/core/hash.rs @@ -54,11 +54,7 @@ impl fmt::Display for Hash { let starting = &hash_hex[..NUM_SHOW]; let ending = &hash_hex[(len - NUM_SHOW)..]; - write!(f, - "{}...{}", - starting, - ending - ) + write!(f, "{}...{}", starting, ending) } } From faff529260be05d560f6e9c2fab3eed88b0bd604 Mon Sep 17 00:00:00 2001 From: Eugene P Date: Thu, 10 Jan 2019 12:39:47 +0300 Subject: [PATCH 5/7] Show first 12 digits of Hash --- core/src/core/hash.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/core/src/core/hash.rs b/core/src/core/hash.rs index 61a27baaf..62170624c 100644 --- a/core/src/core/hash.rs +++ b/core/src/core/hash.rs @@ -48,13 +48,9 @@ impl fmt::Debug for Hash { impl fmt::Display for Hash { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let hash_hex = self.to_hex(); - let len = hash_hex.len(); - const NUM_SHOW: usize = 8; + const NUM_SHOW: usize = 12; - let starting = &hash_hex[..NUM_SHOW]; - let ending = &hash_hex[(len - NUM_SHOW)..]; - - write!(f, "{}...{}", starting, ending) + write!(f, "{}...", &hash_hex[..NUM_SHOW]) } } From bc7b701de3c61bd035b04f0c6a15e0fc9490d060 Mon Sep 17 00:00:00 2001 From: Eugene P Date: Thu, 10 Jan 2019 12:55:10 +0300 Subject: [PATCH 6/7] Show full hex string of hash in fmt::Debug for core::Hash --- core/src/core/hash.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/core/src/core/hash.rs b/core/src/core/hash.rs index 62170624c..8c38f9d77 100644 --- a/core/src/core/hash.rs +++ b/core/src/core/hash.rs @@ -38,10 +38,7 @@ pub struct Hash([u8; 32]); impl fmt::Debug for Hash { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - for i in self.0[..4].iter() { - write!(f, "{:02x}", i)?; - } - Ok(()) + write!(f, "{}", self.to_hex()) } } From 94974ec19a1fd24d5a44050b295694116d601d77 Mon Sep 17 00:00:00 2001 From: Eugene P Date: Thu, 10 Jan 2019 13:01:45 +0300 Subject: [PATCH 7/7] Strip hash in fmt::Debug and use fmt::Debug for fmt::Display --- core/src/core/hash.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/core/src/core/hash.rs b/core/src/core/hash.rs index 8c38f9d77..378940436 100644 --- a/core/src/core/hash.rs +++ b/core/src/core/hash.rs @@ -38,16 +38,16 @@ pub struct Hash([u8; 32]); impl fmt::Debug for Hash { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{}", self.to_hex()) + let hash_hex = self.to_hex(); + const NUM_SHOW: usize = 12; + + write!(f, "{}...", &hash_hex[..NUM_SHOW]) } } impl fmt::Display for Hash { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let hash_hex = self.to_hex(); - const NUM_SHOW: usize = 12; - - write!(f, "{}...", &hash_hex[..NUM_SHOW]) + fmt::Debug::fmt(self, f) } }