Skip to content

Commit bc1de69

Browse files
committed
feat(wallet): WalletTx now supports non-canonical txs
1 parent 4b612f5 commit bc1de69

7 files changed

Lines changed: 263 additions & 69 deletions

File tree

examples/bitcoind_rpc.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ use bdk_bitcoind_rpc::{
55
use bdk_wallet::rusqlite::Connection;
66
use bdk_wallet::{
77
bitcoin::{Block, Network},
8-
KeychainKind, Wallet,
8+
chain::ChainPosition,
9+
KeychainKind, Wallet, WalletTxStatus,
910
};
1011
use clap::{self, Parser};
1112
use std::{
@@ -142,9 +143,12 @@ fn main() -> anyhow::Result<()> {
142143
rpc_client,
143144
wallet_tip,
144145
args.start_height,
145-
wallet
146-
.transactions()
147-
.filter(|tx| tx.chain_position.is_unconfirmed()),
146+
wallet.transactions().filter(|tx| {
147+
matches!(
148+
tx.status,
149+
WalletTxStatus::Canonical(ChainPosition::Unconfirmed { .. })
150+
)
151+
}),
148152
);
149153
spawn(move || -> Result<(), anyhow::Error> {
150154
while let Some(emission) = emitter.next_block()? {

src/wallet/export.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@
137137
use alloc::string::String;
138138
use alloc::string::ToString;
139139
use alloc::vec::Vec;
140+
use bdk_chain::{CanonicalizationParams, Indexer};
140141
use bitcoin::bip32::{DerivationPath, Fingerprint, Xpub};
141142
use core::fmt;
142143
use core::str::FromStr;
@@ -210,12 +211,17 @@ impl FullyNodedExport {
210211
Self::is_compatible_with_core(&descriptor)?;
211212

212213
let blockheight = if include_blockheight {
213-
wallet.transactions().next().map_or(0, |canonical_tx| {
214-
canonical_tx
215-
.chain_position
216-
.confirmation_height_upper_bound()
217-
.unwrap_or(0)
218-
})
214+
wallet
215+
.tx_graph()
216+
.list_canonical_txs(
217+
wallet.local_chain(),
218+
wallet.local_chain().tip().block_id(),
219+
CanonicalizationParams::default(),
220+
)
221+
.filter(|tx| wallet.spk_index().is_tx_relevant(&tx.tx_node.tx))
222+
.filter_map(|tx| tx.chain_position.confirmation_height_upper_bound())
223+
.min()
224+
.unwrap_or(0)
219225
} else {
220226
0
221227
};

0 commit comments

Comments
 (0)