Skip to content

Commit

Permalink
Track pending send payjoin original_psbt tx
Browse files Browse the repository at this point in the history
  • Loading branch information
DanGould committed Jan 11, 2024
1 parent ff439a4 commit e20e87b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
15 changes: 14 additions & 1 deletion mutiny-core/src/nodemanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,17 @@ impl<S: MutinyStorage> NodeManager<S> {
let address = Address::from_str(&uri.address.to_string())
.map_err(|_| MutinyError::PayjoinConfigError)?;
let original_psbt = self.wallet.create_signed_psbt(address, amount, fee_rate)?;
// TODO ensure this creates a pending tx in the UI. Ensure locked UTXO.
// Track this transaction in the wallet so it shows as an ActivityItem in UI.
// We'll cancel it if and when this original_psbt fallback is replaced with a payjoin.
// TODO mark as a payjoin
self.wallet
.insert_tx(
original_psbt.clone().extract_tx(),
ConfirmationTime::unconfirmed(crate::utils::now().as_secs()),
None,
)
.await?;

let fee_rate = if let Some(rate) = fee_rate {
FeeRate::from_sat_per_vb(rate)
} else {
Expand Down Expand Up @@ -856,6 +866,7 @@ impl<S: MutinyStorage> NodeManager<S> {
let proposal_psbt = match Self::poll_payjoin_sender(stop, req_ctx).await {
Ok(psbt) => psbt,
Err(e) => {
// self.wallet cancel_tx
log_error!(logger, "Error polling payjoin sender: {e}");
return;
}
Expand Down Expand Up @@ -924,11 +935,13 @@ impl<S: MutinyStorage> NodeManager<S> {
labels: Vec<String>,
) -> Result<Txid, MutinyError> {
log_debug!(logger, "Sending payjoin..");
let original_tx = original_psbt.clone().extract_tx();
let tx = wallet
.send_payjoin(original_psbt, proposal_psbt, labels)
.await?;
let txid = tx.txid();
wallet.broadcast_transaction(tx).await?;
wallet.cancel_tx(&original_tx)?;
log_info!(logger, "Payjoin broadcast! TXID: {txid}");
Ok(txid)
}
Expand Down
6 changes: 6 additions & 0 deletions mutiny-core/src/onchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,12 @@ impl<S: MutinyStorage> OnChainWallet<S> {
Ok(())
}

pub(crate) fn cancel_tx(&self, tx: &Transaction) -> Result<(), MutinyError> {
let mut wallet = self.wallet.try_write()?;
wallet.cancel_tx(&tx);
Ok(())
}

fn is_mine(&self, script: &Script) -> Result<bool, MutinyError> {
Ok(self.wallet.try_read()?.is_mine(script))
}
Expand Down

0 comments on commit e20e87b

Please sign in to comment.