@@ -841,6 +841,11 @@ impl<S: MutinyStorage> NodeManager<S> {
841841 Ok ( ( ) )
842842 }
843843
844+ /// Starts a background tasks to poll payjoin directory to attempt receiving.
845+ pub ( crate ) fn start_payjoins ( nm : Arc < NodeManager < S > > ) {
846+ let all = nm. storage . get_payjoins ( ) . unwrap_or_default ( ) ;
847+ }
848+
844849 /// Starts a background tasks to poll redshifts until they are ready and then start attempting payments.
845850 ///
846851 /// This function will first find redshifts that are in the [RedshiftStatus::AttemptingPayments] state and start attempting payments
@@ -1075,11 +1080,11 @@ impl<S: MutinyStorage> NodeManager<S> {
10751080 . unwrap ( ) ;
10761081 let pj_uri = enrolled. fallback_target ( ) ;
10771082 log_debug ! ( self . logger, "{pj_uri}" ) ;
1078- let wallet = self . wallet . clone ( ) ;
10791083 // run await payjoin task in the background as it'll keep polling the relay
1084+ let wallet = self . wallet . clone ( ) ;
1085+ let stop = self . stop . clone ( ) ;
10801086 utils:: spawn ( async move {
1081- let wallet = wallet. clone ( ) ;
1082- let pj_txid = Self :: receive_payjoin ( wallet, enrolled) . await . unwrap ( ) ;
1087+ let pj_txid = Self :: receive_payjoin ( wallet, stop, enrolled) . await . unwrap ( ) ;
10831088 log:: info!( "Received payjoin txid: {}" , pj_txid) ;
10841089 } ) ;
10851090 Some ( pj_uri)
@@ -1170,19 +1175,20 @@ impl<S: MutinyStorage> NodeManager<S> {
11701175 /// Poll the payjoin relay to maintain a payjoin session and create a payjoin proposal.
11711176 pub async fn receive_payjoin (
11721177 wallet : Arc < OnChainWallet < S > > ,
1178+ stop : Arc < AtomicBool > ,
11731179 mut enrolled : payjoin:: receive:: v2:: Enrolled ,
11741180 ) -> Result < Txid , MutinyError > {
11751181 let http_client = reqwest:: Client :: builder ( )
11761182 //.danger_accept_invalid_certs(true) ? is tls unchecked :O
11771183 . build ( )
11781184 . unwrap ( ) ;
11791185 let proposal: payjoin:: receive:: v2:: UncheckedProposal =
1180- Self :: poll_for_fallback_psbt ( & http_client, & mut enrolled)
1186+ Self :: poll_for_fallback_psbt ( stop , & http_client, & mut enrolled)
11811187 . await
11821188 . unwrap ( ) ;
11831189 let payjoin_proposal = wallet. process_payjoin_proposal ( proposal) . unwrap ( ) ;
11841190
1185- let ( req, ohttp_ctx) = payjoin_proposal. extract_v2_req ( ) . unwrap ( ) ;
1191+ let ( req, ohttp_ctx) = payjoin_proposal. extract_v2_req ( ) . unwrap ( ) ; // extraction failed
11861192 let res = http_client
11871193 . post ( req. url )
11881194 . body ( req. body )
@@ -1201,10 +1207,14 @@ impl<S: MutinyStorage> NodeManager<S> {
12011207 }
12021208
12031209 async fn poll_for_fallback_psbt (
1210+ stop : Arc < AtomicBool > ,
12041211 client : & reqwest:: Client ,
12051212 enroller : & mut payjoin:: receive:: v2:: Enrolled ,
12061213 ) -> Result < payjoin:: receive:: v2:: UncheckedProposal , ( ) > {
12071214 loop {
1215+ if stop. load ( Ordering :: Relaxed ) {
1216+ return Err ( ( ) ) ; // stopped
1217+ }
12081218 let ( req, context) = enroller. extract_req ( ) . unwrap ( ) ;
12091219 let ohttp_response = client. post ( req. url ) . body ( req. body ) . send ( ) . await . unwrap ( ) ;
12101220 let ohttp_response = ohttp_response. bytes ( ) . await . unwrap ( ) ;
0 commit comments