Skip to content

Commit 69356e7

Browse files
Split off send_payment_for_bolt12_invoice_internal util.
This new util will be able to send to both static and non-static BOLT 12 invoices.
1 parent 8569830 commit 69356e7

File tree

1 file changed

+35
-14
lines changed

1 file changed

+35
-14
lines changed

lightning/src/ln/outbound_payment.rs

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,7 @@ impl OutboundPayments {
829829
PendingOutboundPayment::AwaitingInvoice {
830830
retry_strategy: retry, max_total_routing_fee_msat: max_total_fee, ..
831831
} => {
832-
retry_strategy = Some(*retry);
832+
retry_strategy = *retry;
833833
max_total_routing_fee_msat = *max_total_fee;
834834
*entry.into_mut() = PendingOutboundPayment::InvoiceReceived {
835835
payment_hash,
@@ -849,11 +849,41 @@ impl OutboundPayments {
849849
return Err(Bolt12PaymentError::UnknownRequiredFeatures);
850850
}
851851

852-
let mut payment_params = PaymentParameters::from_bolt12_invoice(&invoice);
852+
let mut route_params = RouteParameters::from_payment_params_and_value(
853+
PaymentParameters::from_bolt12_invoice(&invoice), invoice.amount_msats()
854+
);
855+
if let Some(max_fee_msat) = max_total_routing_fee_msat {
856+
route_params.max_total_routing_fee_msat = Some(max_fee_msat);
857+
}
858+
self.send_payment_for_bolt12_invoice_internal(
859+
payment_id, payment_hash, route_params, retry_strategy, router, first_hops, inflight_htlcs,
860+
entropy_source, node_signer, node_id_lookup, secp_ctx, best_block_height, logger,
861+
pending_events, send_payment_along_path
862+
)
863+
}
853864

865+
fn send_payment_for_bolt12_invoice_internal<
866+
R: Deref, ES: Deref, NS: Deref, NL: Deref, IH, SP, L: Deref
867+
>(
868+
&self, payment_id: PaymentId, payment_hash: PaymentHash, mut route_params: RouteParameters,
869+
retry_strategy: Retry, router: &R, first_hops: Vec<ChannelDetails>, inflight_htlcs: IH,
870+
entropy_source: &ES, node_signer: &NS, node_id_lookup: &NL,
871+
secp_ctx: &Secp256k1<secp256k1::All>, best_block_height: u32, logger: &L,
872+
pending_events: &Mutex<VecDeque<(events::Event, Option<EventCompletionAction>)>>,
873+
send_payment_along_path: SP,
874+
) -> Result<(), Bolt12PaymentError>
875+
where
876+
R::Target: Router,
877+
ES::Target: EntropySource,
878+
NS::Target: NodeSigner,
879+
NL::Target: NodeIdLookUp,
880+
L::Target: Logger,
881+
IH: Fn() -> InFlightHtlcs,
882+
SP: Fn(SendAlongPathArgs) -> Result<(), APIError>,
883+
{
854884
// Advance any blinded path where the introduction node is our node.
855885
if let Ok(our_node_id) = node_signer.get_node_id(Recipient::Node) {
856-
for path in payment_params.payee.blinded_route_hints_mut().iter_mut() {
886+
for path in route_params.payment_params.payee.blinded_route_hints_mut().iter_mut() {
857887
let introduction_node_id = match path.introduction_node() {
858888
IntroductionNode::NodeId(pubkey) => *pubkey,
859889
IntroductionNode::DirectedShortChannelId(direction, scid) => {
@@ -869,15 +899,6 @@ impl OutboundPayments {
869899
}
870900
}
871901

872-
let amount_msat = invoice.amount_msats();
873-
let mut route_params = RouteParameters::from_payment_params_and_value(
874-
payment_params, amount_msat
875-
);
876-
877-
if let Some(max_fee_msat) = max_total_routing_fee_msat {
878-
route_params.max_total_routing_fee_msat = Some(max_fee_msat);
879-
}
880-
881902
let recipient_onion = RecipientOnionFields {
882903
payment_secret: None,
883904
payment_metadata: None,
@@ -902,8 +923,8 @@ impl OutboundPayments {
902923

903924
let payment_params = Some(route_params.payment_params.clone());
904925
let (retryable_payment, onion_session_privs) = self.create_pending_payment(
905-
payment_hash, recipient_onion.clone(), None, &route,
906-
retry_strategy, payment_params, entropy_source, best_block_height
926+
payment_hash, recipient_onion.clone(), None, &route, Some(retry_strategy), payment_params,
927+
entropy_source, best_block_height
907928
);
908929
match self.pending_outbound_payments.lock().unwrap().entry(payment_id) {
909930
hash_map::Entry::Occupied(entry) => match entry.get() {

0 commit comments

Comments
 (0)