Skip to content

Commit c4a3b8c

Browse files
committed
Merge #393: refactor(wallet)!: Remove Wallet::cancel_tx function
1854b8e cleanup(wallet)!: remove cancel_tx function (Steve Myers) Pull request description: ### Description Per discussion in team chat today I'm removing the `Wallet::cancel_tx` function because it's name is misleading and the `Wallet::mark_unused` function can be used to accomplish the same function. closes #326 and closes #212 and closes #41 ### Notes to the reviewers This is an example of how to use `mark_unused` instead of `cancel_tx` ```rust /// This marks as unused the change addresses used when creating a tx so they can be used in future transactions. for txout in &tx.output { if let Some((keychain, index)) = txout_index.index_of_spk(txout.script_pubkey.clone()) { // NOTE: unmark_used will **not** make something unused if it has actually been used // by a tx in the tracker. It only removes the superficial marking. wallet.unmark_used(*keychain, *index); } } ``` ### Changelog notice - BREAKING: Remove Wallet::cancel_tx function. Use Wallet::unmark_used instead ### Checklists #### All Submissions: * [x] I've signed all my commits * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md) * [x] I ran `just p` before pushing #### Bugfixes: * [x] This pull request breaks the existing API * [ ] I've added tests to reproduce the issue which are now passing * [x] I'm linking the issue being fixed by this PR ACKs for top commit: ValuedMammal: ACK 1854b8e Tree-SHA512: c5fe988c61591267ce4c96fa005355d30a24c006431e60b276ab4a18c0a7be336a53f6c9800b43ab3e915dcb5c1847827e624854c56c14039caf54df4d456758
2 parents 491d1b6 + 1854b8e commit c4a3b8c

2 files changed

Lines changed: 0 additions & 86 deletions

File tree

src/wallet/mod.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1965,21 +1965,6 @@ impl Wallet {
19651965
.0
19661966
}
19671967

1968-
/// Informs the wallet that you no longer intend to broadcast a tx that was built from it.
1969-
///
1970-
/// This frees up the change address used when creating the tx for use in future transactions.
1971-
// TODO: Make this free up reserved utxos when that's implemented
1972-
pub fn cancel_tx(&mut self, tx: &Transaction) {
1973-
let txout_index = &mut self.tx_graph.index;
1974-
for txout in &tx.output {
1975-
if let Some((keychain, index)) = txout_index.index_of_spk(txout.script_pubkey.clone()) {
1976-
// NOTE: unmark_used will **not** make something unused if it has actually been used
1977-
// by a tx in the tracker. It only removes the superficial marking.
1978-
txout_index.unmark_used(*keychain, *index);
1979-
}
1980-
}
1981-
}
1982-
19831968
fn get_descriptor_for_txout(&self, txout: &TxOut) -> Option<DerivedDescriptor> {
19841969
let &(keychain, child) = self
19851970
.tx_graph

tests/wallet.rs

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -2768,77 +2768,6 @@ fn test_keychains_with_overlapping_spks() {
27682768
assert_eq!(wallet.balance().confirmed, Amount::from_sat(58000));
27692769
}
27702770

2771-
#[test]
2772-
/// The wallet should re-use previously allocated change addresses when the tx using them is
2773-
/// cancelled
2774-
fn test_tx_cancellation() {
2775-
macro_rules! new_tx {
2776-
($wallet:expr) => {{
2777-
let addr = Address::from_str("2N4eQYCbKUHCCTUjBJeHcJp9ok6J2GZsTDt")
2778-
.unwrap()
2779-
.assume_checked();
2780-
let mut builder = $wallet.build_tx();
2781-
builder.add_recipient(addr.script_pubkey(), Amount::from_sat(10_000));
2782-
2783-
let psbt = builder.finish().unwrap();
2784-
2785-
psbt
2786-
}};
2787-
}
2788-
2789-
let (mut wallet, _) = get_funded_wallet(get_test_wpkh(), get_test_tr_single_sig_xprv());
2790-
2791-
let psbt1 = new_tx!(wallet);
2792-
let change_derivation_1 = psbt1
2793-
.unsigned_tx
2794-
.output
2795-
.iter()
2796-
.find_map(|txout| wallet.derivation_of_spk(txout.script_pubkey.clone()))
2797-
.unwrap();
2798-
assert_eq!(change_derivation_1, (KeychainKind::Internal, 0));
2799-
2800-
let psbt2 = new_tx!(wallet);
2801-
2802-
let change_derivation_2 = psbt2
2803-
.unsigned_tx
2804-
.output
2805-
.iter()
2806-
.find_map(|txout| wallet.derivation_of_spk(txout.script_pubkey.clone()))
2807-
.unwrap();
2808-
assert_eq!(change_derivation_2, (KeychainKind::Internal, 1));
2809-
2810-
wallet.cancel_tx(&psbt1.extract_tx().expect("failed to extract tx"));
2811-
2812-
let psbt3 = new_tx!(wallet);
2813-
let change_derivation_3 = psbt3
2814-
.unsigned_tx
2815-
.output
2816-
.iter()
2817-
.find_map(|txout| wallet.derivation_of_spk(txout.script_pubkey.clone()))
2818-
.unwrap();
2819-
assert_eq!(change_derivation_3, (KeychainKind::Internal, 0));
2820-
2821-
let psbt3 = new_tx!(wallet);
2822-
let change_derivation_3 = psbt3
2823-
.unsigned_tx
2824-
.output
2825-
.iter()
2826-
.find_map(|txout| wallet.derivation_of_spk(txout.script_pubkey.clone()))
2827-
.unwrap();
2828-
assert_eq!(change_derivation_3, (KeychainKind::Internal, 2));
2829-
2830-
wallet.cancel_tx(&psbt3.extract_tx().expect("failed to extract tx"));
2831-
2832-
let psbt3 = new_tx!(wallet);
2833-
let change_derivation_4 = psbt3
2834-
.unsigned_tx
2835-
.output
2836-
.iter()
2837-
.find_map(|txout| wallet.derivation_of_spk(txout.script_pubkey.clone()))
2838-
.unwrap();
2839-
assert_eq!(change_derivation_4, (KeychainKind::Internal, 2));
2840-
}
2841-
28422771
#[test]
28432772
fn test_thread_safety() {
28442773
fn thread_safe<T: Send + Sync>() {}

0 commit comments

Comments
 (0)