Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(wallet): use map_keychain in Wallet::build_fee_bump #1812

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/wallet/src/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1676,7 +1676,7 @@ impl Wallet {
if tx.output.len() > 1 {
let mut change_index = None;
for (index, txout) in tx.output.iter().enumerate() {
let change_keychain = KeychainKind::Internal;
let change_keychain = self.map_keychain(KeychainKind::Internal);
match txout_index.index_of_spk(txout.script_pubkey.clone()) {
Some((keychain, _)) if *keychain == change_keychain => {
change_index = Some(index)
Expand Down
46 changes: 46 additions & 0 deletions crates/wallet/src/wallet/tx_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1052,4 +1052,50 @@ mod test {
assert_eq!(filtered.len(), 1);
assert_eq!(filtered[0].keychain, KeychainKind::Internal);
}

#[test]
fn test_build_fee_bump_remove_change_output_single_desc() {
use crate::test_utils::*;
use bdk_chain::BlockId;
use bitcoin::{hashes::Hash, BlockHash, Network};

let mut wallet = Wallet::create_single(get_test_tr_single_sig())
.network(Network::Regtest)
.create_wallet_no_persist()
.unwrap();

insert_checkpoint(
&mut wallet,
BlockId {
height: 1,
hash: BlockHash::all_zeros(),
},
);

receive_output_in_latest_block(&mut wallet, Amount::ONE_BTC.to_sat());

// tx1 sending 15k sat to a recipient
let recip = ScriptBuf::from_hex(
"5120e8f5c4dc2f5d6a7595e7b108cb063da9c7550312da1e22875d78b9db62b59cd5",
)
.unwrap();
let mut builder = wallet.build_tx();
builder.add_recipient(recip.clone(), Amount::from_sat(15_000));
builder.fee_absolute(Amount::from_sat(1_000));
let psbt = builder.finish().unwrap();

let tx = psbt.extract_tx().unwrap();
let txid = tx.compute_txid();
let feerate = wallet.calculate_fee_rate(&tx).unwrap().to_sat_per_kwu();
insert_tx(&mut wallet, tx);

// build fee bump
let mut builder = wallet.build_fee_bump(txid).unwrap();
assert_eq!(
builder.params.recipients,
vec![(recip, Amount::from_sat(15_000))]
);
builder.fee_rate(FeeRate::from_sat_per_kwu(feerate + 250));
let _ = builder.finish().unwrap();
}
}
Loading