mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-03-15 15:39:09 +01:00
Use Display of PaymentId&PaymentPreimage; avoid log_bytes macro
This commit is contained in:
parent
b35b8cfbf4
commit
4146264b16
3 changed files with 23 additions and 13 deletions
|
@ -6331,10 +6331,10 @@ where
|
|||
match monitor_event {
|
||||
MonitorEvent::HTLCEvent(htlc_update) => {
|
||||
if let Some(preimage) = htlc_update.payment_preimage {
|
||||
log_trace!(self.logger, "Claiming HTLC with preimage {} from our monitor", log_bytes!(preimage.0));
|
||||
log_trace!(self.logger, "Claiming HTLC with preimage {} from our monitor", &preimage);
|
||||
self.claim_funds_internal(htlc_update.source, preimage, htlc_update.htlc_value_satoshis.map(|v| v * 1000), true, funding_outpoint);
|
||||
} else {
|
||||
log_trace!(self.logger, "Failing HTLC with hash {} from our monitor", log_bytes!(htlc_update.payment_hash.0));
|
||||
log_trace!(self.logger, "Failing HTLC with hash {} from our monitor", &htlc_update.payment_hash);
|
||||
let receiver = HTLCDestination::NextHopChannel { node_id: counterparty_node_id, channel_id: funding_outpoint.to_channel_id() };
|
||||
let reason = HTLCFailReason::from_failure_code(0x4000 | 8);
|
||||
self.fail_htlc_backwards_internal(&htlc_update.source, &htlc_update.payment_hash, &reason, receiver);
|
||||
|
@ -10551,8 +10551,12 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_payment_display() {
|
||||
let payment_id = PaymentId([42; 32]);
|
||||
assert_eq!(format!("{}", &payment_id), "2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a");
|
||||
let payment_hash = PaymentHash([42; 32]);
|
||||
assert_eq!(format!("{}", &payment_hash), "2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a");
|
||||
let payment_preimage = PaymentPreimage([42; 32]);
|
||||
assert_eq!(format!("{}", &payment_preimage), "2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -739,7 +739,7 @@ impl OutboundPayments {
|
|||
|
||||
let res = self.pay_route_internal(&route, payment_hash, recipient_onion, keysend_preimage, payment_id, None,
|
||||
onion_session_privs, node_signer, best_block_height, &send_payment_along_path);
|
||||
log_info!(logger, "Result sending payment with id {}: {:?}", log_bytes!(payment_id.0), res);
|
||||
log_info!(logger, "Result sending payment with id {}: {:?}", &payment_id, res);
|
||||
if let Err(e) = res {
|
||||
self.handle_pay_route_err(e, payment_id, payment_hash, route, route_params, router, first_hops, &inflight_htlcs, entropy_source, node_signer, best_block_height, logger, pending_events, &send_payment_along_path);
|
||||
}
|
||||
|
@ -762,7 +762,7 @@ impl OutboundPayments {
|
|||
{
|
||||
#[cfg(feature = "std")] {
|
||||
if has_expired(&route_params) {
|
||||
log_error!(logger, "Payment params expired on retry, abandoning payment {}", log_bytes!(payment_id.0));
|
||||
log_error!(logger, "Payment params expired on retry, abandoning payment {}", &payment_id);
|
||||
self.abandon_payment(payment_id, PaymentFailureReason::PaymentExpired, pending_events);
|
||||
return
|
||||
}
|
||||
|
@ -775,7 +775,7 @@ impl OutboundPayments {
|
|||
) {
|
||||
Ok(route) => route,
|
||||
Err(e) => {
|
||||
log_error!(logger, "Failed to find a route on retry, abandoning payment {}: {:#?}", log_bytes!(payment_id.0), e);
|
||||
log_error!(logger, "Failed to find a route on retry, abandoning payment {}: {:#?}", &payment_id, e);
|
||||
self.abandon_payment(payment_id, PaymentFailureReason::RouteNotFound, pending_events);
|
||||
return
|
||||
}
|
||||
|
@ -844,7 +844,7 @@ impl OutboundPayments {
|
|||
},
|
||||
};
|
||||
if !payment.get().is_retryable_now() {
|
||||
log_error!(logger, "Retries exhausted for payment id {}", log_bytes!(payment_id.0));
|
||||
log_error!(logger, "Retries exhausted for payment id {}", &payment_id);
|
||||
abandon_with_entry!(payment, PaymentFailureReason::RetriesExhausted);
|
||||
return
|
||||
}
|
||||
|
@ -855,7 +855,7 @@ impl OutboundPayments {
|
|||
res
|
||||
},
|
||||
hash_map::Entry::Vacant(_) => {
|
||||
log_error!(logger, "Payment with ID {} not found", log_bytes!(payment_id.0));
|
||||
log_error!(logger, "Payment with ID {} not found", &payment_id);
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -863,7 +863,7 @@ impl OutboundPayments {
|
|||
let res = self.pay_route_internal(&route, payment_hash, recipient_onion, keysend_preimage,
|
||||
payment_id, Some(total_msat), onion_session_privs, node_signer, best_block_height,
|
||||
&send_payment_along_path);
|
||||
log_info!(logger, "Result retrying payment id {}: {:?}", log_bytes!(payment_id.0), res);
|
||||
log_info!(logger, "Result retrying payment id {}: {:?}", &payment_id, res);
|
||||
if let Err(e) = res {
|
||||
self.handle_pay_route_err(e, payment_id, payment_hash, route, route_params, router, first_hops, inflight_htlcs, entropy_source, node_signer, best_block_height, logger, pending_events, send_payment_along_path);
|
||||
}
|
||||
|
@ -1215,7 +1215,7 @@ impl OutboundPayments {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
log_trace!(logger, "Received duplicative fulfill for HTLC with payment_preimage {}", log_bytes!(payment_preimage.0));
|
||||
log_trace!(logger, "Received duplicative fulfill for HTLC with payment_preimage {}", &payment_preimage);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -88,12 +88,12 @@ impl NodeId {
|
|||
|
||||
impl fmt::Debug for NodeId {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "NodeId({})", log_bytes!(self.0))
|
||||
write!(f, "NodeId({})", crate::util::logger::DebugBytes(&self.0))
|
||||
}
|
||||
}
|
||||
impl fmt::Display for NodeId {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}", log_bytes!(self.0))
|
||||
crate::util::logger::DebugBytes(&self.0).fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -899,7 +899,7 @@ impl ChannelInfo {
|
|||
impl fmt::Display for ChannelInfo {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||
write!(f, "features: {}, node_one: {}, one_to_two: {:?}, node_two: {}, two_to_one: {:?}",
|
||||
log_bytes!(self.features.encode()), log_bytes!(self.node_one.as_slice()), self.one_to_two, log_bytes!(self.node_two.as_slice()), self.two_to_one)?;
|
||||
log_bytes!(self.features.encode()), &self.node_one, self.one_to_two, &self.node_two, self.two_to_one)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -1350,7 +1350,7 @@ impl<L: Deref> fmt::Display for NetworkGraph<L> where L::Target: Logger {
|
|||
}
|
||||
writeln!(f, "[Nodes]")?;
|
||||
for (&node_id, val) in self.nodes.read().unwrap().unordered_iter() {
|
||||
writeln!(f, " {}: {}", log_bytes!(node_id.as_slice()), val)?;
|
||||
writeln!(f, " {}: {}", &node_id, val)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -3429,6 +3429,12 @@ pub(crate) mod tests {
|
|||
// This serialized info has an address field but no announcement_message, therefore the addresses returned by our function will still be empty
|
||||
assert!(ann_info_with_addresses.addresses().is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_node_id_display() {
|
||||
let node_id = NodeId([42; 33]);
|
||||
assert_eq!(format!("{}", &node_id), "2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a");
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(ldk_bench)]
|
||||
|
|
Loading…
Add table
Reference in a new issue