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

Commit 10c2961

Browse files
committed
Track pending send payjoin original_psbt tx
1 parent 841cbe6 commit 10c2961

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
@@ -708,7 +708,17 @@ impl<S: MutinyStorage> NodeManager<S> {
708708
let address = Address::from_str(&uri.address.to_string())
709709
.map_err(|_| MutinyError::InvalidArgumentsError)?;
710710
let original_psbt = self.wallet.create_signed_psbt(address, amount, fee_rate)?;
711-
// TODO ensure this creates a pending tx in the UI. Ensure locked UTXO.
711+
// Track this transaction in the wallet so it shows as an ActivityItem in UI.
712+
// We'll cancel it if and when this original_psbt fallback is replaced with a payjoin.
713+
// TODO mark as a payjoin
714+
self.wallet
715+
.insert_tx(
716+
original_psbt.clone().extract_tx(),
717+
ConfirmationTime::unconfirmed(crate::utils::now().as_secs()),
718+
None,
719+
)
720+
.await?;
721+
712722
let fee_rate = if let Some(rate) = fee_rate {
713723
FeeRate::from_sat_per_vb(rate)
714724
} else {
@@ -743,6 +753,7 @@ impl<S: MutinyStorage> NodeManager<S> {
743753
let proposal_psbt = match Self::poll_payjoin_sender(stop, req_ctx).await {
744754
Ok(psbt) => psbt,
745755
Err(e) => {
756+
// self.wallet cancel_tx
746757
log_error!(logger, "Error polling payjoin sender: {e}");
747758
return;
748759
}
@@ -812,11 +823,13 @@ impl<S: MutinyStorage> NodeManager<S> {
812823
labels: Vec<String>,
813824
) -> Result<Txid, MutinyError> {
814825
log_debug!(logger, "Sending payjoin..");
826+
let original_tx = original_psbt.clone().extract_tx();
815827
let tx = wallet
816828
.send_payjoin(original_psbt, proposal_psbt, labels)
817829
.await?;
818830
let txid = tx.txid();
819831
wallet.broadcast_transaction(tx).await?;
832+
wallet.cancel_tx(&original_tx)?;
820833
log_info!(logger, "Payjoin broadcast! TXID: {txid}");
821834
Ok(txid)
822835
}

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)