Skip to content

Commit 2365008

Browse files
committed
fix(cardano-blockchain-types): impl display for cip36 error
Signed-off-by: bkioshn <[email protected]>
1 parent 47f8357 commit 2365008

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

rust/cardano-blockchain-types/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,4 @@ num-traits = "0.2.19"
3838
ed25519-dalek = "2.1.1"
3939
serde = "1.0.210"
4040
num-bigint = "0.4.6"
41+
serde_json = "1.0.134"

rust/cardano-blockchain-types/src/metadata/cip36/mod.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ pub mod key_registration;
44
pub mod registration_witness;
55
mod validation;
66
pub mod voting_pk;
7-
8-
use std::collections::HashMap;
7+
use std::{collections::HashMap, fmt};
98

109
use catalyst_types::problem_report::ProblemReport;
1110
use ed25519_dalek::VerifyingKey;
@@ -54,6 +53,19 @@ pub struct Cip36Error {
5453
report: ProblemReport,
5554
}
5655

56+
impl fmt::Display for Cip36Error {
57+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
58+
let report_json = serde_json::to_string(&self.report)
59+
.unwrap_or_else(|_| String::from("Failed to serialize ProblemReport"));
60+
61+
write!(
62+
fmt,
63+
"Cip36Error {{ error: {}, report: {} }}",
64+
self.error, report_json
65+
)
66+
}
67+
}
68+
5769
impl Cip36 {
5870
/// Create an instance of CIP-36.
5971
/// The CIP-36 registration contains the key registration (61284)

0 commit comments

Comments
 (0)