@@ -70,7 +70,7 @@ use crate::types::*;
7070use crate :: wallet:: {
7171 coin_selection:: {
7272 DefaultCoinSelectionAlgorithm ,
73- Excess :: { self , Change , NoChange } ,
73+ Excess :: { Change , NoChange } ,
7474 InsufficientFunds ,
7575 } ,
7676 error:: { BuildFeeBumpError , CreateTxError , MiniscriptPsbtError } ,
@@ -1393,19 +1393,13 @@ impl Wallet {
13931393 }
13941394
13951395 let mut outgoing = Amount :: ZERO ;
1396- let mut received = Amount :: ZERO ;
1397-
13981396 let recipients = params. recipients . iter ( ) . map ( |( r, v) | ( r, * v) ) ;
13991397
14001398 for ( index, ( script_pubkey, value) ) in recipients. enumerate ( ) {
14011399 if !params. allow_dust && value. is_dust ( script_pubkey) && !script_pubkey. is_op_return ( ) {
14021400 return Err ( CreateTxError :: OutputBelowDustLimit ( index) ) ;
14031401 }
14041402
1405- if self . is_mine ( script_pubkey. clone ( ) ) {
1406- received += value;
1407- }
1408-
14091403 let new_out = TxOut {
14101404 script_pubkey : script_pubkey. clone ( ) ,
14111405 value,
@@ -1461,9 +1455,8 @@ impl Wallet {
14611455 rng,
14621456 )
14631457 . map_err ( CreateTxError :: CoinSelection ) ?;
1464- fee_amount += Amount :: from_sat ( coin_selection. fee_amount ) ;
1465- let excess = & coin_selection. excess ;
14661458
1459+ let excess = & coin_selection. excess ;
14671460 tx. input = coin_selection
14681461 . selected
14691462 . iter ( )
@@ -1500,36 +1493,27 @@ impl Wallet {
15001493 }
15011494 }
15021495
1503- match excess {
1504- NoChange {
1505- remaining_amount, ..
1506- } => fee_amount += Amount :: from_sat ( * remaining_amount) ,
1507- Change { amount, fee } => {
1508- if self . is_mine ( drain_script. clone ( ) ) {
1509- received += Amount :: from_sat ( * amount) ;
1510- }
1511- fee_amount += Amount :: from_sat ( * fee) ;
1512-
1513- // create drain output
1514- let drain_output = TxOut {
1515- value : Amount :: from_sat ( * amount) ,
1516- script_pubkey : drain_script,
1517- } ;
1496+ // if there's change, create and add a change output
1497+ if let Change { amount, .. } = excess {
1498+ // create drain output
1499+ let drain_output = TxOut {
1500+ value : Amount :: from_sat ( * amount) ,
1501+ script_pubkey : drain_script,
1502+ } ;
15181503
1519- // TODO: We should pay attention when adding a new output: this might increase
1520- // the length of the "number of vouts" parameter by 2 bytes, potentially making
1521- // our feerate too low
1522- tx. output . push ( drain_output) ;
1523- }
1524- } ;
1504+ // TODO: We should pay attention when adding a new output: this might increase
1505+ // the length of the "number of vouts" parameter by 2 bytes, potentially making
1506+ // our feerate too low
1507+ tx. output . push ( drain_output) ;
1508+ }
15251509
15261510 // sort input/outputs according to the chosen algorithm
15271511 params. ordering . sort_tx_with_aux_rand ( & mut tx, rng) ;
15281512
15291513 let psbt = self . complete_transaction ( tx, coin_selection. selected , params) ?;
15301514
15311515 // recording changes to the change keychain
1532- if let ( Excess :: Change { .. } , Some ( ( keychain, index) ) ) = ( excess, drain_index) {
1516+ if let ( Change { .. } , Some ( ( keychain, index) ) ) = ( excess, drain_index) {
15331517 let ( _, index_changeset) = self
15341518 . indexed_graph
15351519 . index
0 commit comments