Skip to content
This repository was archived by the owner on Feb 3, 2025. It is now read-only.

Commit 683663f

Browse files
committed
Track pending send payjoin original_psbt tx
1 parent 363826d commit 683663f

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

mutiny-core/src/nodemanager.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,17 @@ impl<S: MutinyStorage> NodeManager<S> {
821821
let address = Address::from_str(&uri.address.to_string())
822822
.map_err(|_| MutinyError::PayjoinConfigError)?;
823823
let original_psbt = self.wallet.create_signed_psbt(address, amount, fee_rate)?;
824-
// TODO ensure this creates a pending tx in the UI. Ensure locked UTXO.
824+
// Track this transaction in the wallet so it shows as an ActivityItem in UI.
825+
// We'll cancel it if and when this original_psbt fallback is replaced with a payjoin.
826+
// TODO mark as a payjoin
827+
self.wallet
828+
.insert_tx(
829+
original_psbt.clone().extract_tx(),
830+
ConfirmationTime::unconfirmed(crate::utils::now().as_secs()),
831+
None,
832+
)
833+
.await?;
834+
825835
let fee_rate = if let Some(rate) = fee_rate {
826836
FeeRate::from_sat_per_vb(rate)
827837
} else {
@@ -856,6 +866,7 @@ impl<S: MutinyStorage> NodeManager<S> {
856866
let proposal_psbt = match Self::poll_payjoin_sender(stop, req_ctx).await {
857867
Ok(psbt) => psbt,
858868
Err(e) => {
869+
// self.wallet cancel_tx
859870
log_error!(logger, "Error polling payjoin sender: {e}");
860871
return;
861872
}
@@ -924,11 +935,13 @@ impl<S: MutinyStorage> NodeManager<S> {
924935
labels: Vec<String>,
925936
) -> Result<Txid, MutinyError> {
926937
log_debug!(logger, "Sending payjoin..");
938+
let original_tx = original_psbt.clone().extract_tx();
927939
let tx = wallet
928940
.send_payjoin(original_psbt, proposal_psbt, labels)
929941
.await?;
930942
let txid = tx.txid();
931943
wallet.broadcast_transaction(tx).await?;
944+
wallet.cancel_tx(&original_tx)?;
932945
log_info!(logger, "Payjoin broadcast! TXID: {txid}");
933946
Ok(txid)
934947
}

mutiny-core/src/onchain.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,12 @@ impl<S: MutinyStorage> OnChainWallet<S> {
279279
Ok(())
280280
}
281281

282+
pub(crate) fn cancel_tx(&self, tx: &Transaction) -> Result<(), MutinyError> {
283+
let mut wallet = self.wallet.try_write()?;
284+
wallet.cancel_tx(&tx);
285+
Ok(())
286+
}
287+
282288
fn is_mine(&self, script: &Script) -> Result<bool, MutinyError> {
283289
Ok(self.wallet.try_read()?.is_mine(script))
284290
}

0 commit comments

Comments
 (0)