From: Antoine Riard Date: Tue, 3 Mar 2020 19:41:13 +0000 (-0500) Subject: Add logger for SpendableOutputDescriptor X-Git-Tag: v0.0.12~97^2~6 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=c61d7de892b41eb4018083bfdabc6abb34a9399c;p=rust-lightning Add logger for SpendableOutputDescriptor --- diff --git a/lightning/src/ln/channelmonitor.rs b/lightning/src/ln/channelmonitor.rs index 8c26139c4..c2dd9c352 100644 --- a/lightning/src/ln/channelmonitor.rs +++ b/lightning/src/ln/channelmonitor.rs @@ -2132,6 +2132,10 @@ impl ChannelMonitor { self.outputs_to_watch.insert(txid.clone(), output_scripts.iter().map(|o| o.script_pubkey.clone()).collect()); } + for spend in spendable_outputs.iter() { + log_trace!(self, "Announcing spendable output to user: {}", log_spendable!(spend)); + } + if spendable_outputs.len() > 0 { self.pending_events.push(events::Event::SpendableOutputs { outputs: spendable_outputs, diff --git a/lightning/src/util/macro_logger.rs b/lightning/src/util/macro_logger.rs index e3a431ed5..5a7024142 100644 --- a/lightning/src/util/macro_logger.rs +++ b/lightning/src/util/macro_logger.rs @@ -1,4 +1,5 @@ use chain::transaction::OutPoint; +use chain::keysinterface::SpendableOutputDescriptor; use bitcoin_hashes::sha256d::Hash as Sha256dHash; use bitcoin::blockdata::transaction::Transaction; @@ -128,6 +129,30 @@ macro_rules! log_tx { } } +pub(crate) struct DebugSpendable<'a>(pub &'a SpendableOutputDescriptor); +impl<'a> std::fmt::Display for DebugSpendable<'a> { + fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> { + match self.0 { + &SpendableOutputDescriptor::StaticOutput { ref outpoint, .. } => { + write!(f, "StaticOutput {}:{} marked for spending", outpoint.txid, outpoint.vout)?; + } + &SpendableOutputDescriptor::DynamicOutputP2WSH { ref outpoint, .. } => { + write!(f, "DynamicOutputP2WSH {}:{} marked for spending", outpoint.txid, outpoint.vout)?; + } + &SpendableOutputDescriptor::DynamicOutputP2WPKH { ref outpoint, .. } => { + write!(f, "DynamicOutputP2WPKH {}:{} marked for spending", outpoint.txid, outpoint.vout)?; + } + } + Ok(()) + } +} + +macro_rules! log_spendable { + ($obj: expr) => { + ::util::macro_logger::DebugSpendable(&$obj) + } +} + macro_rules! log_internal { ($self: ident, $lvl:expr, $($arg:tt)+) => ( &$self.logger.log(&::util::logger::Record::new($lvl, format_args!($($arg)+), module_path!(), file!(), line!()));