]> Untitled Git - bdk-cli/commitdiff
[wallet] Split `send_all` into `set_single_recipient` and `drain_wallet`
authorAlekos Filini <alekos.filini@gmail.com>
Wed, 28 Oct 2020 09:37:47 +0000 (10:37 +0100)
committerAlekos Filini <alekos.filini@gmail.com>
Thu, 5 Nov 2020 11:06:43 +0000 (12:06 +0100)
Previously `send_all` was particularly confusing, because when used on a
`create_tx` it implied two things:
- spend everything that's in the wallet (if no utxos are specified)
- don't create a change output

But when used on a `bump_fee` it only meant to not add a change output
and instead reduce the only existing output to increase the fee.

This has now been split into two separate options that should hopefully
make it more clear to use, as described in #142.

Additionally, `TxBuilder` now has a "context", that basically allows to
make some flags available only when they are actually meaningful, either
for `create_tx` or `bump_fee`.

Closes #142.

src/cli.rs

index 26556d4b74ba2f8a61ded9623b6026543118e284..513d25f2a60bc1625206822a60d19b6d1b6a0c4a 100644 (file)
@@ -397,11 +397,16 @@ where
             .map(|s| parse_recipient(s))
             .collect::<Result<Vec<_>, _>>()
             .map_err(Error::Generic)?;
-        let mut tx_builder = TxBuilder::with_recipients(recipients);
+        let mut tx_builder = TxBuilder::new();
 
         if sub_matches.is_present("send_all") {
-            tx_builder = tx_builder.send_all();
+            tx_builder = tx_builder
+                .drain_wallet()
+                .set_single_recipient(recipients[0].0.clone());
+        } else {
+            tx_builder = tx_builder.set_recipients(recipients);
         }
+
         if sub_matches.is_present("enable_rbf") {
             tx_builder = tx_builder.enable_rbf();
         }
@@ -445,7 +450,7 @@ where
         let mut tx_builder = TxBuilder::new().fee_rate(FeeRate::from_sat_per_vb(fee_rate));
 
         if sub_matches.is_present("send_all") {
-            tx_builder = tx_builder.send_all();
+            tx_builder = tx_builder.maintain_single_recipient();
         }
 
         if let Some(utxos) = sub_matches.values_of("utxos") {