Skip to content

Commit 69c9a34

Browse files
committed
Add Display to PaymentId, PaymentPreimage
1 parent 774046d commit 69c9a34

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

lightning/src/ln/channelmanager.rs

+7
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use bitcoin::blockdata::constants::{genesis_block, ChainHash};
2323
use bitcoin::network::constants::Network;
2424

2525
use bitcoin::hashes::Hash;
26+
use bitcoin::hashes::hex::ToHex;
2627
use bitcoin::hashes::sha256::Hash as Sha256;
2728
use bitcoin::hash_types::{BlockHash, Txid};
2829

@@ -240,6 +241,12 @@ impl Readable for PaymentId {
240241
}
241242
}
242243

244+
impl core::fmt::Display for PaymentId {
245+
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
246+
f.write_str(&self.0.to_hex())
247+
}
248+
}
249+
243250
/// An identifier used to uniquely identify an intercepted HTLC to LDK.
244251
///
245252
/// This is not exported to bindings users as we just use [u8; 32] directly

lightning/src/ln/mod.rs

+7
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ impl core::fmt::Display for PaymentHash {
8888
/// This is not exported to bindings users as we just use [u8; 32] directly
8989
#[derive(Hash, Copy, Clone, PartialEq, Eq, Debug, Ord, PartialOrd)]
9090
pub struct PaymentPreimage(pub [u8; 32]);
91+
92+
impl core::fmt::Display for PaymentPreimage {
93+
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
94+
f.write_str(&self.0.to_hex())
95+
}
96+
}
97+
9198
/// payment_secret type, use to authenticate sender to the receiver and tie MPP HTLCs together
9299
///
93100
/// This is not exported to bindings users as we just use [u8; 32] directly

lightning/src/ln/outbound_payment.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ impl OutboundPayments {
739739

740740
let res = self.pay_route_internal(&route, payment_hash, recipient_onion, keysend_preimage, payment_id, None,
741741
onion_session_privs, node_signer, best_block_height, &send_payment_along_path);
742-
log_info!(logger, "Result sending payment with id {}: {:?}", log_bytes!(payment_id.0), res);
742+
log_info!(logger, "Result sending payment with id {}: {:?}", &payment_id, res);
743743
if let Err(e) = res {
744744
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);
745745
}
@@ -762,7 +762,7 @@ impl OutboundPayments {
762762
{
763763
#[cfg(feature = "std")] {
764764
if has_expired(&route_params) {
765-
log_error!(logger, "Payment params expired on retry, abandoning payment {}", log_bytes!(payment_id.0));
765+
log_error!(logger, "Payment params expired on retry, abandoning payment {}", &payment_id);
766766
self.abandon_payment(payment_id, PaymentFailureReason::PaymentExpired, pending_events);
767767
return
768768
}
@@ -775,7 +775,7 @@ impl OutboundPayments {
775775
) {
776776
Ok(route) => route,
777777
Err(e) => {
778-
log_error!(logger, "Failed to find a route on retry, abandoning payment {}: {:#?}", log_bytes!(payment_id.0), e);
778+
log_error!(logger, "Failed to find a route on retry, abandoning payment {}: {:#?}", &payment_id, e);
779779
self.abandon_payment(payment_id, PaymentFailureReason::RouteNotFound, pending_events);
780780
return
781781
}
@@ -844,7 +844,7 @@ impl OutboundPayments {
844844
},
845845
};
846846
if !payment.get().is_retryable_now() {
847-
log_error!(logger, "Retries exhausted for payment id {}", log_bytes!(payment_id.0));
847+
log_error!(logger, "Retries exhausted for payment id {}", &payment_id);
848848
abandon_with_entry!(payment, PaymentFailureReason::RetriesExhausted);
849849
return
850850
}
@@ -855,15 +855,15 @@ impl OutboundPayments {
855855
res
856856
},
857857
hash_map::Entry::Vacant(_) => {
858-
log_error!(logger, "Payment with ID {} not found", log_bytes!(payment_id.0));
858+
log_error!(logger, "Payment with ID {} not found", &payment_id);
859859
return
860860
}
861861
}
862862
};
863863
let res = self.pay_route_internal(&route, payment_hash, recipient_onion, keysend_preimage,
864864
payment_id, Some(total_msat), onion_session_privs, node_signer, best_block_height,
865865
&send_payment_along_path);
866-
log_info!(logger, "Result retrying payment id {}: {:?}", log_bytes!(payment_id.0), res);
866+
log_info!(logger, "Result retrying payment id {}: {:?}", &payment_id, res);
867867
if let Err(e) = res {
868868
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);
869869
}
@@ -1215,7 +1215,7 @@ impl OutboundPayments {
12151215
}
12161216
}
12171217
} else {
1218-
log_trace!(logger, "Received duplicative fulfill for HTLC with payment_preimage {}", log_bytes!(payment_preimage.0));
1218+
log_trace!(logger, "Received duplicative fulfill for HTLC with payment_preimage {}", &payment_preimage);
12191219
}
12201220
}
12211221

0 commit comments

Comments
 (0)