@@ -13,6 +13,7 @@ use bitcoin::hashes::Hash;
13
13
use bitcoin:: hashes:: sha256:: Hash as Sha256 ;
14
14
use bitcoin:: secp256k1:: { self , Secp256k1 , SecretKey } ;
15
15
16
+ use crate :: offers:: invoice_request:: InvoiceRequest ;
16
17
use crate :: sign:: { EntropySource , NodeSigner , Recipient } ;
17
18
use crate :: events:: { self , PaymentFailureReason } ;
18
19
use crate :: ln:: types:: { PaymentHash , PaymentPreimage , PaymentSecret } ;
@@ -53,6 +54,7 @@ pub(crate) enum PendingOutboundPayment {
53
54
expiration : StaleExpiration ,
54
55
retry_strategy : Retry ,
55
56
max_total_routing_fee_msat : Option < u64 > ,
57
+ invoice_request : Option < InvoiceRequest > ,
56
58
} ,
57
59
InvoiceReceived {
58
60
payment_hash : PaymentHash ,
@@ -1313,7 +1315,7 @@ impl OutboundPayments {
1313
1315
1314
1316
pub ( super ) fn add_new_awaiting_invoice (
1315
1317
& self , payment_id : PaymentId , expiration : StaleExpiration , retry_strategy : Retry ,
1316
- max_total_routing_fee_msat : Option < u64 >
1318
+ max_total_routing_fee_msat : Option < u64 > , invoice_request : Option < InvoiceRequest >
1317
1319
) -> Result < ( ) , ( ) > {
1318
1320
let mut pending_outbounds = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
1319
1321
match pending_outbounds. entry ( payment_id) {
@@ -1323,6 +1325,7 @@ impl OutboundPayments {
1323
1325
expiration,
1324
1326
retry_strategy,
1325
1327
max_total_routing_fee_msat,
1328
+ invoice_request,
1326
1329
} ) ;
1327
1330
1328
1331
Ok ( ( ) )
@@ -1789,6 +1792,22 @@ impl OutboundPayments {
1789
1792
pub fn clear_pending_payments ( & self ) {
1790
1793
self . pending_outbound_payments . lock ( ) . unwrap ( ) . clear ( )
1791
1794
}
1795
+
1796
+ pub fn get_invoice_request_awaiting_invoice ( & self ) -> Vec < InvoiceRequest > {
1797
+ if !self . awaiting_invoice_flag . load ( Ordering :: SeqCst ) {
1798
+ return vec ! [ ] ;
1799
+ }
1800
+ let mut pending_outbound_payments = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
1801
+ let invoice_requests = pending_outbound_payments. values_mut ( )
1802
+ . filter_map ( |payment| match payment {
1803
+ PendingOutboundPayment :: AwaitingInvoice { invoice_request, .. } => invoice_request. take ( ) ,
1804
+ _ => None ,
1805
+ } )
1806
+ . collect ( ) ;
1807
+
1808
+ self . awaiting_invoice_flag . store ( false , Ordering :: SeqCst ) ;
1809
+ invoice_requests
1810
+ }
1792
1811
}
1793
1812
1794
1813
/// Returns whether a payment with the given [`PaymentHash`] and [`PaymentId`] is, in fact, a
@@ -1844,6 +1863,7 @@ impl_writeable_tlv_based_enum_upgradable!(PendingOutboundPayment,
1844
1863
( 0 , expiration, required) ,
1845
1864
( 2 , retry_strategy, required) ,
1846
1865
( 4 , max_total_routing_fee_msat, option) ,
1866
+ ( 6 , invoice_request, option) ,
1847
1867
} ,
1848
1868
( 7 , InvoiceReceived ) => {
1849
1869
( 0 , payment_hash, required) ,
@@ -2081,7 +2101,7 @@ mod tests {
2081
2101
assert ! ( !outbound_payments. has_pending_payments( ) ) ;
2082
2102
assert ! (
2083
2103
outbound_payments. add_new_awaiting_invoice(
2084
- payment_id, expiration, Retry :: Attempts ( 0 ) , None
2104
+ payment_id, expiration, Retry :: Attempts ( 0 ) , None , None
2085
2105
) . is_ok( )
2086
2106
) ;
2087
2107
assert ! ( outbound_payments. has_pending_payments( ) ) ;
@@ -2107,14 +2127,14 @@ mod tests {
2107
2127
2108
2128
assert ! (
2109
2129
outbound_payments. add_new_awaiting_invoice(
2110
- payment_id, expiration, Retry :: Attempts ( 0 ) , None
2130
+ payment_id, expiration, Retry :: Attempts ( 0 ) , None , None
2111
2131
) . is_ok( )
2112
2132
) ;
2113
2133
assert ! ( outbound_payments. has_pending_payments( ) ) ;
2114
2134
2115
2135
assert ! (
2116
2136
outbound_payments. add_new_awaiting_invoice(
2117
- payment_id, expiration, Retry :: Attempts ( 0 ) , None
2137
+ payment_id, expiration, Retry :: Attempts ( 0 ) , None , None
2118
2138
) . is_err( )
2119
2139
) ;
2120
2140
}
@@ -2130,7 +2150,7 @@ mod tests {
2130
2150
assert ! ( !outbound_payments. has_pending_payments( ) ) ;
2131
2151
assert ! (
2132
2152
outbound_payments. add_new_awaiting_invoice(
2133
- payment_id, expiration, Retry :: Attempts ( 0 ) , None
2153
+ payment_id, expiration, Retry :: Attempts ( 0 ) , None , None
2134
2154
) . is_ok( )
2135
2155
) ;
2136
2156
assert ! ( outbound_payments. has_pending_payments( ) ) ;
@@ -2156,14 +2176,14 @@ mod tests {
2156
2176
2157
2177
assert ! (
2158
2178
outbound_payments. add_new_awaiting_invoice(
2159
- payment_id, expiration, Retry :: Attempts ( 0 ) , None
2179
+ payment_id, expiration, Retry :: Attempts ( 0 ) , None , None
2160
2180
) . is_ok( )
2161
2181
) ;
2162
2182
assert ! ( outbound_payments. has_pending_payments( ) ) ;
2163
2183
2164
2184
assert ! (
2165
2185
outbound_payments. add_new_awaiting_invoice(
2166
- payment_id, expiration, Retry :: Attempts ( 0 ) , None
2186
+ payment_id, expiration, Retry :: Attempts ( 0 ) , None , None
2167
2187
) . is_err( )
2168
2188
) ;
2169
2189
}
@@ -2178,7 +2198,7 @@ mod tests {
2178
2198
assert ! ( !outbound_payments. has_pending_payments( ) ) ;
2179
2199
assert ! (
2180
2200
outbound_payments. add_new_awaiting_invoice(
2181
- payment_id, expiration, Retry :: Attempts ( 0 ) , None
2201
+ payment_id, expiration, Retry :: Attempts ( 0 ) , None , None
2182
2202
) . is_ok( )
2183
2203
) ;
2184
2204
assert ! ( outbound_payments. has_pending_payments( ) ) ;
@@ -2211,7 +2231,7 @@ mod tests {
2211
2231
2212
2232
assert ! (
2213
2233
outbound_payments. add_new_awaiting_invoice(
2214
- payment_id, expiration, Retry :: Attempts ( 0 ) , None
2234
+ payment_id, expiration, Retry :: Attempts ( 0 ) , None , None
2215
2235
) . is_ok( )
2216
2236
) ;
2217
2237
assert ! ( outbound_payments. has_pending_payments( ) ) ;
@@ -2273,7 +2293,7 @@ mod tests {
2273
2293
assert ! (
2274
2294
outbound_payments. add_new_awaiting_invoice(
2275
2295
payment_id, expiration, Retry :: Attempts ( 0 ) ,
2276
- Some ( invoice. amount_msats( ) / 100 + 50_000 )
2296
+ Some ( invoice. amount_msats( ) / 100 + 50_000 ) , None
2277
2297
) . is_ok( )
2278
2298
) ;
2279
2299
assert ! ( outbound_payments. has_pending_payments( ) ) ;
@@ -2370,7 +2390,7 @@ mod tests {
2370
2390
2371
2391
assert ! (
2372
2392
outbound_payments. add_new_awaiting_invoice(
2373
- payment_id, expiration, Retry :: Attempts ( 0 ) , Some ( 1234 )
2393
+ payment_id, expiration, Retry :: Attempts ( 0 ) , Some ( 1234 ) , None
2374
2394
) . is_ok( )
2375
2395
) ;
2376
2396
assert ! ( outbound_payments. has_pending_payments( ) ) ;
0 commit comments