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 12, 2024
1 parent 606a2b0 commit cc90507
Showing 1 changed file with 13 additions and 29 deletions.
42 changes: 13 additions & 29 deletions crates/wallet/src/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1383,19 +1383,13 @@ impl Wallet {
}

let mut outgoing = Amount::ZERO;
let mut received = Amount::ZERO;

let recipients = params.recipients.iter().map(|(r, v)| (r, *v));

for (index, (script_pubkey, value)) in recipients.enumerate() {
if !params.allow_dust && value.is_dust(script_pubkey) && !script_pubkey.is_op_return() {
return Err(CreateTxError::OutputBelowDustLimit(index));
}

if self.is_mine(script_pubkey.clone()) {
received += value;
}

let new_out = TxOut {
script_pubkey: script_pubkey.clone(),
value,
Expand Down Expand Up @@ -1451,9 +1445,8 @@ impl Wallet {
rng,
)
.map_err(CreateTxError::CoinSelection)?;
fee_amount += coin_selection.fee_amount;
let excess = &coin_selection.excess;

let excess = &coin_selection.excess;
tx.input = coin_selection
.selected
.iter()
Expand Down Expand Up @@ -1492,28 +1485,19 @@ impl Wallet {
}
}

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

// create drain output
let drain_output = TxOut {
value: *amount,
script_pubkey: drain_script,
};
// if there's change, create and add a change output
if let Excess::Change { amount, .. } = excess {
// create drain output
let drain_output = TxOut {
value: *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);
Expand Down

0 comments on commit cc90507

Please sign in to comment.