@@ -771,9 +771,10 @@ impl<S: MutinyStorage> NodeManager<S> {
771771
772772 pub fn spawn_payjoin_receiver ( & self , enrolled : Enrolled ) {
773773 let logger = self . logger . clone ( ) ;
774+ let stop = self . stop . clone ( ) ;
774775 let wallet = self . wallet . clone ( ) ;
775776 utils:: spawn ( async move {
776- match Self :: receive_payjoin ( wallet, enrolled) . await {
777+ match Self :: receive_payjoin ( wallet, stop , enrolled) . await {
777778 Ok ( txid) => log_info ! ( logger, "Received payjoin txid: {txid}" ) ,
778779 Err ( e) => log_error ! ( logger, "Error receiving payjoin: {e}" ) ,
779780 } ;
@@ -783,13 +784,14 @@ impl<S: MutinyStorage> NodeManager<S> {
783784 /// Poll the payjoin relay to maintain a payjoin session and create a payjoin proposal.
784785 async fn receive_payjoin (
785786 wallet : Arc < OnChainWallet < S > > ,
787+ stop : Arc < AtomicBool > ,
786788 mut enrolled : payjoin:: receive:: v2:: Enrolled ,
787789 ) -> Result < Txid , MutinyError > {
788790 let http_client = reqwest:: Client :: builder ( )
789791 . build ( )
790792 . map_err ( PayjoinError :: Reqwest ) ?;
791793 let proposal: payjoin:: receive:: v2:: UncheckedProposal =
792- Self :: poll_for_fallback_psbt ( & http_client, & mut enrolled) . await ?;
794+ Self :: poll_for_fallback_psbt ( stop , & http_client, & mut enrolled) . await ?;
793795 let original_tx = proposal. extract_tx_to_schedule_broadcast ( ) ;
794796 let mut payjoin_proposal = match wallet. process_payjoin_proposal ( proposal) {
795797 Ok ( p) => p,
@@ -818,10 +820,14 @@ impl<S: MutinyStorage> NodeManager<S> {
818820 }
819821
820822 async fn poll_for_fallback_psbt (
823+ stop : Arc < AtomicBool > ,
821824 client : & reqwest:: Client ,
822825 enroller : & mut payjoin:: receive:: v2:: Enrolled ,
823826 ) -> Result < payjoin:: receive:: v2:: UncheckedProposal , PayjoinError > {
824827 loop {
828+ if stop. load ( Ordering :: Relaxed ) {
829+ return Err ( crate :: payjoin:: Error :: Shutdown ) ;
830+ }
825831 let ( req, context) = enroller. extract_req ( ) ?;
826832 let ohttp_response = client
827833 . post ( req. url )
0 commit comments