@@ -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:: { PaymentHash , PaymentPreimage , PaymentSecret } ;
@@ -50,6 +51,7 @@ pub(crate) enum PendingOutboundPayment {
50
51
expiration : StaleExpiration ,
51
52
retry_strategy : Retry ,
52
53
max_total_routing_fee_msat : Option < u64 > ,
54
+ invoice_request : Option < InvoiceRequest > ,
53
55
} ,
54
56
InvoiceReceived {
55
57
payment_hash : PaymentHash ,
@@ -1291,7 +1293,7 @@ impl OutboundPayments {
1291
1293
1292
1294
pub ( super ) fn add_new_awaiting_invoice (
1293
1295
& self , payment_id : PaymentId , expiration : StaleExpiration , retry_strategy : Retry ,
1294
- max_total_routing_fee_msat : Option < u64 >
1296
+ max_total_routing_fee_msat : Option < u64 > , invoice_request : Option < InvoiceRequest >
1295
1297
) -> Result < ( ) , ( ) > {
1296
1298
let mut pending_outbounds = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
1297
1299
match pending_outbounds. entry ( payment_id) {
@@ -1301,6 +1303,7 @@ impl OutboundPayments {
1301
1303
expiration,
1302
1304
retry_strategy,
1303
1305
max_total_routing_fee_msat,
1306
+ invoice_request,
1304
1307
} ) ;
1305
1308
1306
1309
Ok ( ( ) )
@@ -1766,6 +1769,20 @@ impl OutboundPayments {
1766
1769
pub fn clear_pending_payments ( & self ) {
1767
1770
self . pending_outbound_payments . lock ( ) . unwrap ( ) . clear ( )
1768
1771
}
1772
+
1773
+ pub fn get_invoice_request_awaiting_invoice ( & self ) -> Vec < InvoiceRequest > {
1774
+ let pending_outbound_payments = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
1775
+
1776
+ pending_outbound_payments. iter ( ) . filter_map (
1777
+ |( _, payment) | {
1778
+ if let PendingOutboundPayment :: AwaitingInvoice { invoice_request, .. } = payment {
1779
+ invoice_request. clone ( )
1780
+ } else {
1781
+ None
1782
+ }
1783
+ }
1784
+ ) . collect ( )
1785
+ }
1769
1786
}
1770
1787
1771
1788
/// Returns whether a payment with the given [`PaymentHash`] and [`PaymentId`] is, in fact, a
@@ -1821,6 +1838,7 @@ impl_writeable_tlv_based_enum_upgradable!(PendingOutboundPayment,
1821
1838
( 0 , expiration, required) ,
1822
1839
( 2 , retry_strategy, required) ,
1823
1840
( 4 , max_total_routing_fee_msat, option) ,
1841
+ ( 6 , invoice_request, option) ,
1824
1842
} ,
1825
1843
( 7 , InvoiceReceived ) => {
1826
1844
( 0 , payment_hash, required) ,
@@ -2058,7 +2076,7 @@ mod tests {
2058
2076
assert ! ( !outbound_payments. has_pending_payments( ) ) ;
2059
2077
assert ! (
2060
2078
outbound_payments. add_new_awaiting_invoice(
2061
- payment_id, expiration, Retry :: Attempts ( 0 ) , None
2079
+ payment_id, expiration, Retry :: Attempts ( 0 ) , None , None
2062
2080
) . is_ok( )
2063
2081
) ;
2064
2082
assert ! ( outbound_payments. has_pending_payments( ) ) ;
@@ -2084,14 +2102,14 @@ mod tests {
2084
2102
2085
2103
assert ! (
2086
2104
outbound_payments. add_new_awaiting_invoice(
2087
- payment_id, expiration, Retry :: Attempts ( 0 ) , None
2105
+ payment_id, expiration, Retry :: Attempts ( 0 ) , None , None
2088
2106
) . is_ok( )
2089
2107
) ;
2090
2108
assert ! ( outbound_payments. has_pending_payments( ) ) ;
2091
2109
2092
2110
assert ! (
2093
2111
outbound_payments. add_new_awaiting_invoice(
2094
- payment_id, expiration, Retry :: Attempts ( 0 ) , None
2112
+ payment_id, expiration, Retry :: Attempts ( 0 ) , None , None
2095
2113
) . is_err( )
2096
2114
) ;
2097
2115
}
@@ -2107,7 +2125,7 @@ mod tests {
2107
2125
assert ! ( !outbound_payments. has_pending_payments( ) ) ;
2108
2126
assert ! (
2109
2127
outbound_payments. add_new_awaiting_invoice(
2110
- payment_id, expiration, Retry :: Attempts ( 0 ) , None
2128
+ payment_id, expiration, Retry :: Attempts ( 0 ) , None , None
2111
2129
) . is_ok( )
2112
2130
) ;
2113
2131
assert ! ( outbound_payments. has_pending_payments( ) ) ;
@@ -2133,14 +2151,14 @@ mod tests {
2133
2151
2134
2152
assert ! (
2135
2153
outbound_payments. add_new_awaiting_invoice(
2136
- payment_id, expiration, Retry :: Attempts ( 0 ) , None
2154
+ payment_id, expiration, Retry :: Attempts ( 0 ) , None , None
2137
2155
) . is_ok( )
2138
2156
) ;
2139
2157
assert ! ( outbound_payments. has_pending_payments( ) ) ;
2140
2158
2141
2159
assert ! (
2142
2160
outbound_payments. add_new_awaiting_invoice(
2143
- payment_id, expiration, Retry :: Attempts ( 0 ) , None
2161
+ payment_id, expiration, Retry :: Attempts ( 0 ) , None , None
2144
2162
) . is_err( )
2145
2163
) ;
2146
2164
}
@@ -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( ) ) ;
@@ -2188,7 +2206,7 @@ mod tests {
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_ok( )
2193
2211
) ;
2194
2212
assert ! ( outbound_payments. has_pending_payments( ) ) ;
@@ -2250,7 +2268,7 @@ mod tests {
2250
2268
assert ! (
2251
2269
outbound_payments. add_new_awaiting_invoice(
2252
2270
payment_id, expiration, Retry :: Attempts ( 0 ) ,
2253
- Some ( invoice. amount_msats( ) / 100 + 50_000 )
2271
+ Some ( invoice. amount_msats( ) / 100 + 50_000 ) , None
2254
2272
) . is_ok( )
2255
2273
) ;
2256
2274
assert ! ( outbound_payments. has_pending_payments( ) ) ;
@@ -2347,7 +2365,7 @@ mod tests {
2347
2365
2348
2366
assert ! (
2349
2367
outbound_payments. add_new_awaiting_invoice(
2350
- payment_id, expiration, Retry :: Attempts ( 0 ) , Some ( 1234 )
2368
+ payment_id, expiration, Retry :: Attempts ( 0 ) , Some ( 1234 ) , None
2351
2369
) . is_ok( )
2352
2370
) ;
2353
2371
assert ! ( outbound_payments. has_pending_payments( ) ) ;
0 commit comments