Skip to content

Commit d9b76ea

Browse files
committed
f - Avoid cloning cancellation scripts
Consume cancellation transactions. This avoids cloning output scripts during wallet cancellation. Co-Authored-By: HAL 9000
1 parent da75376 commit d9b76ea

2 files changed

Lines changed: 8 additions & 10 deletions

File tree

src/event.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1648,7 +1648,7 @@ where
16481648
})
16491649
.collect(),
16501650
};
1651-
if let Err(e) = self.wallet.cancel_tx(&tx) {
1651+
if let Err(e) = self.wallet.cancel_tx(tx) {
16521652
log_error!(self.logger, "Failed reclaiming unused addresses: {}", e);
16531653
return Err(ReplayEvent());
16541654
}

src/wallet/mod.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ impl Wallet {
524524
Ok(address_info.address)
525525
}
526526

527-
pub(crate) fn cancel_tx(&self, tx: &Transaction) -> Result<(), Error> {
527+
pub(crate) fn cancel_tx(&self, tx: Transaction) -> Result<(), Error> {
528528
let mut locked_wallet = self.inner.lock().expect("lock");
529529
let mut locked_persister = self.persister.lock().expect("lock");
530530

@@ -538,12 +538,10 @@ impl Wallet {
538538
}
539539

540540
fn cancel_tx_inner(
541-
locked_wallet: &mut PersistedWallet<KVStoreWalletPersister>, tx: &Transaction,
541+
locked_wallet: &mut PersistedWallet<KVStoreWalletPersister>, tx: Transaction,
542542
) {
543-
for txout in &tx.output {
544-
if let Some((keychain, index)) =
545-
locked_wallet.derivation_of_spk(txout.script_pubkey.clone())
546-
{
543+
for txout in tx.output {
544+
if let Some((keychain, index)) = locked_wallet.derivation_of_spk(txout.script_pubkey) {
547545
// This mirrors the removed BDK helper: it only frees superficial usage marks.
548546
locked_wallet.unmark_used(keychain, index);
549547
}
@@ -702,7 +700,7 @@ impl Wallet {
702700
None,
703701
)?;
704702

705-
Self::cancel_tx_inner(&mut locked_wallet, &tmp_psbt.unsigned_tx);
703+
Self::cancel_tx_inner(&mut locked_wallet, tmp_psbt.unsigned_tx);
706704

707705
Ok(max_amount)
708706
}
@@ -732,7 +730,7 @@ impl Wallet {
732730
Some(&shared_input),
733731
)?;
734732

735-
Self::cancel_tx_inner(&mut locked_wallet, &tmp_psbt.unsigned_tx);
733+
Self::cancel_tx_inner(&mut locked_wallet, tmp_psbt.unsigned_tx);
736734

737735
Ok(splice_amount)
738736
}
@@ -788,7 +786,7 @@ impl Wallet {
788786
e
789787
})?;
790788

791-
Self::cancel_tx_inner(&mut locked_wallet, &tmp_psbt.unsigned_tx);
789+
Self::cancel_tx_inner(&mut locked_wallet, tmp_psbt.unsigned_tx);
792790

793791
let mut tx_builder = locked_wallet.build_tx();
794792
tx_builder

0 commit comments

Comments
 (0)