Skip to content

Commit 05c6f8e

Browse files
committed
f BDK: Account for TxBuilder::finish only returning Psbt
1 parent f8372a2 commit 05c6f8e

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

src/wallet/mod.rs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ use lightning_invoice::RawBolt11Invoice;
2626

2727
use bdk::blockchain::EsploraBlockchain;
2828
use bdk::wallet::AddressIndex;
29-
use bdk::{SignOptions, SyncOptions};
3029
use bdk_chain::ChainPosition;
30+
use bdk_wallet::SignOptions;
3131
use bdk_wallet::Wallet as BdkWallet;
3232

3333
use bitcoin::blockdata::constants::WITNESS_SCALE_FACTOR;
@@ -142,7 +142,7 @@ where
142142
) -> Result<Transaction, Error> {
143143
let fee_rate = self.fee_estimator.estimate_fee_rate(confirmation_target);
144144

145-
let locked_wallet = self.inner.lock().unwrap();
145+
let mut locked_wallet = self.inner.lock().unwrap();
146146
let mut tx_builder = locked_wallet.build_tx();
147147

148148
tx_builder
@@ -152,7 +152,7 @@ where
152152
.enable_rbf();
153153

154154
let mut psbt = match tx_builder.finish() {
155-
Ok((psbt, _)) => {
155+
Ok(psbt) => {
156156
log_trace!(self.logger, "Created funding PSBT: {:?}", psbt);
157157
psbt
158158
},
@@ -174,7 +174,12 @@ where
174174
},
175175
}
176176

177-
Ok(psbt.extract_tx())
177+
let tx = psbt.extract_tx().map_err(|e| {
178+
log_error!(self.logger, "Failed to extract transaction: {}", e);
179+
e
180+
})?;
181+
182+
Ok(tx)
178183
}
179184

180185
pub(crate) fn get_new_address(&self) -> Result<bitcoin::Address, Error> {
@@ -218,7 +223,7 @@ where
218223
let fee_rate = self.fee_estimator.estimate_fee_rate(confirmation_target);
219224

220225
let tx = {
221-
let locked_wallet = self.inner.lock().unwrap();
226+
let mut locked_wallet = self.inner.lock().unwrap();
222227
let mut tx_builder = locked_wallet.build_tx();
223228

224229
if let Some(amount_sats) = amount_msat_or_drain {
@@ -235,7 +240,7 @@ where
235240
}
236241

237242
let mut psbt = match tx_builder.finish() {
238-
Ok((psbt, _)) => {
243+
Ok(psbt) => {
239244
log_trace!(self.logger, "Created PSBT: {:?}", psbt);
240245
psbt
241246
},
@@ -256,7 +261,11 @@ where
256261
return Err(err.into());
257262
},
258263
}
259-
psbt.extract_tx()
264+
265+
psbt.extract_tx().map_err(|e| {
266+
log_error!(self.logger, "Failed to extract transaction: {}", e);
267+
e
268+
})?
260269
};
261270

262271
self.broadcaster.broadcast_transactions(&[&tx]);
@@ -440,7 +449,12 @@ where
440449
},
441450
}
442451

443-
Ok(psbt.extract_tx())
452+
let tx = psbt.extract_tx().map_err(|e| {
453+
log_error!(self.logger, "Failed to extract transaction: {}", e);
454+
()
455+
})?;
456+
457+
Ok(tx)
444458
}
445459
}
446460

0 commit comments

Comments
 (0)