Skip to content

Commit dbf40d3

Browse files
committed
Somewhat DRY pay_for_offer_intern callback method
1 parent 0c13a66 commit dbf40d3

File tree

1 file changed

+15
-32
lines changed

1 file changed

+15
-32
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12325,17 +12325,11 @@ where
1232512325
&self, offer: &Offer, amount_msats: Option<u64>, payment_id: PaymentId,
1232612326
optional_params: OptionalOfferPaymentParams,
1232712327
) -> Result<(), Bolt12SemanticError> {
12328-
let create_pending_payment_fn = |invoice_request: &InvoiceRequest, nonce| {
12329-
let expiration = StaleExpiration::TimerTicks(1);
12330-
let retryable_invoice_request = RetryableInvoiceRequest {
12331-
invoice_request: invoice_request.clone(),
12332-
nonce,
12333-
needs_retry: true,
12334-
};
12328+
let create_pending_payment_fn = |retryable_invoice_request: RetryableInvoiceRequest| {
1233512329
self.pending_outbound_payments
1233612330
.add_new_awaiting_invoice(
1233712331
payment_id,
12338-
expiration,
12332+
StaleExpiration::TimerTicks(1),
1233912333
optional_params.retry_strategy,
1234012334
optional_params.route_params_config,
1234112335
Some(retryable_invoice_request),
@@ -12360,17 +12354,11 @@ where
1236012354
&self, offer: &OfferFromHrn, amount_msats: u64, payment_id: PaymentId,
1236112355
optional_params: OptionalOfferPaymentParams,
1236212356
) -> Result<(), Bolt12SemanticError> {
12363-
let create_pending_payment_fn = |invoice_request: &InvoiceRequest, nonce| {
12364-
let expiration = StaleExpiration::TimerTicks(1);
12365-
let retryable_invoice_request = RetryableInvoiceRequest {
12366-
invoice_request: invoice_request.clone(),
12367-
nonce,
12368-
needs_retry: true,
12369-
};
12357+
let create_pending_payment_fn = |retryable_invoice_request: RetryableInvoiceRequest| {
1237012358
self.pending_outbound_payments
1237112359
.add_new_awaiting_invoice(
1237212360
payment_id,
12373-
expiration,
12361+
StaleExpiration::TimerTicks(1),
1237412362
optional_params.retry_strategy,
1237512363
optional_params.route_params_config,
1237612364
Some(retryable_invoice_request),
@@ -12408,17 +12396,11 @@ where
1240812396
&self, offer: &Offer, amount_msats: Option<u64>, payment_id: PaymentId,
1240912397
optional_params: OptionalOfferPaymentParams, quantity: u64,
1241012398
) -> Result<(), Bolt12SemanticError> {
12411-
let create_pending_payment_fn = |invoice_request: &InvoiceRequest, nonce| {
12412-
let expiration = StaleExpiration::TimerTicks(1);
12413-
let retryable_invoice_request = RetryableInvoiceRequest {
12414-
invoice_request: invoice_request.clone(),
12415-
nonce,
12416-
needs_retry: true,
12417-
};
12399+
let create_pending_payment_fn = |retryable_invoice_request: RetryableInvoiceRequest| {
1241812400
self.pending_outbound_payments
1241912401
.add_new_awaiting_invoice(
1242012402
payment_id,
12421-
expiration,
12403+
StaleExpiration::TimerTicks(1),
1242212404
optional_params.retry_strategy,
1242312405
optional_params.route_params_config,
1242412406
Some(retryable_invoice_request),
@@ -12438,7 +12420,7 @@ where
1243812420
}
1243912421

1244012422
#[rustfmt::skip]
12441-
fn pay_for_offer_intern<CPP: FnOnce(&InvoiceRequest, Nonce) -> Result<(), Bolt12SemanticError>>(
12423+
fn pay_for_offer_intern<CPP: FnOnce(RetryableInvoiceRequest) -> Result<(), Bolt12SemanticError>>(
1244212424
&self, offer: &Offer, quantity: Option<u64>, amount_msats: Option<u64>,
1244312425
payer_note: Option<String>, payment_id: PaymentId,
1244412426
human_readable_name: Option<HumanReadableName>, create_pending_payment: CPP,
@@ -12475,7 +12457,13 @@ where
1247512457
self.get_peers_for_blinded_path()
1247612458
)?;
1247712459

12478-
create_pending_payment(&invoice_request, nonce)
12460+
let retryable_invoice_request = RetryableInvoiceRequest {
12461+
invoice_request: invoice_request.clone(),
12462+
nonce,
12463+
needs_retry: true,
12464+
};
12465+
12466+
create_pending_payment(retryable_invoice_request)
1247912467
}
1248012468

1248112469
/// Creates a [`Bolt12Invoice`] for a [`Refund`] and enqueues it to be sent via an onion
@@ -14896,12 +14884,7 @@ where
1489614884
if let Ok((amt_msats, payer_note)) = self.pending_outbound_payments.params_for_payment_awaiting_offer(payment_id) {
1489714885
let offer_pay_res =
1489814886
self.pay_for_offer_intern(&offer, None, Some(amt_msats), payer_note, payment_id, Some(name),
14899-
|invoice_request, nonce| {
14900-
let retryable_invoice_request = RetryableInvoiceRequest {
14901-
invoice_request: invoice_request.clone(),
14902-
nonce,
14903-
needs_retry: true,
14904-
};
14887+
|retryable_invoice_request| {
1490514888
self.pending_outbound_payments
1490614889
.received_offer(payment_id, Some(retryable_invoice_request))
1490714890
.map_err(|_| Bolt12SemanticError::DuplicatePaymentId)

0 commit comments

Comments
 (0)