@@ -774,9 +774,10 @@ impl<S: MutinyStorage> NodeManager<S> {
774774
775775 pub fn spawn_payjoin_receiver ( & self , enrolled : Enrolled ) {
776776 let logger = self . logger . clone ( ) ;
777+ let stop = self . stop . clone ( ) ;
777778 let wallet = self . wallet . clone ( ) ;
778779 utils:: spawn ( async move {
779- match Self :: receive_payjoin ( wallet, enrolled) . await {
780+ match Self :: receive_payjoin ( wallet, stop , enrolled) . await {
780781 Ok ( txid) => log_info ! ( logger, "Received payjoin txid: {txid}" ) ,
781782 Err ( e) => log_error ! ( logger, "Error receiving payjoin: {e}" ) ,
782783 } ;
@@ -786,13 +787,14 @@ impl<S: MutinyStorage> NodeManager<S> {
786787 /// Poll the payjoin relay to maintain a payjoin session and create a payjoin proposal.
787788 async fn receive_payjoin (
788789 wallet : Arc < OnChainWallet < S > > ,
790+ stop : Arc < AtomicBool > ,
789791 mut enrolled : payjoin:: receive:: v2:: Enrolled ,
790792 ) -> Result < Txid , MutinyError > {
791793 let http_client = reqwest:: Client :: builder ( )
792794 . build ( )
793795 . map_err ( PayjoinError :: Reqwest ) ?;
794796 let proposal: payjoin:: receive:: v2:: UncheckedProposal =
795- Self :: poll_for_fallback_psbt ( & http_client, & mut enrolled) . await ?;
797+ Self :: poll_for_fallback_psbt ( stop , & http_client, & mut enrolled) . await ?;
796798 let original_tx = proposal. extract_tx_to_schedule_broadcast ( ) ;
797799 let mut payjoin_proposal = match wallet
798800 . process_payjoin_proposal ( proposal)
@@ -824,10 +826,14 @@ impl<S: MutinyStorage> NodeManager<S> {
824826 }
825827
826828 async fn poll_for_fallback_psbt (
829+ stop : Arc < AtomicBool > ,
827830 client : & reqwest:: Client ,
828831 enroller : & mut payjoin:: receive:: v2:: Enrolled ,
829832 ) -> Result < payjoin:: receive:: v2:: UncheckedProposal , PayjoinError > {
830833 loop {
834+ if stop. load ( Ordering :: Relaxed ) {
835+ return Err ( crate :: payjoin:: Error :: Shutdown ) ;
836+ }
831837 let ( req, context) = enroller. extract_req ( ) ?;
832838 let ohttp_response = client
833839 . post ( req. url )
0 commit comments