Skip to content

Commit

Permalink
refactor(wallet): cleanup and remove unused code in create_tx
Browse files Browse the repository at this point in the history
  • Loading branch information
notmandatory committed Dec 10, 2024
1 parent ab08b8c commit fefbebc
Showing 1 changed file with 15 additions and 25 deletions.
40 changes: 15 additions & 25 deletions crates/wallet/src/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ use crate::types::*;
use crate::wallet::{
coin_selection::{
DefaultCoinSelectionAlgorithm,
Excess::{self, Change, NoChange},
Excess::{Change, NoChange},
InsufficientFunds,
},
error::{BuildFeeBumpError, CreateTxError, MiniscriptPsbtError},
Expand Down Expand Up @@ -1461,9 +1461,8 @@ impl Wallet {
rng,
)
.map_err(CreateTxError::CoinSelection)?;
fee_amount += Amount::from_sat(coin_selection.fee_amount);
let excess = &coin_selection.excess;

let excess = &coin_selection.excess;
tx.input = coin_selection
.selected
.iter()
Expand Down Expand Up @@ -1500,36 +1499,27 @@ impl Wallet {
}
}

match excess {
NoChange {
remaining_amount, ..
} => fee_amount += Amount::from_sat(*remaining_amount),
Change { amount, fee } => {
if self.is_mine(drain_script.clone()) {
received += Amount::from_sat(*amount);
}
fee_amount += Amount::from_sat(*fee);

// create drain output
let drain_output = TxOut {
value: Amount::from_sat(*amount),
script_pubkey: drain_script,
};
// if there's change, create and add a change output
if let Change { amount, .. } = excess {
// create drain output
let drain_output = TxOut {
value: Amount::from_sat(*amount),
script_pubkey: drain_script,
};

// TODO: We should pay attention when adding a new output: this might increase
// the length of the "number of vouts" parameter by 2 bytes, potentially making
// our feerate too low
tx.output.push(drain_output);
}
};
// TODO: We should pay attention when adding a new output: this might increase
// the length of the "number of vouts" parameter by 2 bytes, potentially making
// our feerate too low
tx.output.push(drain_output);
}

// sort input/outputs according to the chosen algorithm
params.ordering.sort_tx_with_aux_rand(&mut tx, rng);

let psbt = self.complete_transaction(tx, coin_selection.selected, params)?;

// recording changes to the change keychain
if let (Excess::Change { .. }, Some((keychain, index))) = (excess, drain_index) {
if let (Change { .. }, Some((keychain, index))) = (excess, drain_index) {
let (_, index_changeset) = self
.indexed_graph
.index
Expand Down

0 comments on commit fefbebc

Please sign in to comment.