]> Untitled Git - bdk/commitdiff
refactor(wallet): cleanup and remove unused code in create_tx
authorSteve Myers <steve@notmandatory.org>
Mon, 9 Dec 2024 23:56:49 +0000 (17:56 -0600)
committervalued mammal <valuedmammal@protonmail.com>
Mon, 23 Dec 2024 15:09:37 +0000 (10:09 -0500)
crates/wallet/src/wallet/mod.rs

index 81c2f8282366aaee032868e0fe1ac20fc6f5ebc9..2e068a95f3a02492254c1525f6bbcbdf11cd90ba 100644 (file)
@@ -1399,8 +1399,6 @@ 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() {
@@ -1408,10 +1406,6 @@ impl Wallet {
                 return Err(CreateTxError::OutputBelowDustLimit(index));
             }
 
-            if self.is_mine(script_pubkey.clone()) {
-                received += value;
-            }
-
             let new_out = TxOut {
                 script_pubkey: script_pubkey.clone(),
                 value,
@@ -1467,9 +1461,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()
@@ -1508,28 +1501,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);