feat(chain)!: Implement ConfirmationBlockTime

Both `bdk_electrum` and `bdk_esplora` now report the exact block
that the transaction is in, which removes the need for having the
old `ConfirmationTimeHeightAnchor` and `ConfirmationHeightAnchor`.
This PR introduces a new, simpler anchor type that can be modified
to support additional data in the future.
This commit is contained in:
Wei Chen
2024-07-01 13:40:26 +08:00
parent e761adf481
commit 1a62488abf
17 changed files with 158 additions and 235 deletions

View File

@@ -10,7 +10,7 @@ use bdk_chain::{
indexer::keychain_txout,
local_chain::{self, LocalChain},
spk_client::{FullScanRequest, SyncRequest},
ConfirmationHeightAnchor, Merge,
ConfirmationBlockTime, Merge,
};
use bdk_electrum::{
electrum_client::{self, Client, ElectrumApi},
@@ -100,7 +100,7 @@ pub struct ScanOptions {
type ChangeSet = (
local_chain::ChangeSet,
indexed_tx_graph::ChangeSet<ConfirmationHeightAnchor, keychain_txout::ChangeSet<Keychain>>,
indexed_tx_graph::ChangeSet<ConfirmationBlockTime, keychain_txout::ChangeSet<Keychain>>,
);
fn main() -> anyhow::Result<()> {
@@ -338,17 +338,12 @@ fn main() -> anyhow::Result<()> {
let chain_changeset = chain.apply_update(chain_update)?;
let mut indexed_tx_graph_changeset =
indexed_tx_graph::ChangeSet::<ConfirmationHeightAnchor, _>::default();
indexed_tx_graph::ChangeSet::<ConfirmationBlockTime, _>::default();
if let Some(keychain_update) = keychain_update {
let keychain_changeset = graph.index.reveal_to_target_multi(&keychain_update);
indexed_tx_graph_changeset.merge(keychain_changeset.into());
}
indexed_tx_graph_changeset.merge(graph.apply_update(graph_update.map_anchors(|a| {
ConfirmationHeightAnchor {
confirmation_height: a.confirmation_height,
anchor_block: a.anchor_block,
}
})));
indexed_tx_graph_changeset.merge(graph.apply_update(graph_update));
(chain_changeset, indexed_tx_graph_changeset)
};