}
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() {
return Err(CreateTxError::OutputBelowDustLimit(index));
}
- if self.is_mine(script_pubkey.clone()) {
- received += value;
- }
-
let new_out = TxOut {
script_pubkey: script_pubkey.clone(),
value,
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()
}
}
- 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);