Skip to content

Commit

Permalink
rbf: pass change_address to create_spend_internal
Browse files Browse the repository at this point in the history
  • Loading branch information
jp1ac4 committed Nov 24, 2023
1 parent 908c03b commit 711204b
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1059,25 +1059,26 @@ impl DaemonControl {
.collect();
// Set the change index we'll use for the replacement transaction, if any, to that of
// the change output with the largest value and then largest index.
let change_index = prev_derivs
let change_address = prev_derivs
.iter()
.filter_map(|(_, amt, deriv)| {
.filter_map(|(addr, amt, deriv)| {
if let Some((ind, true)) = &deriv {
Some((*ind, amt))
Some((addr, amt, ind))
} else {
None
}
})
.max_by(|(ind_1, amt_1), (ind_2, amt_2)| amt_1.cmp(amt_2).then(ind_1.cmp(ind_2)))
.map(|(ind, _)| ind);
.max_by(|(_, amt_1, ind_1), (_, amt_2, ind_2)| amt_1.cmp(amt_2).then(ind_1.cmp(ind_2)))
.map(|(addr, _, _)| addr);
// Use all previous outputs as destinations, except for the output corresponding to the change index we found above.
let destinations: HashMap<bitcoin::Address, bitcoin::Amount> = prev_derivs
.iter()
.filter_map(|(addr, amt, deriv)| match deriv {
Some((ind, true)) if *ind == change_index.expect("change_index is some here") => {
.filter_map(|(addr, amt, _)| {
if change_address != Some(addr) {
Some((addr.clone(), *amt))
} else {
None
}
_ => Some((addr.clone(), *amt)),
})
.collect();

Expand Down Expand Up @@ -1127,12 +1128,12 @@ impl DaemonControl {
// will ensure that the PSBT meets the required replacement fee and the loop will exit.
let min_fee = mempool_entry.fees.descendant.to_sat() + rbf_vsize;
println!("trying min_fee of {}", min_fee);
let rbf_psbt = match self.create_rbf_spend(
let rbf_psbt = match self.create_spend_internal(
&destinations,
&candidate_coins,
feerate_vb,
min_fee,
change_index,
change_address.cloned(),
) {
Ok(psbt) => psbt,
// If we get a coin selection error due to insufficient funds and we want to cancel the
Expand Down

0 comments on commit 711204b

Please sign in to comment.