From fefbebcc8171c35e025899c58ba1e8ebdae32a16 Mon Sep 17 00:00:00 2001 From: Steve Myers Date: Mon, 9 Dec 2024 17:56:49 -0600 Subject: [PATCH] refactor(wallet): cleanup and remove unused code in create_tx --- crates/wallet/src/wallet/mod.rs | 40 +++++++++++++-------------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/crates/wallet/src/wallet/mod.rs b/crates/wallet/src/wallet/mod.rs index e2e905020..ae74872ed 100644 --- a/crates/wallet/src/wallet/mod.rs +++ b/crates/wallet/src/wallet/mod.rs @@ -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}, @@ -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() @@ -1500,28 +1499,19 @@ 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); @@ -1529,7 +1519,7 @@ impl Wallet { 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