Skip to content

Commit

Permalink
add debug to other hashes
Browse files Browse the repository at this point in the history
  • Loading branch information
damip committed Jan 26, 2022
1 parent ead81d2 commit 21e5a7b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
8 changes: 7 additions & 1 deletion massa-models/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand All @@ -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<Self, Self::Err> {
Expand Down
8 changes: 7 additions & 1 deletion massa-models/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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<Self, Self::Err> {
Expand Down
9 changes: 8 additions & 1 deletion massa-models/src/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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<Self, Self::Err> {
Expand All @@ -50,6 +56,7 @@ impl OperationId {
Hash::from_bytes(data).map_err(|_| ModelsError::HashError)?,
))
}

pub fn from_bs58_check(data: &str) -> Result<OperationId, ModelsError> {
Ok(OperationId(
Hash::from_bs58_check(data).map_err(|_| ModelsError::HashError)?,
Expand Down

0 comments on commit 21e5a7b

Please sign in to comment.