@@ -887,7 +887,7 @@ impl Node {
887
887
Ok ( _payment_id) => {
888
888
let payee_pubkey = invoice. recover_payee_pub_key ( ) ;
889
889
let amt_msat = invoice. amount_milli_satoshis ( ) . unwrap ( ) ;
890
- log_info ! ( self . logger, "Initiated sending {} msats to {}" , amt_msat, payee_pubkey) ;
890
+ log_info ! ( self . logger, "Initiated sending {}msat to {}" , amt_msat, payee_pubkey) ;
891
891
892
892
outbound_payments_lock. insert (
893
893
payment_hash,
@@ -922,9 +922,13 @@ impl Node {
922
922
}
923
923
}
924
924
925
- /// Send a payement given a so-called "zero amount" invoice, i.e., an invoice that leaves the
925
+ /// Send a payment given an invoice and an amount in millisatoshi.
926
+ ///
927
+ /// This will fail if the amount given is less than the value required by the given invoice.
928
+ ///
929
+ /// This can be used to pay a so-called "zero-amount" invoice, i.e., an invoice that leaves the
926
930
/// amount paid to be determined by the user.
927
- pub fn send_adjustable_value_payment (
931
+ pub fn send_payment_using_amount (
928
932
& self , invoice : Invoice , amount_msat : u64 ,
929
933
) -> Result < PaymentHash , Error > {
930
934
if self . running . read ( ) . unwrap ( ) . is_none ( ) {
@@ -933,27 +937,58 @@ impl Node {
933
937
934
938
let mut outbound_payments_lock = self . outbound_payments . lock ( ) . unwrap ( ) ;
935
939
940
+ if let Some ( invoice_amount_msat) = invoice. amount_milli_satoshis ( ) {
941
+ if amount_msat < invoice_amount_msat {
942
+ log_error ! (
943
+ self . logger,
944
+ "Failed to pay as the given amount needs to be larger or equal to the invoice amount: required {}msat, gave {}msat." , invoice_amount_msat, amount_msat) ;
945
+ return Err ( Error :: InvalidAmount ) ;
946
+ }
947
+ }
948
+
949
+ let payment_id = PaymentId ( invoice. payment_hash ( ) . into_inner ( ) ) ;
936
950
let payment_hash = PaymentHash ( ( * invoice. payment_hash ( ) ) . into_inner ( ) ) ;
937
951
let payment_secret = Some ( * invoice. payment_secret ( ) ) ;
938
-
939
- if invoice. amount_milli_satoshis ( ) . is_some ( ) {
940
- log_error ! (
941
- self . logger,
942
- "Failed to pay the given invoice: expected \" zero-amount\" invoice, please use send_payment."
943
- ) ;
944
- return Err ( Error :: InvalidInvoice ) ;
952
+ let expiry_time = invoice
953
+ . clone ( )
954
+ . into_signed_raw ( )
955
+ . raw_invoice ( )
956
+ . data
957
+ . timestamp
958
+ . as_duration_since_epoch ( )
959
+ + invoice. expiry_time ( ) ;
960
+ let mut payment_params = PaymentParameters :: from_node_id (
961
+ invoice. recover_payee_pub_key ( ) ,
962
+ invoice. min_final_cltv_expiry_delta ( ) as u32 ,
963
+ )
964
+ . with_expiry_time ( expiry_time. as_secs ( ) )
965
+ . with_route_hints ( invoice. route_hints ( ) ) ;
966
+ if let Some ( features) = invoice. features ( ) {
967
+ payment_params = payment_params. with_features ( features. clone ( ) ) ;
945
968
}
946
-
947
- match lightning_invoice:: payment:: pay_zero_value_invoice (
948
- & invoice,
949
- amount_msat,
950
- Retry :: Timeout ( LDK_PAYMENT_RETRY_TIMEOUT ) ,
951
- self . channel_manager . as_ref ( ) ,
952
- ) {
969
+ let route_params = RouteParameters { payment_params, final_value_msat : amount_msat } ;
970
+
971
+ let retry_strategy = Retry :: Timeout ( LDK_PAYMENT_RETRY_TIMEOUT ) ;
972
+
973
+ match self
974
+ . channel_manager
975
+ . send_payment_with_retry (
976
+ payment_hash,
977
+ & payment_secret,
978
+ payment_id,
979
+ route_params,
980
+ retry_strategy,
981
+ )
982
+ . map_err ( payment:: PaymentError :: Sending )
983
+ {
953
984
Ok ( _payment_id) => {
954
985
let payee_pubkey = invoice. recover_payee_pub_key ( ) ;
955
- let amt_msat = invoice. amount_milli_satoshis ( ) . unwrap ( ) ;
956
- log_info ! ( self . logger, "Initiated sending {} msats to {}" , amt_msat, payee_pubkey) ;
986
+ log_info ! (
987
+ self . logger,
988
+ "Initiated sending {} msat to {}" ,
989
+ amount_msat,
990
+ payee_pubkey
991
+ ) ;
957
992
958
993
outbound_payments_lock. insert (
959
994
payment_hash,
@@ -1018,7 +1053,7 @@ impl Node {
1018
1053
Retry :: Timeout ( LDK_PAYMENT_RETRY_TIMEOUT ) ,
1019
1054
) {
1020
1055
Ok ( _payment_id) => {
1021
- log_info ! ( self . logger, "Initiated sending {} msats to {}." , amount_msat, node_id) ;
1056
+ log_info ! ( self . logger, "Initiated sending {}msat to {}." , amount_msat, node_id) ;
1022
1057
outbound_payments_lock. insert (
1023
1058
payment_hash,
1024
1059
PaymentInfo {
@@ -1046,8 +1081,23 @@ impl Node {
1046
1081
}
1047
1082
}
1048
1083
1049
- /// Returns a payable invoice that can be used to request and receive a payment.
1084
+ /// Returns a payable invoice that can be used to request and receive a payment of the amount
1085
+ /// given.
1050
1086
pub fn receive_payment (
1087
+ & self , amount_msat : u64 , description : & str , expiry_secs : u32 ,
1088
+ ) -> Result < Invoice , Error > {
1089
+ self . receive_payment_inner ( Some ( amount_msat) , description, expiry_secs)
1090
+ }
1091
+
1092
+ /// Returns a payable invoice that can be used to request and receive a payment for which the
1093
+ /// amount is to be determined by the user, also known as a "zero-amount" invoice.
1094
+ pub fn receive_variable_amount_payment (
1095
+ & self , description : & str , expiry_secs : u32 ,
1096
+ ) -> Result < Invoice , Error > {
1097
+ self . receive_payment_inner ( None , description, expiry_secs)
1098
+ }
1099
+
1100
+ fn receive_payment_inner (
1051
1101
& self , amount_msat : Option < u64 > , description : & str , expiry_secs : u32 ,
1052
1102
) -> Result < Invoice , Error > {
1053
1103
let mut inbound_payments_lock = self . inbound_payments . lock ( ) . unwrap ( ) ;
0 commit comments