Skip to content

Commit cc90507

Browse files
committed
refactor(wallet): cleanup and remove unused code in create_tx
1 parent 606a2b0 commit cc90507

File tree

1 file changed

+13
-29
lines changed
  • crates/wallet/src/wallet

1 file changed

+13
-29
lines changed

crates/wallet/src/wallet/mod.rs

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,19 +1383,13 @@ impl Wallet {
13831383
}
13841384

13851385
let mut outgoing = Amount::ZERO;
1386-
let mut received = Amount::ZERO;
1387-
13881386
let recipients = params.recipients.iter().map(|(r, v)| (r, *v));
13891387

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

1395-
if self.is_mine(script_pubkey.clone()) {
1396-
received += value;
1397-
}
1398-
13991393
let new_out = TxOut {
14001394
script_pubkey: script_pubkey.clone(),
14011395
value,
@@ -1451,9 +1445,8 @@ impl Wallet {
14511445
rng,
14521446
)
14531447
.map_err(CreateTxError::CoinSelection)?;
1454-
fee_amount += coin_selection.fee_amount;
1455-
let excess = &coin_selection.excess;
14561448

1449+
let excess = &coin_selection.excess;
14571450
tx.input = coin_selection
14581451
.selected
14591452
.iter()
@@ -1492,28 +1485,19 @@ impl Wallet {
14921485
}
14931486
}
14941487

1495-
match excess {
1496-
Excess::NoChange {
1497-
remaining_amount, ..
1498-
} => fee_amount += *remaining_amount,
1499-
Excess::Change { amount, fee } => {
1500-
if self.is_mine(drain_script.clone()) {
1501-
received += *amount;
1502-
}
1503-
fee_amount += *fee;
1504-
1505-
// create drain output
1506-
let drain_output = TxOut {
1507-
value: *amount,
1508-
script_pubkey: drain_script,
1509-
};
1488+
// if there's change, create and add a change output
1489+
if let Excess::Change { amount, .. } = excess {
1490+
// create drain output
1491+
let drain_output = TxOut {
1492+
value: *amount,
1493+
script_pubkey: drain_script,
1494+
};
15101495

1511-
// TODO: We should pay attention when adding a new output: this might increase
1512-
// the length of the "number of vouts" parameter by 2 bytes, potentially making
1513-
// our feerate too low
1514-
tx.output.push(drain_output);
1515-
}
1516-
};
1496+
// TODO: We should pay attention when adding a new output: this might increase
1497+
// the length of the "number of vouts" parameter by 2 bytes, potentially making
1498+
// our feerate too low
1499+
tx.output.push(drain_output);
1500+
}
15171501

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

0 commit comments

Comments
 (0)