Skip to content

Commit ef1e19f

Browse files
committed
Add '--shrink' option to wallet bump_fee command
Replace `wallet bump_fee` command `--send_all` with new `--shrink ADDRESS` option to reduce the output amount for the specified address to increase RBF transaction fee.
1 parent a6c4859 commit ef1e19f

File tree

2 files changed

+74
-8
lines changed

2 files changed

+74
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313
- Add `verbose` option to `WalletOpts` to display PSBTs and transaction details also in JSON format
1414
- Require at most one blockchain client feature be enabled at a time
1515
- Change default esplora server URL to https://blockstream.info/testnet/api/ to match default testnet network
16+
- Replace `wallet bump_fee` command `--send_all` with new `--shrink` option
1617

1718
## [0.2.0]
1819

src/lib.rs

Lines changed: 73 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -639,9 +639,9 @@ pub enum OfflineWalletSubCommand {
639639
/// TXID of the transaction to update
640640
#[structopt(name = "TXID", short = "txid", long = "txid")]
641641
txid: String,
642-
/// Allows the wallet to reduce the amount of the only output in order to increase fees. This is generally the expected behavior for transactions originally created with `send_all`
643-
#[structopt(short = "all", long = "send_all")]
644-
send_all: bool,
642+
/// Allows the wallet to reduce the amount to the specified address in order to increase fees.
643+
#[structopt(name = "SHRINK_ADDRESS", short = "s", long = "shrink")]
644+
shrink_address: Option<Address>,
645645
/// Make a PSBT that can be signed by offline signers and hardware wallets. Forces the addition of `non_witness_utxo` and more details to let the signer identify the change output.
646646
#[structopt(long = "offline_signer")]
647647
offline_signer: bool,
@@ -847,7 +847,7 @@ where
847847
}
848848
BumpFee {
849849
txid,
850-
send_all,
850+
shrink_address,
851851
offline_signer,
852852
utxos,
853853
unspendable,
@@ -858,9 +858,9 @@ where
858858
let mut tx_builder = wallet.build_fee_bump(txid)?;
859859
tx_builder.fee_rate(FeeRate::from_sat_per_vb(fee_rate));
860860

861-
if send_all {
862-
// TODO: Find a way to get the recipient scriptpubkey to allow shrinking
863-
//tx_builder.allow_shrinking()
861+
if let Some(address) = shrink_address {
862+
let script_pubkey = address.script_pubkey();
863+
tx_builder.allow_shrinking(script_pubkey)?;
864864
}
865865

866866
if offline_signer {
@@ -1143,7 +1143,7 @@ mod test {
11431143
use crate::ElectrumOpts;
11441144
#[cfg(feature = "esplora")]
11451145
use crate::EsploraOpts;
1146-
use crate::OfflineWalletSubCommand::{CreateTx, GetNewAddress};
1146+
use crate::OfflineWalletSubCommand::{BumpFee, CreateTx, GetNewAddress};
11471147
#[cfg(any(feature = "electrum", feature = "esplora", feature = "compact_filters"))]
11481148
use crate::OnlineWalletSubCommand::{Broadcast, Sync};
11491149
#[cfg(any(feature = "compact_filters", feature = "electrum", feature = "esplora"))]
@@ -1513,6 +1513,71 @@ mod test {
15131513
assert_eq!(expected_cli_opts, cli_opts);
15141514
}
15151515

1516+
#[test]
1517+
fn test_parse_wallet_bump_fee() {
1518+
let cli_args = vec!["bdk-cli", "--network", "testnet", "wallet",
1519+
"--descriptor", "wpkh(tpubDEnoLuPdBep9bzw5LoGYpsxUQYheRQ9gcgrJhJEcdKFB9cWQRyYmkCyRoTqeD4tJYiVVgt6A3rN6rWn9RYhR9sBsGxji29LYWHuKKbdb1ev/0/*)",
1520+
"--change_descriptor", "wpkh(tpubDEnoLuPdBep9bzw5LoGYpsxUQYheRQ9gcgrJhJEcdKFB9cWQRyYmkCyRoTqeD4tJYiVVgt6A3rN6rWn9RYhR9sBsGxji29LYWHuKKbdb1ev/1/*)",
1521+
"bump_fee", "--fee_rate", "6.1",
1522+
"--txid","35aab0d0213f8996f9e236a28630319b93109754819e8abf48a0835708d33506",
1523+
"--shrink","tb1ql7w62elx9ucw4pj5lgw4l028hmuw80sndtntxt"];
1524+
1525+
let cli_opts = CliOpts::from_iter(&cli_args);
1526+
1527+
let expected_cli_opts = CliOpts {
1528+
network: Network::Testnet,
1529+
subcommand: CliSubCommand::Wallet {
1530+
wallet_opts: WalletOpts {
1531+
wallet: "main".to_string(),
1532+
verbose: false,
1533+
descriptor: "wpkh(tpubDEnoLuPdBep9bzw5LoGYpsxUQYheRQ9gcgrJhJEcdKFB9cWQRyYmkCyRoTqeD4tJYiVVgt6A3rN6rWn9RYhR9sBsGxji29LYWHuKKbdb1ev/0/*)".to_string(),
1534+
change_descriptor: Some("wpkh(tpubDEnoLuPdBep9bzw5LoGYpsxUQYheRQ9gcgrJhJEcdKFB9cWQRyYmkCyRoTqeD4tJYiVVgt6A3rN6rWn9RYhR9sBsGxji29LYWHuKKbdb1ev/1/*)".to_string()),
1535+
#[cfg(feature = "electrum")]
1536+
electrum_opts: ElectrumOpts {
1537+
timeout: None,
1538+
server: "ssl://electrum.blockstream.info:60002".to_string(),
1539+
stop_gap: 10,
1540+
},
1541+
#[cfg(feature = "esplora-ureq")]
1542+
esplora_opts: EsploraOpts {
1543+
server: "https://blockstream.info/testnet/api/".to_string(),
1544+
read_timeout: 5,
1545+
write_timeout: 5,
1546+
stop_gap: 10,
1547+
},
1548+
#[cfg(feature = "esplora-reqwest")]
1549+
esplora_opts: EsploraOpts {
1550+
server: "https://blockstream.info/testnet/api/".to_string(),
1551+
conc: 4,
1552+
stop_gap: 10,
1553+
},
1554+
#[cfg(feature = "compact_filters")]
1555+
compactfilter_opts: CompactFilterOpts{
1556+
address: vec!["127.0.0.1:18444".to_string()],
1557+
conn_count: 4,
1558+
skip_blocks: 0,
1559+
},
1560+
#[cfg(any(feature="compact_filters", feature="electrum", feature="esplora"))]
1561+
proxy_opts: ProxyOpts{
1562+
proxy: None,
1563+
proxy_auth: None,
1564+
retries: 5,
1565+
}
1566+
},
1567+
subcommand: WalletSubCommand::OfflineWalletSubCommand(BumpFee {
1568+
txid: "35aab0d0213f8996f9e236a28630319b93109754819e8abf48a0835708d33506".to_string(),
1569+
shrink_address: Some(Address::from_str("tb1ql7w62elx9ucw4pj5lgw4l028hmuw80sndtntxt").unwrap()),
1570+
offline_signer: false,
1571+
utxos: None,
1572+
unspendable: None,
1573+
fee_rate: 6.1
1574+
}),
1575+
},
1576+
};
1577+
1578+
assert_eq!(expected_cli_opts, cli_opts);
1579+
}
1580+
15161581
#[cfg(any(feature = "electrum", feature = "esplora", feature = "compact_filters"))]
15171582
#[test]
15181583
fn test_parse_wallet_broadcast() {

0 commit comments

Comments
 (0)