@@ -93,6 +93,7 @@ pub(crate) enum PendingOutboundPayment {
93
93
retry_strategy : Retry ,
94
94
route_params : RouteParameters ,
95
95
invoice_request : InvoiceRequest ,
96
+ static_invoice : StaticInvoice ,
96
97
} ,
97
98
Retryable {
98
99
retry_strategy : Option < Retry > ,
@@ -1160,6 +1161,7 @@ impl OutboundPayments {
1160
1161
. take ( )
1161
1162
. ok_or ( Bolt12PaymentError :: UnexpectedInvoice ) ?
1162
1163
. invoice_request ,
1164
+ static_invoice : invoice. clone ( ) ,
1163
1165
} ;
1164
1166
return Ok ( ( ) )
1165
1167
} ,
@@ -1188,22 +1190,22 @@ impl OutboundPayments {
1188
1190
IH : Fn ( ) -> InFlightHtlcs ,
1189
1191
SP : Fn ( SendAlongPathArgs ) -> Result < ( ) , APIError > ,
1190
1192
{
1191
- let ( payment_hash, keysend_preimage, route_params, retry_strategy, invoice_request) =
1193
+ let ( payment_hash, keysend_preimage, route_params, retry_strategy, invoice_request, invoice ) =
1192
1194
match self . pending_outbound_payments . lock ( ) . unwrap ( ) . entry ( payment_id) {
1193
1195
hash_map:: Entry :: Occupied ( entry) => match entry. get ( ) {
1194
1196
PendingOutboundPayment :: StaticInvoiceReceived {
1195
- payment_hash, route_params, retry_strategy, keysend_preimage, invoice_request, ..
1197
+ payment_hash, route_params, retry_strategy, keysend_preimage, invoice_request, static_invoice , ..
1196
1198
} => {
1197
1199
( * payment_hash, * keysend_preimage, route_params. clone ( ) , * retry_strategy,
1198
- invoice_request. clone ( ) )
1200
+ invoice_request. clone ( ) , static_invoice . clone ( ) )
1199
1201
} ,
1200
1202
_ => return Err ( Bolt12PaymentError :: DuplicateInvoice ) ,
1201
1203
} ,
1202
1204
hash_map:: Entry :: Vacant ( _) => return Err ( Bolt12PaymentError :: UnexpectedInvoice ) ,
1203
1205
} ;
1204
-
1206
+ let invoice = PaidInvoice :: StaticInvoice ( invoice . clone ( ) ) ;
1205
1207
self . send_payment_for_bolt12_invoice_internal (
1206
- payment_id, payment_hash, Some ( keysend_preimage) , Some ( & invoice_request) , None , route_params,
1208
+ payment_id, payment_hash, Some ( keysend_preimage) , Some ( & invoice_request) , Some ( & invoice ) , route_params,
1207
1209
retry_strategy, router, first_hops, inflight_htlcs, entropy_source, node_signer,
1208
1210
node_id_lookup, secp_ctx, best_block_height, logger, pending_events, send_payment_along_path
1209
1211
)
@@ -2527,6 +2529,7 @@ impl_writeable_tlv_based_enum_upgradable!(PendingOutboundPayment,
2527
2529
( 4 , retry_strategy, required) ,
2528
2530
( 6 , route_params, required) ,
2529
2531
( 8 , invoice_request, required) ,
2532
+ ( 10 , static_invoice, required) ,
2530
2533
} ,
2531
2534
// Added in 0.1. Prior versions will drop these outbounds on downgrade, which is safe because
2532
2535
// no HTLCs are in-flight.
@@ -2558,6 +2561,10 @@ mod tests {
2558
2561
2559
2562
use crate :: blinded_path:: EmptyNodeIdLookUp ;
2560
2563
use crate :: events:: { Event , PathFailure , PaymentFailureReason } ;
2564
+ use crate :: offers:: static_invoice:: { StaticInvoiceBuilder , StaticInvoice } ;
2565
+ use crate :: blinded_path:: message:: BlindedMessagePath ;
2566
+ use crate :: ln:: outbound_payment:: tests:: test_utils:: pubkey;
2567
+ use crate :: blinded_path:: BlindedHop ;
2561
2568
use crate :: types:: payment:: { PaymentHash , PaymentPreimage } ;
2562
2569
use crate :: ln:: channelmanager:: { PaymentId , RecipientOnionFields } ;
2563
2570
use crate :: ln:: inbound_payment:: ExpandedKey ;
@@ -3135,6 +3142,46 @@ mod tests {
3135
3142
. unwrap ( )
3136
3143
}
3137
3144
3145
+ fn blinded_path ( ) -> BlindedMessagePath {
3146
+ BlindedMessagePath :: from_raw (
3147
+ pubkey ( 40 ) ,
3148
+ pubkey ( 41 ) ,
3149
+ vec ! [
3150
+ BlindedHop { blinded_node_id: pubkey( 42 ) , encrypted_payload: vec![ 0 ; 43 ] } ,
3151
+ BlindedHop { blinded_node_id: pubkey( 43 ) , encrypted_payload: vec![ 0 ; 44 ] } ,
3152
+ ] ,
3153
+ )
3154
+ }
3155
+
3156
+ // FIXME(vincenzopalazzo): This function is duplicated with the one in static_invoive.rs
3157
+ fn dummy_static_invoice ( ) -> StaticInvoice {
3158
+ let node_id = recipient_pubkey ( ) ;
3159
+ let payment_paths = payment_paths ( ) ;
3160
+ let now = now ( ) ;
3161
+ let expanded_key = ExpandedKey :: new ( [ 42 ; 32 ] ) ;
3162
+ let entropy = FixedEntropy { } ;
3163
+ let nonce = Nonce :: from_entropy_source ( & entropy) ;
3164
+ let secp_ctx = Secp256k1 :: new ( ) ;
3165
+
3166
+ let offer = OfferBuilder :: deriving_signing_pubkey ( node_id, & expanded_key, nonce, & secp_ctx)
3167
+ . path ( blinded_path ( ) )
3168
+ . build ( )
3169
+ . unwrap ( ) ;
3170
+
3171
+ StaticInvoiceBuilder :: for_offer_using_derived_keys (
3172
+ & offer,
3173
+ payment_paths. clone ( ) ,
3174
+ vec ! [ blinded_path( ) ] ,
3175
+ now,
3176
+ & expanded_key,
3177
+ nonce,
3178
+ & secp_ctx,
3179
+ )
3180
+ . unwrap ( )
3181
+ . build_and_sign ( & secp_ctx)
3182
+ . unwrap ( )
3183
+ }
3184
+
3138
3185
#[ test]
3139
3186
fn time_out_unreleased_async_payments ( ) {
3140
3187
let pending_events = Mutex :: new ( VecDeque :: new ( ) ) ;
@@ -3157,6 +3204,7 @@ mod tests {
3157
3204
retry_strategy : Retry :: Attempts ( 0 ) ,
3158
3205
route_params,
3159
3206
invoice_request : dummy_invoice_request ( ) ,
3207
+ static_invoice : dummy_static_invoice ( ) ,
3160
3208
} ;
3161
3209
outbounds. insert ( payment_id, outbound) ;
3162
3210
core:: mem:: drop ( outbounds) ;
@@ -3204,6 +3252,7 @@ mod tests {
3204
3252
retry_strategy : Retry :: Attempts ( 0 ) ,
3205
3253
route_params,
3206
3254
invoice_request : dummy_invoice_request ( ) ,
3255
+ static_invoice : dummy_static_invoice ( ) ,
3207
3256
} ;
3208
3257
outbounds. insert ( payment_id, outbound) ;
3209
3258
core:: mem:: drop ( outbounds) ;
0 commit comments