From 518eb91064ac4120792b71cec8f52eb26e359b89 Mon Sep 17 00:00:00 2001 From: Antoine Poinsot Date: Thu, 16 Feb 2023 16:12:28 +0100 Subject: [PATCH] commands: print the PSBT in base64 on sanity checks failure To make it readable.. --- src/commands/mod.rs | 9 ++++++--- src/commands/utils.rs | 6 +++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 080aaccc..07d5ed04 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -10,7 +10,10 @@ use crate::{ descriptors, DaemonControl, VERSION, }; -use utils::{deser_amount_from_sats, deser_base64, deser_hex, ser_amount, ser_base64, ser_hex}; +use utils::{ + deser_amount_from_sats, deser_base64, deser_hex, ser_amount, ser_base64, ser_hex, + to_base64_string, +}; use std::{ collections::{hash_map, BTreeMap, HashMap}, @@ -105,8 +108,8 @@ impl fmt::Display for CommandError { } Self::SanityCheckFailure(psbt) => write!( f, - "BUG! Please report this. Failed sanity checks for PSBT '{:?}'.", - psbt + "BUG! Please report this. Failed sanity checks for PSBT '{}'.", + to_base64_string(psbt) ), Self::UnknownSpend(txid) => write!(f, "Unknown spend transaction '{}'.", txid), Self::SpendFinalization(e) => { diff --git a/src/commands/utils.rs b/src/commands/utils.rs index 6c1ae85a..85ac95ea 100644 --- a/src/commands/utils.rs +++ b/src/commands/utils.rs @@ -15,12 +15,16 @@ where Ok(bitcoin::Amount::from_sat(a)) } +pub fn to_base64_string(t: T) -> String { + base64::encode(consensus::serialize(&t)) +} + pub fn ser_base64(t: T, s: S) -> Result where S: Serializer, T: consensus::Encodable, { - s.serialize_str(&base64::encode(consensus::serialize(&t))) + s.serialize_str(&to_base64_string(t)) } pub fn deser_base64<'de, D, T>(d: D) -> Result