|
1 | 1 | use crate::lnurlauth::AuthManager; |
2 | 2 | use crate::logging::LOGGING_KEY; |
| 3 | +use crate::payjoin::PayjoinStorage; |
3 | 4 | use crate::redshift::{RedshiftManager, RedshiftStatus, RedshiftStorage}; |
4 | 5 | use crate::storage::{MutinyStorage, DEVICE_ID_KEY, KEYCHAIN_STORE_KEY, NEED_FULL_SYNC_KEY}; |
5 | 6 | use crate::utils::{sleep, spawn}; |
@@ -802,6 +803,19 @@ impl<S: MutinyStorage> NodeManager<S> { |
802 | 803 | Ok(()) |
803 | 804 | } |
804 | 805 |
|
| 806 | + /// Starts a background task to poll payjoin sessions to attempt receiving. |
| 807 | + pub(crate) fn resume_payjoins(nm: Arc<NodeManager<S>>) { |
| 808 | + let all = nm.storage.get_payjoins().unwrap_or_default(); |
| 809 | + for payjoin in all { |
| 810 | + let wallet = nm.wallet.clone(); |
| 811 | + let stop = nm.stop.clone(); |
| 812 | + utils::spawn(async move { |
| 813 | + let pj_txid = Self::receive_payjoin(wallet, stop, payjoin).await.unwrap(); |
| 814 | + log::info!("Received payjoin txid: {}", pj_txid); |
| 815 | + }); |
| 816 | + } |
| 817 | + } |
| 818 | + |
805 | 819 | /// Starts a background tasks to poll redshifts until they are ready and then start attempting payments. |
806 | 820 | /// |
807 | 821 | /// This function will first find redshifts that are in the [RedshiftStatus::AttemptingPayments] state and start attempting payments |
@@ -1043,6 +1057,7 @@ impl<S: MutinyStorage> NodeManager<S> { |
1043 | 1057 | .process_res(ohttp_response.as_ref(), context) |
1044 | 1058 | .map_err(|e| anyhow!("parse error {}", e)) |
1045 | 1059 | .unwrap(); |
| 1060 | + self.storage.persist_payjoin(enrolled.clone()).unwrap(); |
1046 | 1061 | let pj_uri = enrolled.fallback_target(); |
1047 | 1062 | log_debug!(self.logger, "{pj_uri}"); |
1048 | 1063 | // run await payjoin task in the background as it'll keep polling the relay |
|
0 commit comments