Skip to content

Commit 04cb808

Browse files
committed
Somewhat DRY pay_for_offer_intern callback method
1 parent 58b0951 commit 04cb808

1 file changed

Lines changed: 15 additions & 32 deletions

File tree

lightning/src/ln/channelmanager.rs

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12295,17 +12295,11 @@ where
1229512295
&self, offer: &Offer, amount_msats: Option<u64>, payment_id: PaymentId,
1229612296
optional_params: OptionalOfferPaymentParams,
1229712297
) -> Result<(), Bolt12SemanticError> {
12298-
let create_pending_payment_fn = |invoice_request: &InvoiceRequest, nonce| {
12299-
let expiration = StaleExpiration::TimerTicks(1);
12300-
let retryable_invoice_request = RetryableInvoiceRequest {
12301-
invoice_request: invoice_request.clone(),
12302-
nonce,
12303-
needs_retry: true,
12304-
};
12298+
let create_pending_payment_fn = |retryable_invoice_request: RetryableInvoiceRequest| {
1230512299
self.pending_outbound_payments
1230612300
.add_new_awaiting_invoice(
1230712301
payment_id,
12308-
expiration,
12302+
StaleExpiration::TimerTicks(1),
1230912303
optional_params.retry_strategy,
1231012304
optional_params.route_params_config,
1231112305
Some(retryable_invoice_request),
@@ -12330,17 +12324,11 @@ where
1233012324
&self, offer: &OfferFromHrn, amount_msats: u64, payment_id: PaymentId,
1233112325
optional_params: OptionalOfferPaymentParams,
1233212326
) -> Result<(), Bolt12SemanticError> {
12333-
let create_pending_payment_fn = |invoice_request: &InvoiceRequest, nonce| {
12334-
let expiration = StaleExpiration::TimerTicks(1);
12335-
let retryable_invoice_request = RetryableInvoiceRequest {
12336-
invoice_request: invoice_request.clone(),
12337-
nonce,
12338-
needs_retry: true,
12339-
};
12327+
let create_pending_payment_fn = |retryable_invoice_request: RetryableInvoiceRequest| {
1234012328
self.pending_outbound_payments
1234112329
.add_new_awaiting_invoice(
1234212330
payment_id,
12343-
expiration,
12331+
StaleExpiration::TimerTicks(1),
1234412332
optional_params.retry_strategy,
1234512333
optional_params.route_params_config,
1234612334
Some(retryable_invoice_request),
@@ -12378,17 +12366,11 @@ where
1237812366
&self, offer: &Offer, amount_msats: Option<u64>, payment_id: PaymentId,
1237912367
optional_params: OptionalOfferPaymentParams, quantity: u64,
1238012368
) -> Result<(), Bolt12SemanticError> {
12381-
let create_pending_payment_fn = |invoice_request: &InvoiceRequest, nonce| {
12382-
let expiration = StaleExpiration::TimerTicks(1);
12383-
let retryable_invoice_request = RetryableInvoiceRequest {
12384-
invoice_request: invoice_request.clone(),
12385-
nonce,
12386-
needs_retry: true,
12387-
};
12369+
let create_pending_payment_fn = |retryable_invoice_request: RetryableInvoiceRequest| {
1238812370
self.pending_outbound_payments
1238912371
.add_new_awaiting_invoice(
1239012372
payment_id,
12391-
expiration,
12373+
StaleExpiration::TimerTicks(1),
1239212374
optional_params.retry_strategy,
1239312375
optional_params.route_params_config,
1239412376
Some(retryable_invoice_request),
@@ -12408,7 +12390,7 @@ where
1240812390
}
1240912391

1241012392
#[rustfmt::skip]
12411-
fn pay_for_offer_intern<CPP: FnOnce(&InvoiceRequest, Nonce) -> Result<(), Bolt12SemanticError>>(
12393+
fn pay_for_offer_intern<CPP: FnOnce(RetryableInvoiceRequest) -> Result<(), Bolt12SemanticError>>(
1241212394
&self, offer: &Offer, quantity: Option<u64>, amount_msats: Option<u64>,
1241312395
payer_note: Option<String>, payment_id: PaymentId,
1241412396
human_readable_name: Option<HumanReadableName>, create_pending_payment: CPP,
@@ -12445,7 +12427,13 @@ where
1244512427
self.get_peers_for_blinded_path()
1244612428
)?;
1244712429

12448-
create_pending_payment(&invoice_request, nonce)
12430+
let retryable_invoice_request = RetryableInvoiceRequest {
12431+
invoice_request: invoice_request.clone(),
12432+
nonce,
12433+
needs_retry: true,
12434+
};
12435+
12436+
create_pending_payment(retryable_invoice_request)
1244912437
}
1245012438

1245112439
/// Creates a [`Bolt12Invoice`] for a [`Refund`] and enqueues it to be sent via an onion
@@ -14824,12 +14812,7 @@ where
1482414812
if let Ok((amt_msats, payer_note)) = self.pending_outbound_payments.params_for_payment_awaiting_offer(payment_id) {
1482514813
let offer_pay_res =
1482614814
self.pay_for_offer_intern(&offer, None, Some(amt_msats), payer_note, payment_id, Some(name),
14827-
|invoice_request, nonce| {
14828-
let retryable_invoice_request = RetryableInvoiceRequest {
14829-
invoice_request: invoice_request.clone(),
14830-
nonce,
14831-
needs_retry: true,
14832-
};
14815+
|retryable_invoice_request| {
1483314816
self.pending_outbound_payments
1483414817
.received_offer(payment_id, Some(retryable_invoice_request))
1483514818
.map_err(|_| Bolt12SemanticError::DuplicatePaymentId)

0 commit comments

Comments
 (0)