@@ -186,6 +186,18 @@ impl PendingOutboundPayment {
186
186
}
187
187
}
188
188
189
+ fn keysend_preimage ( & self ) -> Option < PaymentPreimage > {
190
+ match self {
191
+ PendingOutboundPayment :: StaticInvoiceReceived { keysend_preimage, .. } => Some ( * keysend_preimage) ,
192
+ PendingOutboundPayment :: Retryable { keysend_preimage, .. } => * keysend_preimage,
193
+ PendingOutboundPayment :: Legacy { .. } => None ,
194
+ PendingOutboundPayment :: AwaitingInvoice { .. } => None ,
195
+ PendingOutboundPayment :: InvoiceReceived { .. } => None ,
196
+ PendingOutboundPayment :: Fulfilled { .. } => None ,
197
+ PendingOutboundPayment :: Abandoned { .. } => None ,
198
+ }
199
+ }
200
+
189
201
fn mark_fulfilled ( & mut self ) {
190
202
let mut session_privs = new_hash_set ( ) ;
191
203
core:: mem:: swap ( & mut session_privs, match self {
@@ -898,6 +910,47 @@ impl OutboundPayments {
898
910
} ;
899
911
}
900
912
913
+ #[ cfg( async_payments) ]
914
+ pub ( super ) fn send_payment_for_static_invoice < R : Deref , ES : Deref , NS : Deref , IH , SP , L : Deref > (
915
+ & self , payment_id : PaymentId , payment_release_secret : [ u8 ; 32 ] , router : & R ,
916
+ first_hops : Vec < ChannelDetails > , inflight_htlcs : IH , entropy_source : & ES , node_signer : & NS ,
917
+ best_block_height : u32 , logger : & L ,
918
+ pending_events : & Mutex < VecDeque < ( events:: Event , Option < EventCompletionAction > ) > > ,
919
+ send_payment_along_path : SP ,
920
+ ) -> Result < ( ) , Bolt12PaymentError >
921
+ where
922
+ R :: Target : Router ,
923
+ ES :: Target : EntropySource ,
924
+ NS :: Target : NodeSigner ,
925
+ L :: Target : Logger ,
926
+ IH : Fn ( ) -> InFlightHtlcs ,
927
+ SP : Fn ( SendAlongPathArgs ) -> Result < ( ) , APIError > ,
928
+ {
929
+ let ( payment_hash, route_params) =
930
+ match self . pending_outbound_payments . lock ( ) . unwrap ( ) . entry ( payment_id) {
931
+ hash_map:: Entry :: Occupied ( entry) => match entry. get ( ) {
932
+ PendingOutboundPayment :: StaticInvoiceReceived {
933
+ payment_hash, payment_release_secret : release_secret, route_params, ..
934
+ } => {
935
+ if payment_release_secret != * release_secret {
936
+ return Err ( Bolt12PaymentError :: UnexpectedInvoice )
937
+ }
938
+ ( * payment_hash, route_params. clone ( ) )
939
+ } ,
940
+ _ => return Err ( Bolt12PaymentError :: DuplicateInvoice ) ,
941
+ } ,
942
+ hash_map:: Entry :: Vacant ( _) => return Err ( Bolt12PaymentError :: UnexpectedInvoice ) ,
943
+ } ;
944
+
945
+ self . find_route_and_send_payment (
946
+ payment_hash, payment_id, route_params, router, first_hops, & inflight_htlcs,
947
+ entropy_source, node_signer, best_block_height, logger, pending_events,
948
+ & send_payment_along_path
949
+ ) ;
950
+
951
+ Ok ( ( ) )
952
+ }
953
+
901
954
pub ( super ) fn check_retry_payments < R : Deref , ES : Deref , NS : Deref , SP , IH , FH , L : Deref > (
902
955
& self , router : & R , first_hops : FH , inflight_htlcs : IH , entropy_source : & ES , node_signer : & NS ,
903
956
best_block_height : u32 ,
@@ -1103,10 +1156,10 @@ impl OutboundPayments {
1103
1156
let mut outbounds = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
1104
1157
match outbounds. entry ( payment_id) {
1105
1158
hash_map:: Entry :: Occupied ( mut payment) => {
1159
+ let keysend_preimage = payment. get ( ) . keysend_preimage ( ) ;
1106
1160
match payment. get ( ) {
1107
1161
PendingOutboundPayment :: Retryable {
1108
- total_msat, keysend_preimage, payment_secret, payment_metadata,
1109
- custom_tlvs, pending_amt_msat, ..
1162
+ total_msat, payment_secret, payment_metadata, custom_tlvs, pending_amt_msat, ..
1110
1163
} => {
1111
1164
const RETRY_OVERFLOW_PERCENTAGE : u64 = 10 ;
1112
1165
let retry_amt_msat = route. get_total_amount ( ) ;
@@ -1128,7 +1181,6 @@ impl OutboundPayments {
1128
1181
payment_metadata : payment_metadata. clone ( ) ,
1129
1182
custom_tlvs : custom_tlvs. clone ( ) ,
1130
1183
} ;
1131
- let keysend_preimage = * keysend_preimage;
1132
1184
1133
1185
let mut onion_session_privs = Vec :: with_capacity ( route. paths . len ( ) ) ;
1134
1186
for _ in 0 ..route. paths . len ( ) {
@@ -1151,7 +1203,9 @@ impl OutboundPayments {
1151
1203
log_error ! ( logger, "Payment not yet sent" ) ;
1152
1204
return
1153
1205
} ,
1154
- PendingOutboundPayment :: InvoiceReceived { payment_hash, retry_strategy, .. } => {
1206
+ PendingOutboundPayment :: InvoiceReceived { payment_hash, retry_strategy, .. } |
1207
+ PendingOutboundPayment :: StaticInvoiceReceived { payment_hash, retry_strategy, .. } =>
1208
+ {
1155
1209
let total_amount = route_params. final_value_msat ;
1156
1210
let recipient_onion = RecipientOnionFields {
1157
1211
payment_secret : None ,
@@ -1161,13 +1215,12 @@ impl OutboundPayments {
1161
1215
let retry_strategy = Some ( * retry_strategy) ;
1162
1216
let payment_params = Some ( route_params. payment_params . clone ( ) ) ;
1163
1217
let ( retryable_payment, onion_session_privs) = self . create_pending_payment (
1164
- * payment_hash, recipient_onion. clone ( ) , None , & route,
1218
+ * payment_hash, recipient_onion. clone ( ) , keysend_preimage , & route,
1165
1219
retry_strategy, payment_params, entropy_source, best_block_height
1166
1220
) ;
1167
1221
* payment. into_mut ( ) = retryable_payment;
1168
- ( total_amount, recipient_onion, None , onion_session_privs)
1222
+ ( total_amount, recipient_onion, keysend_preimage , onion_session_privs)
1169
1223
} ,
1170
- PendingOutboundPayment :: StaticInvoiceReceived { .. } => todo ! ( ) ,
1171
1224
PendingOutboundPayment :: Fulfilled { .. } => {
1172
1225
log_error ! ( logger, "Payment already completed" ) ;
1173
1226
return
0 commit comments