Skip to content

Commit 5eecd74

Browse files
committed
Manually implement display for message in common that own encoded keys
1 parent 46732dc commit 5eecd74

File tree

5 files changed

+172
-11
lines changed

5 files changed

+172
-11
lines changed

mithril-common/src/messages/certificate.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
use serde::{Deserialize, Serialize};
2+
use std::fmt::{Debug, Formatter};
23

34
use crate::entities::{Beacon, ProtocolMessage, ProtocolMessagePartKey};
45
use crate::messages::CertificateMetadataMessagePart;
56
use crate::test_utils::fake_keys;
67

78
/// Message structure of a certificate
8-
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
9+
#[derive(Clone, PartialEq, Serialize, Deserialize)]
910
pub struct CertificateMessage {
1011
/// Hash of the current certificate
1112
/// Computed from the other fields of the certificate
@@ -74,6 +75,35 @@ impl CertificateMessage {
7475
}
7576
}
7677

78+
impl Debug for CertificateMessage {
79+
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
80+
let should_be_exhaustive = f.alternate();
81+
let mut debug = f.debug_struct("Certificate");
82+
debug
83+
.field("hash", &self.hash)
84+
.field("previous_hash", &self.previous_hash)
85+
.field("beacon", &format_args!("{:?}", self.beacon))
86+
.field("metadata", &format_args!("{:?}", self.metadata))
87+
.field(
88+
"protocol_message",
89+
&format_args!("{:?}", self.protocol_message),
90+
)
91+
.field("signed_message", &self.signed_message);
92+
93+
match should_be_exhaustive {
94+
true => debug
95+
.field(
96+
"aggregate_verification_key",
97+
&self.aggregate_verification_key,
98+
)
99+
.field("multi_signature", &self.multi_signature)
100+
.field("genesis_signature", &self.genesis_signature)
101+
.finish(),
102+
false => debug.finish_non_exhaustive(),
103+
}
104+
}
105+
}
106+
77107
#[cfg(test)]
78108
mod tests {
79109
use super::*;

mithril-common/src/messages/certificate_list.rs

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
use chrono::{DateTime, Utc};
22
use serde::{Deserialize, Serialize};
3+
use std::fmt::{Debug, Formatter};
34

4-
use crate::entities::Beacon;
5-
use crate::entities::ProtocolMessage;
6-
use crate::entities::ProtocolMessagePartKey;
7-
use crate::entities::ProtocolParameters;
8-
use crate::entities::ProtocolVersion;
5+
use crate::entities::{
6+
Beacon, ProtocolMessage, ProtocolMessagePartKey, ProtocolParameters, ProtocolVersion,
7+
};
98

109
/// Message structure of a certificate list
1110
pub type CertificateListMessage = Vec<CertificateListItemMessage>;
@@ -40,7 +39,7 @@ pub struct CertificateListItemMessageMetadata {
4039
}
4140

4241
/// Message structure of a certificate list item
43-
#[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
42+
#[derive(Clone, PartialEq, Default, Serialize, Deserialize)]
4443
pub struct CertificateListItemMessage {
4544
/// Hash of the current certificate
4645
/// Computed from the other fields of the certificate
@@ -109,6 +108,33 @@ impl CertificateListItemMessage {
109108
}
110109
}
111110

111+
impl Debug for CertificateListItemMessage {
112+
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
113+
let should_be_exhaustive = f.alternate();
114+
let mut debug = f.debug_struct("Certificate");
115+
debug
116+
.field("hash", &self.hash)
117+
.field("previous_hash", &self.previous_hash)
118+
.field("beacon", &format_args!("{:?}", self.beacon))
119+
.field("metadata", &format_args!("{:?}", self.metadata))
120+
.field(
121+
"protocol_message",
122+
&format_args!("{:?}", self.protocol_message),
123+
)
124+
.field("signed_message", &self.signed_message);
125+
126+
match should_be_exhaustive {
127+
true => debug
128+
.field(
129+
"aggregate_verification_key",
130+
&self.aggregate_verification_key,
131+
)
132+
.finish(),
133+
false => debug.finish_non_exhaustive(),
134+
}
135+
}
136+
}
137+
112138
#[cfg(test)]
113139
mod tests {
114140
use super::*;

mithril-common/src/messages/message_parts/signer.rs

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ use crate::{
88
StdResult,
99
};
1010
use serde::{Deserialize, Serialize};
11+
use std::fmt::{Debug, Formatter};
1112

1213
/// Signer with Stake Message
13-
#[derive(Clone, Debug, PartialEq, Eq, Default, Serialize, Deserialize)]
14+
#[derive(Clone, PartialEq, Eq, Default, Serialize, Deserialize)]
1415
pub struct SignerWithStakeMessagePart {
1516
/// The unique identifier of the signer
1617
// TODO: Should be removed once the signer certification is fully deployed
@@ -108,8 +109,35 @@ impl From<SignerWithStake> for SignerWithStakeMessagePart {
108109
}
109110
}
110111

112+
impl Debug for SignerMessagePart {
113+
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
114+
let should_be_exhaustive = f.alternate();
115+
let mut debug = f.debug_struct("Signer");
116+
debug.field("party_id", &self.party_id);
117+
118+
match should_be_exhaustive {
119+
true => debug
120+
.field(
121+
"verification_key",
122+
&format_args!("{:?}", self.verification_key),
123+
)
124+
.field(
125+
"verification_key_signature",
126+
&format_args!("{:?}", self.verification_key_signature),
127+
)
128+
.field(
129+
"operational_certificate",
130+
&format_args!("{:?}", self.operational_certificate),
131+
)
132+
.field("kes_period", &format_args!("{:?}", self.kes_period))
133+
.finish(),
134+
false => debug.finish_non_exhaustive(),
135+
}
136+
}
137+
}
138+
111139
/// Signer Message
112-
#[derive(Clone, Debug, PartialEq, Eq, Default, Serialize, Deserialize)]
140+
#[derive(Clone, PartialEq, Eq, Default, Serialize, Deserialize)]
113141
pub struct SignerMessagePart {
114142
/// The unique identifier of the signer
115143
// TODO: Should be removed once the signer certification is fully deployed
@@ -153,3 +181,32 @@ impl SignerMessagePart {
153181
}
154182
}
155183
}
184+
185+
impl Debug for SignerWithStakeMessagePart {
186+
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
187+
let should_be_exhaustive = f.alternate();
188+
let mut debug = f.debug_struct("Signer");
189+
debug
190+
.field("party_id", &self.party_id)
191+
.field("stake", &self.stake);
192+
193+
match should_be_exhaustive {
194+
true => debug
195+
.field(
196+
"verification_key",
197+
&format_args!("{:?}", self.verification_key),
198+
)
199+
.field(
200+
"verification_key_signature",
201+
&format_args!("{:?}", self.verification_key_signature),
202+
)
203+
.field(
204+
"operational_certificate",
205+
&format_args!("{:?}", self.operational_certificate),
206+
)
207+
.field("kes_period", &format_args!("{:?}", self.kes_period))
208+
.finish(),
209+
false => debug.finish_non_exhaustive(),
210+
}
211+
}
212+
}

