@@ -19,6 +19,7 @@ use lightning::sign::{EntropySource, KeysManager};
19
19
use lightning:: util:: config:: { ChannelHandshakeConfig , ChannelHandshakeLimits , UserConfig } ;
20
20
use lightning:: util:: persist:: KVStore ;
21
21
use lightning:: util:: ser:: { Writeable , Writer } ;
22
+ use lightning_invoice:: payment:: payment_parameters_from_invoice;
22
23
use lightning_invoice:: { utils, Bolt11Invoice , Currency } ;
23
24
use lightning_persister:: fs_store:: FilesystemStore ;
24
25
use std:: env;
@@ -690,8 +691,16 @@ fn send_payment(
690
691
outbound_payments : & mut OutboundPaymentInfoStorage , fs_store : Arc < FilesystemStore > ,
691
692
) {
692
693
let payment_id = PaymentId ( ( * invoice. payment_hash ( ) ) . to_byte_array ( ) ) ;
693
- let payment_hash = PaymentHash ( ( * invoice. payment_hash ( ) ) . to_byte_array ( ) ) ;
694
694
let payment_secret = Some ( * invoice. payment_secret ( ) ) ;
695
+ let ( payment_hash, recipient_onion, route_params) =
696
+ match payment_parameters_from_invoice ( invoice) {
697
+ Ok ( res) => res,
698
+ Err ( e) => {
699
+ println ! ( "Failed to parse invoice" ) ;
700
+ print ! ( "> " ) ;
701
+ return ;
702
+ }
703
+ } ;
695
704
outbound_payments. payments . insert (
696
705
payment_id,
697
706
PaymentInfo {
@@ -703,42 +712,6 @@ fn send_payment(
703
712
) ;
704
713
fs_store. write ( "" , "" , OUTBOUND_PAYMENTS_FNAME , & outbound_payments. encode ( ) ) . unwrap ( ) ;
705
714
706
- let mut recipient_onion = RecipientOnionFields :: secret_only ( * invoice. payment_secret ( ) ) ;
707
- recipient_onion. payment_metadata = invoice. payment_metadata ( ) . map ( |v| v. clone ( ) ) ;
708
- let mut payment_params = match PaymentParameters :: from_node_id (
709
- invoice. recover_payee_pub_key ( ) ,
710
- invoice. min_final_cltv_expiry_delta ( ) as u32 ,
711
- )
712
- . with_expiry_time (
713
- invoice. duration_since_epoch ( ) . as_secs ( ) . saturating_add ( invoice. expiry_time ( ) . as_secs ( ) ) ,
714
- )
715
- . with_route_hints ( invoice. route_hints ( ) )
716
- {
717
- Err ( e) => {
718
- println ! ( "ERROR: Could not process invoice to prepare payment parameters, {:?}, invoice: {:?}" , e, invoice) ;
719
- return ;
720
- }
721
- Ok ( p) => p,
722
- } ;
723
- if let Some ( features) = invoice. features ( ) {
724
- payment_params = match payment_params. with_bolt11_features ( features. clone ( ) ) {
725
- Err ( e) => {
726
- println ! ( "ERROR: Could not build BOLT11 payment parameters! {:?}" , e) ;
727
- return ;
728
- }
729
- Ok ( p) => p,
730
- } ;
731
- }
732
- let invoice_amount = match invoice. amount_milli_satoshis ( ) {
733
- None => {
734
- println ! ( "ERROR: An invoice with an amount is expected; {:?}" , invoice) ;
735
- return ;
736
- }
737
- Some ( a) => a,
738
- } ;
739
- let route_params =
740
- RouteParameters :: from_payment_params_and_value ( payment_params, invoice_amount) ;
741
-
742
715
match channel_manager. send_payment (
743
716
payment_hash,
744
717
recipient_onion,
0 commit comments