Add logger for SpendableOutputDescriptor
authorAntoine Riard <ariard@student.42.fr>
Tue, 3 Mar 2020 19:41:13 +0000 (14:41 -0500)
committerAntoine Riard <ariard@student.42.fr>
Fri, 20 Mar 2020 02:29:26 +0000 (22:29 -0400)
lightning/src/ln/channelmonitor.rs
lightning/src/util/macro_logger.rs

index 8c26139c4cba1fa750c8ba07e9637fcf16becf79..c2dd9c352a32a4885d8204680a70f3819125b028 100644 (file)
@@ -2132,6 +2132,10 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
                        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,
index e3a431ed54f8614d988c8ad2654d7389d9ed1e59..5a70241428bacf3d974d86bc96b349ec37ac544f 100644 (file)
@@ -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!()));