Skip to content

Commit 1854b8e

Browse files
committed
cleanup(wallet)!: remove cancel_tx function
Removed because its name is misleading and mark_unused can be used to accomplish the same function.
1 parent c422104 commit 1854b8e

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
@@ -2762,77 +2762,6 @@ fn test_keychains_with_overlapping_spks() {
27622762
assert_eq!(wallet.balance().confirmed, Amount::from_sat(58000));
27632763
}
27642764

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

0 commit comments

Comments
 (0)