mithril-common/src/messages/register_signature.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use serde::{Deserialize, Serialize};
2+
use std::fmt::{Debug, Formatter};
23

34
use crate::{
45
entities::{HexEncodedSingleSignature, LotteryIndex, PartyId, SignedEntityType},
@@ -7,7 +8,7 @@ use crate::{
78

89
era_deprecate!("make signed_entity_type of RegisterSignatureMessage not optional");
910
/// Message structure to register single signature.
10-
#[derive(Clone, Debug, PartialEq, Eq, Default, Serialize, Deserialize)]
11+
#[derive(Clone, PartialEq, Eq, Default, Serialize, Deserialize)]
1112
pub struct RegisterSignatureMessage {
1213
/// Signed entity type
1314
#[serde(rename = "entity_type")]
@@ -36,6 +37,25 @@ impl RegisterSignatureMessage {
3637
}
3738
}
3839

40+
impl Debug for RegisterSignatureMessage {
41+
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
42+
let is_pretty_printing = f.alternate();
43+
let mut debug = f.debug_struct("SingleSignatures");
44+
debug
45+
.field(
46+
"signed_entity_type",
47+
&format_args!("{:?}", self.signed_entity_type),
48+
)
49+
.field("party_id", &self.party_id)
50+
.field("won_indexes", &format_args!("{:?}", self.won_indexes));
51+
52+
match is_pretty_printing {
53+
true => debug.field("signature", &self.signature).finish(),
54+
false => debug.finish_non_exhaustive(),
55+
}
56+
}
57+
}
58+
3959
#[cfg(test)]
4060
mod tests {
4161
use super::*;

mithril-common/src/messages/register_signer.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use serde::{Deserialize, Serialize};
2+
use std::fmt::{Debug, Formatter};
23

34
use crate::{
45
crypto_helper::KESPeriod,
@@ -11,7 +12,7 @@ use crate::{
1112

1213
era_deprecate!("make epoch of RegisterSignerMessage not optional");
1314
/// Register Signer Message
14-
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
15+
#[derive(Clone, PartialEq, Eq, Serialize, Deserialize)]
1516
pub struct RegisterSignerMessage {
1617
/// Epoch at which registration is sent
1718
/// #[serde(skip_serializing_if = "Option::is_none")]
@@ -61,6 +62,33 @@ impl RegisterSignerMessage {
6162
}
6263
}
6364

65+
impl Debug for RegisterSignerMessage {
66+
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
67+
let should_be_exhaustive = f.alternate();
68+
let mut debug = f.debug_struct("Signer");
69+
debug.field("party_id", &self.party_id);
70+
71+
match should_be_exhaustive {
72+
true => debug
73+
.field(
74+
"verification_key",
75+
&format_args!("{:?}", self.verification_key),
76+
)
77+
.field(
78+
"verification_key_signature",
79+
&format_args!("{:?}", self.verification_key_signature),
80+
)
81+
.field(
82+
"operational_certificate",
83+
&format_args!("{:?}", self.operational_certificate),
84+
)
85+
.field("kes_period", &format_args!("{:?}", self.kes_period))
86+
.finish(),
87+
false => debug.finish_non_exhaustive(),
88+
}
89+
}
90+
}
91+
6492
#[cfg(test)]
6593
mod tests {
6694
use super::*;

0 commit comments

Comments
 (0)