Skip to content

Commit ae9173c

Browse files
committed
Use SpacesAwareCoinSelection for bumpfee
1 parent 024d364 commit ae9173c

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

node/src/wallets.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use wallet::{
3333
},
3434
DoubleUtxo, SpacesWallet, WalletInfo,
3535
};
36-
36+
use wallet::bdk_wallet::wallet::tx_builder::TxOrdering;
3737
use crate::{
3838
config::ExtendedNetwork,
3939
node::BlockSource,
@@ -177,12 +177,20 @@ impl RpcWallet {
177177

178178
fn handle_fee_bump(
179179
source: &BitcoinBlockSource,
180+
state: &mut LiveSnapshot,
180181
wallet: &mut SpacesWallet,
181182
txid: Txid,
182183
fee_rate: FeeRate,
183184
) -> anyhow::Result<Vec<TxResponse>> {
184-
let mut builder = wallet.spaces.build_fee_bump(txid)?;
185-
builder.fee_rate(fee_rate);
185+
let coin_selection = Self::get_spaces_coin_selection(wallet, state)?;
186+
let mut builder = wallet.spaces
187+
.build_fee_bump(txid)?
188+
.coin_selection(coin_selection);
189+
190+
builder
191+
.enable_rbf()
192+
.ordering(TxOrdering::Untouched)
193+
.fee_rate(fee_rate);
186194

187195
let psbt = builder.finish()?;
188196
let tx = wallet.sign(psbt, None)?;
@@ -200,17 +208,21 @@ impl RpcWallet {
200208

201209
fn handle_force_spend_output(
202210
source: &BitcoinBlockSource,
211+
state: &mut LiveSnapshot,
203212
wallet: &mut SpacesWallet,
204213
output: OutPoint,
205214
fee_rate: FeeRate,
206215
) -> anyhow::Result<TxResponse> {
216+
let coin_selection = Self::get_spaces_coin_selection(wallet, state)?;
207217
let addre = wallet.spaces.next_unused_address(KeychainKind::External);
208218
let mut builder = wallet
209219
.spaces
210220
.build_tx()
211-
.coin_selection(SpacesAwareCoinSelection::new(vec![]));
221+
.coin_selection(coin_selection);
212222

223+
builder.ordering(TxOrdering::Untouched);
213224
builder.fee_rate(fee_rate);
225+
builder.enable_rbf();
214226
builder.add_utxo(output)?;
215227
builder.add_recipient(addre.script_pubkey(), Amount::from_sat(5000));
216228

@@ -247,15 +259,15 @@ impl RpcWallet {
247259
fee_rate,
248260
resp,
249261
} => {
250-
let result = Self::handle_fee_bump(source, wallet, txid, fee_rate);
262+
let result = Self::handle_fee_bump(source, &mut state, wallet, txid, fee_rate);
251263
_ = resp.send(result);
252264
}
253265
WalletCommand::ForceSpendOutput {
254266
outpoint,
255267
fee_rate,
256268
resp,
257269
} => {
258-
let result = Self::handle_force_spend_output(source, wallet, outpoint, fee_rate);
270+
let result = Self::handle_force_spend_output(source, &mut state, wallet, outpoint, fee_rate);
259271
_ = resp.send(result);
260272
}
261273
WalletCommand::GetNewAddress { kind, resp } => {

wallet/src/builder.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,9 @@ impl Builder {
370370
}
371371

372372
let commit_psbt = {
373-
let mut builder = w.spaces.build_tx().coin_selection(coin_selection);
373+
let mut builder = w.spaces
374+
.build_tx()
375+
.coin_selection(coin_selection);
374376
builder.nlocktime(magic_lock_time(median_time));
375377

376378
builder.ordering(TxOrdering::Untouched);
@@ -799,7 +801,9 @@ impl Builder {
799801
) -> anyhow::Result<Transaction> {
800802
let (offer, placeholder) = w.new_bid_psbt(bid)?;
801803
let bid_psbt = {
802-
let mut builder = w.spaces.build_tx().coin_selection(coin_selection);
804+
let mut builder = w.spaces
805+
.build_tx()
806+
.coin_selection(coin_selection);
803807
builder
804808
.ordering(TxOrdering::Untouched)
805809
.nlocktime(LockTime::Blocks(Height::ZERO))
@@ -830,7 +834,9 @@ impl Builder {
830834
let (offer, placeholder) = w.new_bid_psbt(params.amount)?;
831835
let mut extra_prevouts = BTreeMap::new();
832836
let open_psbt = {
833-
let mut builder = w.spaces.build_tx().coin_selection(coin_selection);
837+
let mut builder = w.spaces
838+
.build_tx()
839+
.coin_selection(coin_selection);
834840
builder.ordering(TxOrdering::Untouched).add_bid(
835841
None,
836842
offer,
@@ -865,7 +871,9 @@ impl Builder {
865871
.spaces
866872
.next_unused_address(KeychainKind::Internal)
867873
.script_pubkey();
868-
let mut builder = w.spaces.build_tx().coin_selection(coin_selection);
874+
let mut builder = w.spaces
875+
.build_tx()
876+
.coin_selection(coin_selection);
869877

870878
builder
871879
.ordering(TxOrdering::Untouched)

0 commit comments

Comments
 (0)