@@ -22,6 +22,7 @@ use crate::ln::channelmanager::{EventCompletionAction, HTLCSource, PaymentId};
22
22
use crate :: ln:: onion_utils;
23
23
use crate :: ln:: onion_utils:: { DecodedOnionFailure , HTLCFailReason } ;
24
24
use crate :: offers:: invoice:: Bolt12Invoice ;
25
+ use crate :: offers:: invoice_request:: InvoiceRequest ;
25
26
use crate :: routing:: router:: { BlindedTail , InFlightHtlcs , Path , PaymentParameters , Route , RouteParameters , Router } ;
26
27
use crate :: sign:: { EntropySource , NodeSigner , Recipient } ;
27
28
use crate :: util:: errors:: APIError ;
@@ -54,6 +55,7 @@ pub(crate) enum PendingOutboundPayment {
54
55
expiration : StaleExpiration ,
55
56
retry_strategy : Retry ,
56
57
max_total_routing_fee_msat : Option < u64 > ,
58
+ invoice_request : Option < InvoiceRequest > ,
57
59
} ,
58
60
InvoiceReceived {
59
61
payment_hash : PaymentHash ,
@@ -1337,7 +1339,7 @@ impl OutboundPayments {
1337
1339
1338
1340
pub ( super ) fn add_new_awaiting_invoice (
1339
1341
& self , payment_id : PaymentId , expiration : StaleExpiration , retry_strategy : Retry ,
1340
- max_total_routing_fee_msat : Option < u64 >
1342
+ max_total_routing_fee_msat : Option < u64 > , invoice_request : Option < InvoiceRequest >
1341
1343
) -> Result < ( ) , ( ) > {
1342
1344
let mut pending_outbounds = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
1343
1345
match pending_outbounds. entry ( payment_id) {
@@ -1347,6 +1349,7 @@ impl OutboundPayments {
1347
1349
expiration,
1348
1350
retry_strategy,
1349
1351
max_total_routing_fee_msat,
1352
+ invoice_request,
1350
1353
} ) ;
1351
1354
1352
1355
Ok ( ( ) )
@@ -1813,6 +1816,20 @@ impl OutboundPayments {
1813
1816
pub fn clear_pending_payments ( & self ) {
1814
1817
self . pending_outbound_payments . lock ( ) . unwrap ( ) . clear ( )
1815
1818
}
1819
+
1820
+ pub fn get_invoice_request_awaiting_invoice ( & self ) -> Vec < InvoiceRequest > {
1821
+ let pending_outbound_payments = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
1822
+
1823
+ pending_outbound_payments. iter ( ) . filter_map (
1824
+ |( _, payment) | {
1825
+ if let PendingOutboundPayment :: AwaitingInvoice { invoice_request, .. } = payment {
1826
+ invoice_request. clone ( )
1827
+ } else {
1828
+ None
1829
+ }
1830
+ }
1831
+ ) . collect ( )
1832
+ }
1816
1833
}
1817
1834
1818
1835
/// Returns whether a payment with the given [`PaymentHash`] and [`PaymentId`] is, in fact, a
@@ -1868,6 +1885,7 @@ impl_writeable_tlv_based_enum_upgradable!(PendingOutboundPayment,
1868
1885
( 0 , expiration, required) ,
1869
1886
( 2 , retry_strategy, required) ,
1870
1887
( 4 , max_total_routing_fee_msat, option) ,
1888
+ ( 6 , invoice_request, option) ,
1871
1889
} ,
1872
1890
( 7 , InvoiceReceived ) => {
1873
1891
( 0 , payment_hash, required) ,
@@ -2106,7 +2124,7 @@ mod tests {
2106
2124
assert ! ( !outbound_payments. has_pending_payments( ) ) ;
2107
2125
assert ! (
2108
2126
outbound_payments. add_new_awaiting_invoice(
2109
- payment_id, expiration, Retry :: Attempts ( 0 ) , None
2127
+ payment_id, expiration, Retry :: Attempts ( 0 ) , None , None
2110
2128
) . is_ok( )
2111
2129
) ;
2112
2130
assert ! ( outbound_payments. has_pending_payments( ) ) ;
@@ -2132,14 +2150,14 @@ mod tests {
2132
2150
2133
2151
assert ! (
2134
2152
outbound_payments. add_new_awaiting_invoice(
2135
- payment_id, expiration, Retry :: Attempts ( 0 ) , None
2153
+ payment_id, expiration, Retry :: Attempts ( 0 ) , None , None
2136
2154
) . is_ok( )
2137
2155
) ;
2138
2156
assert ! ( outbound_payments. has_pending_payments( ) ) ;
2139
2157
2140
2158
assert ! (
2141
2159
outbound_payments. add_new_awaiting_invoice(
2142
- payment_id, expiration, Retry :: Attempts ( 0 ) , None
2160
+ payment_id, expiration, Retry :: Attempts ( 0 ) , None , None
2143
2161
) . is_err( )
2144
2162
) ;
2145
2163
}
@@ -2155,7 +2173,7 @@ mod tests {
2155
2173
assert ! ( !outbound_payments. has_pending_payments( ) ) ;
2156
2174
assert ! (
2157
2175
outbound_payments. add_new_awaiting_invoice(
2158
- payment_id, expiration, Retry :: Attempts ( 0 ) , None
2176
+ payment_id, expiration, Retry :: Attempts ( 0 ) , None , None
2159
2177
) . is_ok( )
2160
2178
) ;
2161
2179
assert ! ( outbound_payments. has_pending_payments( ) ) ;
@@ -2181,14 +2199,14 @@ mod tests {
2181
2199
2182
2200
assert ! (
2183
2201
outbound_payments. add_new_awaiting_invoice(
2184
- payment_id, expiration, Retry :: Attempts ( 0 ) , None
2202
+ payment_id, expiration, Retry :: Attempts ( 0 ) , None , None
2185
2203
) . is_ok( )
2186
2204
) ;
2187
2205
assert ! ( outbound_payments. has_pending_payments( ) ) ;
2188
2206
2189
2207
assert ! (
2190
2208
outbound_payments. add_new_awaiting_invoice(
2191
- payment_id, expiration, Retry :: Attempts ( 0 ) , None
2209
+ payment_id, expiration, Retry :: Attempts ( 0 ) , None , None
2192
2210
) . is_err( )
2193
2211
) ;
2194
2212
}
@@ -2203,7 +2221,7 @@ mod tests {
2203
2221
assert ! ( !outbound_payments. has_pending_payments( ) ) ;
2204
2222
assert ! (
2205
2223
outbound_payments. add_new_awaiting_invoice(
2206
- payment_id, expiration, Retry :: Attempts ( 0 ) , None
2224
+ payment_id, expiration, Retry :: Attempts ( 0 ) , None , None
2207
2225
) . is_ok( )
2208
2226
) ;
2209
2227
assert ! ( outbound_payments. has_pending_payments( ) ) ;
@@ -2237,7 +2255,7 @@ mod tests {
2237
2255
2238
2256
assert ! (
2239
2257
outbound_payments. add_new_awaiting_invoice(
2240
- payment_id, expiration, Retry :: Attempts ( 0 ) , None
2258
+ payment_id, expiration, Retry :: Attempts ( 0 ) , None , None
2241
2259
) . is_ok( )
2242
2260
) ;
2243
2261
assert ! ( outbound_payments. has_pending_payments( ) ) ;
@@ -2301,7 +2319,7 @@ mod tests {
2301
2319
assert ! (
2302
2320
outbound_payments. add_new_awaiting_invoice(
2303
2321
payment_id, expiration, Retry :: Attempts ( 0 ) ,
2304
- Some ( invoice. amount_msats( ) / 100 + 50_000 )
2322
+ Some ( invoice. amount_msats( ) / 100 + 50_000 ) , None
2305
2323
) . is_ok( )
2306
2324
) ;
2307
2325
assert ! ( outbound_payments. has_pending_payments( ) ) ;
@@ -2401,7 +2419,7 @@ mod tests {
2401
2419
2402
2420
assert ! (
2403
2421
outbound_payments. add_new_awaiting_invoice(
2404
- payment_id, expiration, Retry :: Attempts ( 0 ) , Some ( 1234 )
2422
+ payment_id, expiration, Retry :: Attempts ( 0 ) , Some ( 1234 ) , None
2405
2423
) . is_ok( )
2406
2424
) ;
2407
2425
assert ! ( outbound_payments. has_pending_payments( ) ) ;
0 commit comments