+pub(crate) struct DebugTx<'a>(pub &'a Transaction);
+impl<'a> core::fmt::Display for DebugTx<'a> {
+ fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> {
+ if self.0.input.len() >= 1 && self.0.input.iter().any(|i| !i.witness.is_empty()) {
+ if self.0.input.len() == 1 && self.0.input[0].witness.last().unwrap().len() == 71 &&
+ (self.0.input[0].sequence >> 8*3) as u8 == 0x80 {
+ write!(f, "commitment tx ")?;
+ } else if self.0.input.len() == 1 && self.0.input[0].witness.last().unwrap().len() == 71 {
+ write!(f, "closing tx ")?;
+ } else if self.0.input.len() == 1 && HTLCType::scriptlen_to_htlctype(self.0.input[0].witness.last().unwrap().len()) == Some(HTLCType::OfferedHTLC) &&
+ self.0.input[0].witness.len() == 5 {
+ write!(f, "HTLC-timeout tx ")?;
+ } else if self.0.input.len() == 1 && HTLCType::scriptlen_to_htlctype(self.0.input[0].witness.last().unwrap().len()) == Some(HTLCType::AcceptedHTLC) &&
+ self.0.input[0].witness.len() == 5 {
+ write!(f, "HTLC-success tx ")?;
+ } else {
+ for inp in &self.0.input {
+ if !inp.witness.is_empty() {
+ if HTLCType::scriptlen_to_htlctype(inp.witness.last().unwrap().len()) == Some(HTLCType::OfferedHTLC) { write!(f, "preimage-")?; break }
+ else if HTLCType::scriptlen_to_htlctype(inp.witness.last().unwrap().len()) == Some(HTLCType::AcceptedHTLC) { write!(f, "timeout-")?; break }
+ }
+ }
+ write!(f, "tx ")?;
+ }
+ } else {
+ debug_assert!(false, "We should never generate unknown transaction types");
+ write!(f, "unknown tx type ").unwrap();
+ }
+ write!(f, "with txid {}", self.0.txid())?;
+ Ok(())
+ }
+}
+
+macro_rules! log_tx {
+ ($obj: expr) => {
+ ::util::macro_logger::DebugTx(&$obj)
+ }
+}
+
+pub(crate) struct DebugSpendable<'a>(pub &'a SpendableOutputDescriptor);
+impl<'a> core::fmt::Display for DebugSpendable<'a> {
+ fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> {
+ match self.0 {
+ &SpendableOutputDescriptor::StaticOutput { ref outpoint, .. } => {
+ write!(f, "StaticOutput {}:{} marked for spending", outpoint.txid, outpoint.index)?;
+ }
+ &SpendableOutputDescriptor::DelayedPaymentOutput(ref descriptor) => {
+ write!(f, "DelayedPaymentOutput {}:{} marked for spending", descriptor.outpoint.txid, descriptor.outpoint.index)?;
+ }
+ &SpendableOutputDescriptor::StaticPaymentOutput(ref descriptor) => {
+ write!(f, "StaticPaymentOutput {}:{} marked for spending", descriptor.outpoint.txid, descriptor.outpoint.index)?;
+ }
+ }
+ Ok(())
+ }
+}
+
+macro_rules! log_spendable {
+ ($obj: expr) => {
+ ::util::macro_logger::DebugSpendable(&$obj)
+ }
+}
+
+/// Create a new Record and log it. You probably don't want to use this macro directly,
+/// but it needs to be exported so `log_trace` etc can use it in external crates.
+#[macro_export]