@@ -25,6 +25,8 @@ use std::string::String;
2525use url:: Url ;
2626use tempfile:: NamedTempFile ;
2727
28+ use crate :: lnclient;
29+
2830//Structs and Enums ------------------------------------------------------------------------------------------
2931#[ derive( Debug , Serialize , Deserialize ) ]
3032struct JwtClaims {
@@ -406,7 +408,7 @@ pub struct ReplyForm {
406408#[ derive( Debug , Serialize , Deserialize ) ]
407409pub struct ReplyResponse {
408410 success : bool ,
409- data : BoostRecord ,
411+ payment : lnclient :: Payment ,
410412}
411413
412414pub async fn api_v1_reply (
@@ -461,10 +463,12 @@ pub async fn api_v1_reply(
461463 } ) ;
462464
463465 let helipad_config = state. helipad_config . clone ( ) ;
464- let lightning = match lightning:: connect_to_lnd ( helipad_config. node_address , helipad_config. cert_path , helipad_config. macaroon_path ) . await {
465- Some ( lndconn) => lndconn,
466- None => {
467- return ( StatusCode :: INTERNAL_SERVER_ERROR , "** Error connecting to LND." ) . into_response ( ) ;
466+
467+ let lightning = match lnclient:: connect ( & helipad_config) . await {
468+ Ok ( conn) => conn,
469+ Err ( e) => {
470+ eprintln ! ( "** Error connecting to node: {}" , e) ;
471+ return ( StatusCode :: INTERNAL_SERVER_ERROR , "** Error connecting to node." ) . into_response ( ) ;
468472 }
469473 } ;
470474
@@ -478,33 +482,27 @@ pub async fn api_v1_reply(
478482
479483 let mut cache = podcastindex:: GuidCache :: new ( 1 ) ;
480484
481- let mut boost = match lightning:: parse_boost_from_payment ( payment, & mut cache) . await {
482- Some ( boost) => boost,
483- None => {
484- eprintln ! ( "** Error parsing sent boost" ) ;
485- return ( StatusCode :: INTERNAL_SERVER_ERROR , "** Error parsing sent boost" ) . into_response ( ) ;
485+ if let Some ( mut boost) = lightning:: parse_boost_from_payment ( & payment, & mut cache) . await {
486+ if let Some ( pay_info) = boost. payment_info {
487+ boost. payment_info = Some ( dbif:: PaymentRecord {
488+ reply_to_idx : Some ( index) ,
489+ ..pay_info
490+ } ) ;
486491 }
487- } ;
488-
489- if let Some ( pay_info) = boost. payment_info {
490- boost. payment_info = Some ( dbif:: PaymentRecord {
491- reply_to_idx : Some ( index) ,
492- ..pay_info
493- } ) ;
494- }
495492
496- //Give some output
497- println ! ( "Sent Boost: {:#?}" , boost) ;
493+ //Give some output
494+ println ! ( "Sent Boost: {:#?}" , boost) ;
498495
499- //Store in the database
500- match dbif:: add_payment_to_db ( & state. helipad_config . database_file_path , & boost) {
501- Ok ( _) => println ! ( "New sent boost added." ) ,
502- Err ( e) => eprintln ! ( "Error adding sent boost: {:#?}" , e)
496+ //Store in the database
497+ match dbif:: add_payment_to_db ( & state. helipad_config . database_file_path , & boost) {
498+ Ok ( _) => println ! ( "New sent boost added." ) ,
499+ Err ( e) => eprintln ! ( "Error adding sent boost: {:#?}" , e)
500+ }
503501 }
504502
505503 Json ( ReplyResponse {
506504 success : true ,
507- data : boost ,
505+ payment : payment ,
508506 } ) . into_response ( )
509507}
510508
0 commit comments