@@ -184,6 +184,18 @@ impl PendingOutboundPayment {
184
184
}
185
185
}
186
186
187
+ fn keysend_preimage ( & self ) -> Option < PaymentPreimage > {
188
+ match self {
189
+ PendingOutboundPayment :: StaticInvoiceReceived { keysend_preimage, .. } => Some ( * keysend_preimage) ,
190
+ PendingOutboundPayment :: Retryable { keysend_preimage, .. } => * keysend_preimage,
191
+ PendingOutboundPayment :: Legacy { .. } => None ,
192
+ PendingOutboundPayment :: AwaitingInvoice { .. } => None ,
193
+ PendingOutboundPayment :: InvoiceReceived { .. } => None ,
194
+ PendingOutboundPayment :: Fulfilled { .. } => None ,
195
+ PendingOutboundPayment :: Abandoned { .. } => None ,
196
+ }
197
+ }
198
+
187
199
fn mark_fulfilled ( & mut self ) {
188
200
let mut session_privs = new_hash_set ( ) ;
189
201
core:: mem:: swap ( & mut session_privs, match self {
@@ -871,6 +883,47 @@ impl OutboundPayments {
871
883
} ;
872
884
}
873
885
886
+ #[ cfg( async_payments) ]
887
+ pub ( super ) fn send_payment_for_static_invoice < R : Deref , ES : Deref , NS : Deref , IH , SP , L : Deref > (
888
+ & self , payment_id : PaymentId , payment_release_secret : [ u8 ; 32 ] , router : & R ,
889
+ first_hops : Vec < ChannelDetails > , inflight_htlcs : IH , entropy_source : & ES , node_signer : & NS ,
890
+ best_block_height : u32 , logger : & L ,
891
+ pending_events : & Mutex < VecDeque < ( events:: Event , Option < EventCompletionAction > ) > > ,
892
+ send_payment_along_path : SP ,
893
+ ) -> Result < ( ) , Bolt12PaymentError >
894
+ where
895
+ R :: Target : Router ,
896
+ ES :: Target : EntropySource ,
897
+ NS :: Target : NodeSigner ,
898
+ L :: Target : Logger ,
899
+ IH : Fn ( ) -> InFlightHtlcs ,
900
+ SP : Fn ( SendAlongPathArgs ) -> Result < ( ) , APIError > ,
901
+ {
902
+ let ( payment_hash, route_params) =
903
+ match self . pending_outbound_payments . lock ( ) . unwrap ( ) . entry ( payment_id) {
904
+ hash_map:: Entry :: Occupied ( entry) => match entry. get ( ) {
905
+ PendingOutboundPayment :: StaticInvoiceReceived {
906
+ payment_hash, payment_release_secret : release_secret, route_params, ..
907
+ } => {
908
+ if payment_release_secret != * release_secret {
909
+ return Err ( Bolt12PaymentError :: UnexpectedInvoice )
910
+ }
911
+ ( * payment_hash, route_params. clone ( ) )
912
+ } ,
913
+ _ => return Err ( Bolt12PaymentError :: DuplicateInvoice ) ,
914
+ } ,
915
+ hash_map:: Entry :: Vacant ( _) => return Err ( Bolt12PaymentError :: UnexpectedInvoice ) ,
916
+ } ;
917
+
918
+ self . find_route_and_send_payment (
919
+ payment_hash, payment_id, route_params, router, first_hops, & inflight_htlcs,
920
+ entropy_source, node_signer, best_block_height, logger, pending_events,
921
+ & send_payment_along_path
922
+ ) ;
923
+
924
+ Ok ( ( ) )
925
+ }
926
+
874
927
pub ( super ) fn check_retry_payments < R : Deref , ES : Deref , NS : Deref , SP , IH , FH , L : Deref > (
875
928
& self , router : & R , first_hops : FH , inflight_htlcs : IH , entropy_source : & ES , node_signer : & NS ,
876
929
best_block_height : u32 ,
@@ -1076,10 +1129,10 @@ impl OutboundPayments {
1076
1129
let mut outbounds = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
1077
1130
match outbounds. entry ( payment_id) {
1078
1131
hash_map:: Entry :: Occupied ( mut payment) => {
1132
+ let keysend_preimage = payment. get ( ) . keysend_preimage ( ) ;
1079
1133
match payment. get ( ) {
1080
1134
PendingOutboundPayment :: Retryable {
1081
- total_msat, keysend_preimage, payment_secret, payment_metadata,
1082
- custom_tlvs, pending_amt_msat, ..
1135
+ total_msat, payment_secret, payment_metadata, custom_tlvs, pending_amt_msat, ..
1083
1136
} => {
1084
1137
const RETRY_OVERFLOW_PERCENTAGE : u64 = 10 ;
1085
1138
let retry_amt_msat = route. get_total_amount ( ) ;
@@ -1101,7 +1154,6 @@ impl OutboundPayments {
1101
1154
payment_metadata : payment_metadata. clone ( ) ,
1102
1155
custom_tlvs : custom_tlvs. clone ( ) ,
1103
1156
} ;
1104
- let keysend_preimage = * keysend_preimage;
1105
1157
1106
1158
let mut onion_session_privs = Vec :: with_capacity ( route. paths . len ( ) ) ;
1107
1159
for _ in 0 ..route. paths . len ( ) {
@@ -1124,7 +1176,9 @@ impl OutboundPayments {
1124
1176
log_error ! ( logger, "Payment not yet sent" ) ;
1125
1177
return
1126
1178
} ,
1127
- PendingOutboundPayment :: InvoiceReceived { payment_hash, retry_strategy, .. } => {
1179
+ PendingOutboundPayment :: InvoiceReceived { payment_hash, retry_strategy, .. } |
1180
+ PendingOutboundPayment :: StaticInvoiceReceived { payment_hash, retry_strategy, .. } =>
1181
+ {
1128
1182
let total_amount = route_params. final_value_msat ;
1129
1183
let recipient_onion = RecipientOnionFields {
1130
1184
payment_secret : None ,
@@ -1134,13 +1188,12 @@ impl OutboundPayments {
1134
1188
let retry_strategy = Some ( * retry_strategy) ;
1135
1189
let payment_params = Some ( route_params. payment_params . clone ( ) ) ;
1136
1190
let ( retryable_payment, onion_session_privs) = self . create_pending_payment (
1137
- * payment_hash, recipient_onion. clone ( ) , None , & route,
1191
+ * payment_hash, recipient_onion. clone ( ) , keysend_preimage , & route,
1138
1192
retry_strategy, payment_params, entropy_source, best_block_height
1139
1193
) ;
1140
1194
* payment. into_mut ( ) = retryable_payment;
1141
- ( total_amount, recipient_onion, None , onion_session_privs)
1195
+ ( total_amount, recipient_onion, keysend_preimage , onion_session_privs)
1142
1196
} ,
1143
- PendingOutboundPayment :: StaticInvoiceReceived { .. } => todo ! ( ) ,
1144
1197
PendingOutboundPayment :: Fulfilled { .. } => {
1145
1198
log_error ! ( logger, "Payment already completed" ) ;
1146
1199
return
0 commit comments