Skip to content

Commit e7daa83

Browse files
committed
f BDK: Account for changes in list_transactions/list_unspent
1 parent 270b9c6 commit e7daa83

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

src/wallet/mod.rs

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use lightning_invoice::RawBolt11Invoice;
2727
use bdk::blockchain::EsploraBlockchain;
2828
use bdk::wallet::AddressIndex;
2929
use bdk::{Balance, SignOptions, SyncOptions};
30+
use bdk_chain::ChainPosition;
3031
use bdk_wallet::Wallet as BdkWallet;
3132

3233
use bitcoin::blockdata::constants::WITNESS_SCALE_FACTOR;
@@ -373,25 +374,13 @@ where
373374
fn list_confirmed_utxos(&self) -> Result<Vec<Utxo>, ()> {
374375
let locked_wallet = self.inner.lock().unwrap();
375376
let mut utxos = Vec::new();
376-
let confirmed_txs: Vec<bdk::TransactionDetails> = locked_wallet
377-
.list_transactions(false)
378-
.map_err(|e| {
379-
log_error!(self.logger, "Failed to retrieve transactions from wallet: {}", e);
380-
})?
381-
.into_iter()
382-
.filter(|t| t.confirmation_time.is_some())
377+
let confirmed_txs: Vec<Txid> = locked_wallet
378+
.transactions()
379+
.filter(|t| matches!(t.chain_position, ChainPosition::Confirmed(_)))
380+
.map(|t| t.tx_node.txid)
383381
.collect();
384-
let unspent_confirmed_utxos = locked_wallet
385-
.list_unspent()
386-
.map_err(|e| {
387-
log_error!(
388-
self.logger,
389-
"Failed to retrieve unspent transactions from wallet: {}",
390-
e
391-
);
392-
})?
393-
.into_iter()
394-
.filter(|u| confirmed_txs.iter().find(|t| t.txid == u.outpoint.txid).is_some());
382+
let unspent_confirmed_utxos =
383+
locked_wallet.list_unspent().filter(|u| confirmed_txs.contains(&u.outpoint.txid));
395384

396385
for u in unspent_confirmed_utxos {
397386
let script_pubkey = u.txout.script_pubkey;

0 commit comments

Comments
 (0)