From ead81d27a186eb63038879698ea3ba64e2ee2a5e Mon Sep 17 00:00:00 2001 From: damip Date: Wed, 26 Jan 2022 15:45:05 +0100 Subject: [PATCH 1/2] add debug to hashes --- massa-hash/src/hash.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/massa-hash/src/hash.rs b/massa-hash/src/hash.rs index cdd77e3efc0..fb4996283a9 100644 --- a/massa-hash/src/hash.rs +++ b/massa-hash/src/hash.rs @@ -5,7 +5,7 @@ use crate::settings::HASH_SIZE_BYTES; use bitcoin_hashes; use std::{convert::TryInto, str::FromStr}; -#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Copy, Clone, Hash)] +#[derive(Eq, PartialEq, Ord, PartialOrd, Copy, Clone, Hash)] pub struct Hash(bitcoin_hashes::sha256::Hash); impl std::fmt::Display for Hash { @@ -14,6 +14,12 @@ impl std::fmt::Display for Hash { } } +impl std::fmt::Debug for Hash { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + write!(f, "{}", self.to_bs58_check()) + } +} + impl Hash { /// Compute a hash from data. /// From 21e5a7b7b69323ee859b6cae1290a6ff6d0f0dac Mon Sep 17 00:00:00 2001 From: damip Date: Wed, 26 Jan 2022 15:46:23 +0100 Subject: [PATCH 2/2] add debug to other hashes --- massa-models/src/block.rs | 8 +++++++- massa-models/src/node.rs | 8 +++++++- massa-models/src/operation.rs | 9 ++++++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/massa-models/src/block.rs b/massa-models/src/block.rs index a167aa53ba6..3bf0f0f05f8 100644 --- a/massa-models/src/block.rs +++ b/massa-models/src/block.rs @@ -18,7 +18,7 @@ use std::convert::TryInto; use std::fmt::Formatter; use std::str::FromStr; -#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)] +#[derive(Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)] pub struct BlockId(pub Hash); impl PreHashed for BlockId {} @@ -29,6 +29,12 @@ impl std::fmt::Display for BlockId { } } +impl std::fmt::Debug for BlockId { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + write!(f, "{}", self.0.to_bs58_check()) + } +} + impl FromStr for BlockId { type Err = ModelsError; fn from_str(s: &str) -> Result { diff --git a/massa-models/src/node.rs b/massa-models/src/node.rs index df0c3d5dce7..2bda59d74a4 100644 --- a/massa-models/src/node.rs +++ b/massa-models/src/node.rs @@ -4,7 +4,7 @@ use massa_signature::PublicKey; use serde::{Deserialize, Serialize}; /// NodeId wraps a public key to uniquely identify a node. -#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)] +#[derive(Clone, Copy, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)] pub struct NodeId(pub PublicKey); impl std::fmt::Display for NodeId { @@ -13,6 +13,12 @@ impl std::fmt::Display for NodeId { } } +impl std::fmt::Debug for NodeId { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + write!(f, "{}", self.0.to_bs58_check()) + } +} + impl std::str::FromStr for NodeId { type Err = (); fn from_str(s: &str) -> Result { diff --git a/massa-models/src/operation.rs b/massa-models/src/operation.rs index 986e70486a1..5097dd112bc 100644 --- a/massa-models/src/operation.rs +++ b/massa-models/src/operation.rs @@ -18,7 +18,7 @@ use std::convert::TryInto; use std::fmt::Formatter; use std::{ops::RangeInclusive, str::FromStr}; -#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)] +#[derive(Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)] pub struct OperationId(Hash); impl std::fmt::Display for OperationId { @@ -27,6 +27,12 @@ impl std::fmt::Display for OperationId { } } +impl std::fmt::Debug for OperationId { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + write!(f, "{}", self.0.to_bs58_check()) + } +} + impl FromStr for OperationId { type Err = ModelsError; fn from_str(s: &str) -> Result { @@ -50,6 +56,7 @@ impl OperationId { Hash::from_bytes(data).map_err(|_| ModelsError::HashError)?, )) } + pub fn from_bs58_check(data: &str) -> Result { Ok(OperationId( Hash::from_bs58_check(data).map_err(|_| ModelsError::HashError)?,