Skip to content

Commit 529e8b5

Browse files
feat: add apply_block_relevant/batch_insert_relevant_uncofirmed to wallet
1 parent 9b4107a commit 529e8b5

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

crates/bdk/src/wallet/mod.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use bitcoin::secp256k1::Secp256k1;
3434
use bitcoin::sighash::{EcdsaSighashType, TapSighashType};
3535
use bitcoin::{
3636
absolute, Address, Network, OutPoint, Script, ScriptBuf, Sequence, Transaction, TxOut, Txid,
37-
Weight, Witness,
37+
Weight, Witness, Block,
3838
};
3939
use core::fmt;
4040
use core::ops::Deref;
@@ -1949,6 +1949,15 @@ impl<D> Wallet<D> {
19491949
Ok(())
19501950
}
19511951

1952+
/// Stages wallet changes in memory for later commit.
1953+
///
1954+
/// To commit changes to the persistence backend, call [`commit`].
1955+
///
1956+
/// [`commit`]: Self::commit
1957+
pub fn stage(&mut self, changeset: ChangeSet) where D: PersistBackend<ChangeSet> {
1958+
self.persist.stage(changeset);
1959+
}
1960+
19521961
/// Commits all currently [`staged`] changed to the persistence backend returning and error when
19531962
/// this fails.
19541963
///
@@ -1995,6 +2004,27 @@ impl<D> Wallet<D> {
19952004
assert_ne!(lookahead, 0, "lookahead must be greater than 0");
19962005
self.indexed_graph.index.set_lookahead_for_all(lookahead);
19972006
}
2007+
2008+
/// Insert all the block's relevant transactions into the IndexedTxGraph.
2009+
pub fn apply_block_relevant(&mut self, block: Block, height: u32) -> Result<ChangeSet, CannotConnectError> {
2010+
let chain_update = CheckPoint::from_header(&block.header, height).into_update(false);
2011+
let mut changeset = ChangeSet::from(self.chain.apply_update(chain_update)?);
2012+
changeset.append(ChangeSet::from(
2013+
self.indexed_graph.apply_block_relevant(block, height),
2014+
));
2015+
Ok(changeset)
2016+
}
2017+
2018+
/// Batch insert unconfirmed transactions into the IndexedTxGraph.
2019+
/// Filtering out those that are not relevant.
2020+
///
2021+
/// Read more here: [`self.indexed_graph.batch_insert_relevant_unconfirmed()`]
2022+
pub fn batch_insert_relevant_unconfirmed<'t>(
2023+
&mut self,
2024+
unconfirmed_txs: impl IntoIterator<Item = (&'t Transaction, u64)>,
2025+
) -> indexed_tx_graph::ChangeSet<ConfirmationTimeAnchor, keychain::ChangeSet<KeychainKind>> {
2026+
self.indexed_graph.batch_insert_relevant_unconfirmed(unconfirmed_txs)
2027+
}
19982028
}
19992029

20002030
impl<D> AsRef<bdk_chain::tx_graph::TxGraph<ConfirmationTimeAnchor>> for Wallet<D> {

0 commit comments

Comments
 (0)