commands: print the PSBT in base64 on sanity checks failure

To make it readable..
This commit is contained in:
Antoine Poinsot 2023-02-16 16:12:28 +01:00
parent 6e1c41238f
commit 518eb91064
No known key found for this signature in database
GPG Key ID: E13FC145CD3F4304
2 changed files with 11 additions and 4 deletions

View File

@ -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) => {

View File

@ -15,12 +15,16 @@ where
Ok(bitcoin::Amount::from_sat(a))
}
pub fn to_base64_string<T: consensus::Encodable>(t: T) -> String {
base64::encode(consensus::serialize(&t))
}
pub fn ser_base64<S, T>(t: T, s: S) -> Result<S::Ok, S::Error>
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<T, D::Error>