From: Alekos Filini Date: Wed, 28 Oct 2020 09:37:47 +0000 (+0100) Subject: [wallet] Split `send_all` into `set_single_recipient` and `drain_wallet` X-Git-Tag: v0.1.0~36 X-Git-Url: http://internal-gitweb-vhost/script/%22https:/-sqlite-db-configuration/struct.EncoderStringWriter.html?a=commitdiff_plain;h=f587c3bee499baa32421a6c20e96cbddac8bc173;p=bdk-cli [wallet] Split `send_all` into `set_single_recipient` and `drain_wallet` 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. --- diff --git a/src/cli.rs b/src/cli.rs index 26556d4..513d25f 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -397,11 +397,16 @@ where .map(|s| parse_recipient(s)) .collect::, _>>() .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") {