Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion examples/bitcoind_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use bdk_bitcoind_rpc::{
use bdk_wallet::rusqlite::Connection;
use bdk_wallet::{
bitcoin::{Block, Network},
chain::ChainPosition,
KeychainKind, Wallet,
};
use clap::{self, Parser};
Expand Down Expand Up @@ -144,7 +145,13 @@ fn main() -> anyhow::Result<()> {
args.start_height,
wallet
.transactions()
.filter(|tx| tx.chain_position.is_unconfirmed()),
.filter(|tx| {
matches!(
tx.details.chain_position,
Some(ChainPosition::Unconfirmed { .. })
)
})
.map(|tx| tx.details.tx),
);
spawn(move || -> Result<(), anyhow::Error> {
while let Some(emission) = emitter.next_block()? {
Expand Down
12 changes: 12 additions & 0 deletions src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,3 +361,15 @@ pub fn insert_seen_at(wallet: &mut Wallet, txid: Txid, seen_at: u64) {
})
.expect("failed to apply update");
}

/// Marks the given `txid` evicted from the mempool at `evicted_at`
pub fn insert_evicted_at(wallet: &mut Wallet, txid: Txid, evicted_at: u64) {
let mut tx_update = TxUpdate::default();
tx_update.evicted_ats = [(txid, evicted_at)].into();
wallet
.apply_update(Update {
tx_update,
..Default::default()
})
.expect("failed to apply update");
}
12 changes: 12 additions & 0 deletions src/wallet/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,3 +365,15 @@ impl fmt::Display for BuildFeeBumpError {
}

impl core::error::Error for BuildFeeBumpError {}

/// The transaction is unknown or not relevant to this wallet.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct UnknownTransaction;

impl fmt::Display for UnknownTransaction {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "transaction is unknown or not wallet-relevant")
}
}

impl core::error::Error for UnknownTransaction {}
18 changes: 12 additions & 6 deletions src/wallet/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
use alloc::string::String;
use alloc::string::ToString;
use alloc::vec::Vec;
use bdk_chain::{CanonicalizationParams, Indexer};
use bitcoin::bip32::{DerivationPath, Fingerprint, Xpub};
use core::fmt;
use core::str::FromStr;
Expand Down Expand Up @@ -210,12 +211,17 @@ impl FullyNodedExport {
Self::is_compatible_with_core(&descriptor)?;

let blockheight = if include_blockheight {
wallet.transactions().next().map_or(0, |canonical_tx| {
canonical_tx
.chain_position
.confirmation_height_upper_bound()
.unwrap_or(0)
})
wallet
.tx_graph()
.list_canonical_txs(
wallet.local_chain(),
wallet.local_chain().tip().block_id(),
CanonicalizationParams::default(),
)
.filter(|tx| wallet.spk_index().is_tx_relevant(&tx.tx_node.tx))
.filter_map(|tx| tx.chain_position.confirmation_height_upper_bound())
.min()
.unwrap_or(0)
} else {
0
};
Expand Down
Loading