@@ -9,8 +9,6 @@ use bitcoin::hashes::Hash;
99use bitcoin:: network:: Network ;
1010use bitcoin:: secp256k1:: PublicKey ;
1111use lightning:: chain:: channelmonitor:: Balance ;
12- // use lightning::ln::bolt11_payment::payment_parameters_from_invoice;
13- // use lightning::ln::bolt11_payment::payment_parameters_from_variable_amount_invoice;
1412use lightning:: ln:: channelmanager:: {
1513 Bolt11InvoiceParameters , PaymentId , RecipientOnionFields , Retry ,
1614} ;
@@ -829,36 +827,27 @@ fn send_payment(
829827) {
830828 let payment_id = PaymentId ( ( * invoice. payment_hash ( ) ) . to_byte_array ( ) ) ;
831829 let payment_secret = Some ( * invoice. payment_secret ( ) ) ;
832- // let zero_amt_invoice =
833- // invoice.amount_milli_satoshis().is_none() || invoice.amount_milli_satoshis() == Some(0);
834- // let pay_params_opt = if zero_amt_invoice {
835- // if let Some(amt_msat) = required_amount_msat {
836- // payment_parameters_from_variable_amount_invoice(invoice, amt_msat)
837- // } else {
838- // println!("Need an amount for the given 0-value invoice");
839- // print!("> ");
840- // return;
841- // }
842- // } else {
843- // if required_amount_msat.is_some() && invoice.amount_milli_satoshis() != required_amount_msat
844- // {
845- // println!(
846- // "Amount didn't match invoice value of {}msat",
847- // invoice.amount_milli_satoshis().unwrap_or(0)
848- // );
849- // print!("> ");
850- // return;
851- // }
852- // payment_parameters_from_invoice(invoice)
853- // };
854- // let (payment_hash, recipient_onion, route_params) = match pay_params_opt {
855- // Ok(res) => res,
856- // Err(e) => {
857- // println!("Failed to parse invoice: {:?}", e);
858- // print!("> ");
859- // return;
860- // },
861- // };
830+ let zero_amt_invoice =
831+ invoice. amount_milli_satoshis ( ) . is_none ( ) || invoice. amount_milli_satoshis ( ) == Some ( 0 ) ;
832+ let amount_msats = if zero_amt_invoice {
833+ if required_amount_msat. is_none ( ) {
834+ println ! ( "Need an amount for the given 0-value invoice" ) ;
835+ print ! ( "> " ) ;
836+ return ;
837+ }
838+ required_amount_msat
839+ } else {
840+ if required_amount_msat. is_some ( ) && invoice. amount_milli_satoshis ( ) != required_amount_msat
841+ {
842+ println ! (
843+ "Amount didn't match invoice value of {}msat" ,
844+ invoice. amount_milli_satoshis( ) . unwrap_or( 0 )
845+ ) ;
846+ print ! ( "> " ) ;
847+ return ;
848+ }
849+ None
850+ } ;
862851 outbound_payments. payments . insert (
863852 payment_id,
864853 PaymentInfo {
@@ -870,34 +859,27 @@ fn send_payment(
870859 ) ;
871860 fs_store. write ( "" , "" , OUTBOUND_PAYMENTS_FNAME , & outbound_payments. encode ( ) ) . unwrap ( ) ;
872861
873- // TODO: fix this so the amounts match
874- let amount_msats = invoice. amount_milli_satoshis ( ) . or ( required_amount_msat) ;
875862 let route_params_config = RouteParametersConfig :: default ( ) ;
876- channel_manager. pay_for_bolt11_invoice (
877- invoice, payment_id, amount_msats, route_params_config,
878- Retry :: Timeout ( Duration :: from_secs ( 10 ) )
879- ) . unwrap ( ) ;
880-
881- // match channel_manager.send_payment(
882- // payment_hash,
883- // recipient_onion,
884- // payment_id,
885- // route_params,
886- // Retry::Timeout(Duration::from_secs(10)),
887- // ) {
888- // Ok(_) => {
889- // let payee_pubkey = invoice.recover_payee_pub_key();
890- // let amt_msat = invoice.amount_milli_satoshis().unwrap();
891- // println!("EVENT: initiated sending {} msats to {}", amt_msat, payee_pubkey);
892- // print!("> ");
893- // },
894- // Err(e) => {
895- // println!("ERROR: failed to send payment: {:?}", e);
896- // print!("> ");
897- // outbound_payments.payments.get_mut(&payment_id).unwrap().status = HTLCStatus::Failed;
898- // fs_store.write("", "", OUTBOUND_PAYMENTS_FNAME, &outbound_payments.encode()).unwrap();
899- // },
900- // };
863+ match channel_manager. pay_for_bolt11_invoice (
864+ invoice,
865+ payment_id,
866+ amount_msats,
867+ route_params_config,
868+ Retry :: Timeout ( Duration :: from_secs ( 10 ) ) ,
869+ ) {
870+ Ok ( _) => {
871+ let payee_pubkey = invoice. recover_payee_pub_key ( ) ;
872+ let amt_msat = invoice. amount_milli_satoshis ( ) . unwrap ( ) ;
873+ println ! ( "EVENT: initiated sending {} msats to {}" , amt_msat, payee_pubkey) ;
874+ print ! ( "> " ) ;
875+ } ,
876+ Err ( e) => {
877+ println ! ( "ERROR: failed to send payment: {:?}" , e) ;
878+ print ! ( "> " ) ;
879+ outbound_payments. payments . get_mut ( & payment_id) . unwrap ( ) . status = HTLCStatus :: Failed ;
880+ fs_store. write ( "" , "" , OUTBOUND_PAYMENTS_FNAME , & outbound_payments. encode ( ) ) . unwrap ( ) ;
881+ } ,
882+ } ;
901883}
902884
903885fn keysend < E : EntropySource > (
0 commit comments