1 use chain::transaction::OutPoint;
3 use bitcoin_hashes::sha256d::Hash as Sha256dHash;
4 use bitcoin::blockdata::transaction::Transaction;
5 use secp256k1::key::PublicKey;
11 pub(crate) struct DebugPubKey<'a>(pub &'a PublicKey);
12 impl<'a> std::fmt::Display for DebugPubKey<'a> {
13 fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
14 for i in self.0.serialize().iter() {
15 write!(f, "{:02x}", i)?;
20 macro_rules! log_pubkey {
22 ::util::macro_logger::DebugPubKey(&$obj)
26 pub(crate) struct DebugBytes<'a>(pub &'a [u8]);
27 impl<'a> std::fmt::Display for DebugBytes<'a> {
28 fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
30 write!(f, "{:02x}", i)?;
35 macro_rules! log_bytes {
37 ::util::macro_logger::DebugBytes(&$obj)
41 pub(crate) struct DebugFundingChannelId<'a>(pub &'a Sha256dHash, pub u16);
42 impl<'a> std::fmt::Display for DebugFundingChannelId<'a> {
43 fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
44 for i in OutPoint::new(self.0.clone(), self.1).to_channel_id().iter() {
45 write!(f, "{:02x}", i)?;
50 macro_rules! log_funding_channel_id {
51 ($funding_txid: expr, $funding_txo: expr) => {
52 ::util::macro_logger::DebugFundingChannelId(&$funding_txid, $funding_txo)
56 pub(crate) struct DebugFundingInfo<'a, T: 'a>(pub &'a Option<(OutPoint, T)>);
57 impl<'a, T> std::fmt::Display for DebugFundingInfo<'a, T> {
58 fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
59 match self.0.as_ref() {
60 Some(&(ref funding_output, _)) => DebugBytes(&funding_output.to_channel_id()[..]).fmt(f),
61 None => write!(f, "without funding output set"),
65 macro_rules! log_funding_info {
66 ($key_storage: expr) => {
68 Storage::Local { ref funding_info, .. } => {
69 ::util::macro_logger::DebugFundingInfo(&funding_info)
71 Storage::Watchtower { .. } => {
72 ::util::macro_logger::DebugFundingInfo(&None)
78 pub(crate) struct DebugRoute<'a>(pub &'a Route);
79 impl<'a> std::fmt::Display for DebugRoute<'a> {
80 fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
81 for h in self.0.hops.iter() {
82 write!(f, "node_id: {}, short_channel_id: {}, fee_msat: {}, cltv_expiry_delta: {}\n", log_pubkey!(h.pubkey), h.short_channel_id, h.fee_msat, h.cltv_expiry_delta)?;
87 macro_rules! log_route {
89 ::util::macro_logger::DebugRoute(&$obj)
93 pub(crate) struct DebugTx<'a>(pub &'a Transaction);
94 impl<'a> std::fmt::Display for DebugTx<'a> {
95 fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
96 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")?; }
97 else if self.0.input.len() == 1 && self.0.input[0].witness.last().unwrap().len() == 71 { write!(f, "closing tx")?; }
98 else if self.0.input.len() == 1 && self.0.input[0].witness.last().unwrap().len() == 133 && self.0.input[0].witness.len() == 5 { write!(f, "HTLC-timeout tx")?; }
99 else if self.0.input.len() == 1 && (self.0.input[0].witness.last().unwrap().len() == 138 || self.0.input[0].witness.last().unwrap().len() == 139) && self.0.input[0].witness.len() == 5 { write!(f, "HTLC-success tx")?; }
101 for inp in &self.0.input {
102 if inp.witness.last().unwrap().len() == 133 { write!(f, "preimage tx")?; break }
103 else if inp.witness.last().unwrap().len() == 138 { write!(f, "timeout tx")?; break }
110 macro_rules! log_tx {
112 ::util::macro_logger::DebugTx(&$obj)
116 macro_rules! log_internal {
117 ($self: ident, $lvl:expr, $($arg:tt)+) => (
118 &$self.logger.log(&::util::logger::Record::new($lvl, format_args!($($arg)+), module_path!(), file!(), line!()));
122 macro_rules! log_error {
123 ($self: ident, $($arg:tt)*) => (
124 #[cfg(not(any(feature = "max_level_off")))]
125 log_internal!($self, $crate::util::logger::Level::Error, $($arg)*);
129 macro_rules! log_warn {
130 ($self: ident, $($arg:tt)*) => (
131 #[cfg(not(any(feature = "max_level_off", feature = "max_level_error")))]
132 log_internal!($self, $crate::util::logger::Level::Warn, $($arg)*);
136 macro_rules! log_info {
137 ($self: ident, $($arg:tt)*) => (
138 #[cfg(not(any(feature = "max_level_off", feature = "max_level_error", feature = "max_level_warn")))]
139 log_internal!($self, $crate::util::logger::Level::Info, $($arg)*);
143 macro_rules! log_debug {
144 ($self: ident, $($arg:tt)*) => (
145 #[cfg(not(any(feature = "max_level_off", feature = "max_level_error", feature = "max_level_warn", feature = "max_level_info")))]
146 log_internal!($self, $crate::util::logger::Level::Debug, $($arg)*);
150 macro_rules! log_trace {
151 ($self: ident, $($arg:tt)*) => (
152 #[cfg(not(any(feature = "max_level_off", feature = "max_level_error", feature = "max_level_warn", feature = "max_level_info", feature = "max_level_debug")))]
153 log_internal!($self, $crate::util::logger::Level::Trace, $($arg)*);