Skip to content

Commit 4f10cde

Browse files
committed
chore(chain,example)!: remove ChainOracle, update docs
1 parent a3c73e4 commit 4f10cde

8 files changed

Lines changed: 39 additions & 64 deletions

File tree

crates/chain/src/canonical.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,8 @@ impl<A: Anchor> CanonicalView<A> {
490490
}
491491

492492
impl<A: Anchor> CanonicalTxs<A> {
493-
/// Creates a [`CanonicalViewTask`] that resolves [`CanonicalReason`]s into [`ChainPosition`]s.
493+
/// Creates a [`CanonicalViewTask`] that resolves [`CanonicalReason`](crate::CanonicalReason)s
494+
/// into [`ChainPosition`]s.
494495
///
495496
/// This is the second phase of the canonicalization pipeline. The resulting task
496497
/// queries the chain to verify anchors for transitively anchored transactions and

crates/chain/src/canonical_task.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ pub struct CanonicalParams {
5353
///
5454
/// This task implements the first phase of canonicalization: it walks the transaction
5555
/// graph and determines which transactions are canonical (non-conflicting) and why
56-
/// (via [`CanonicalReason`]). The output is a [`CanonicalTxs`] which can then be
57-
/// further processed by [`CanonicalViewTask`] to resolve reasons into
58-
/// [`ChainPosition`]s.
56+
/// (via [`CanonicalReason`](crate::CanonicalReason)). The output is a [`CanonicalTxs`] which can
57+
/// then be further processed by [`CanonicalViewTask`](crate::CanonicalViewTask) to resolve reasons
58+
/// into [`ChainPosition`](crate::ChainPosition)s.
5959
pub struct CanonicalTask<'g, A> {
6060
tx_graph: &'g TxGraph<A>,
6161
chain_tip: BlockId,

crates/chain/src/chain_oracle.rs

Lines changed: 0 additions & 25 deletions
This file was deleted.

crates/chain/src/indexed_tx_graph.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,8 @@ impl<A, X> IndexedTxGraph<A, X>
436436
where
437437
A: Anchor,
438438
{
439-
/// Creates a [`CanonicalTask`] to determine the [`CanonicalView`] of transactions.
439+
/// Creates a [`CanonicalTask`] to determine the [`CanonicalView`](crate::CanonicalView) of
440+
/// transactions.
440441
///
441442
/// This method delegates to the underlying [`TxGraph`] to create a [`CanonicalTask`]
442443
/// that can be used to determine which transactions are canonical based on the provided

crates/chain/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ mod tx_data_traits;
4242
pub use tx_data_traits::*;
4343
pub mod tx_graph;
4444
pub use tx_graph::TxGraph;
45-
mod chain_oracle;
46-
pub use chain_oracle::*;
4745
mod canonical_task;
4846
pub use canonical_task::*;
4947
mod canonical;

crates/chain/src/local_chain.rs

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
//! The [`LocalChain`] is a local implementation of [`ChainOracle`].
1+
//! The [`LocalChain`] is a local chain of checkpoints.
22
3-
use core::convert::Infallible;
43
use core::fmt;
54
use core::ops::RangeBounds;
65

76
use crate::collections::BTreeMap;
8-
use crate::{Anchor, BlockId, CanonicalParams, CanonicalView, ChainOracle, Merge, TxGraph};
9-
use bdk_core::{ChainQuery, CheckPointEntry, ToBlockHash};
10-
pub use bdk_core::{CheckPoint, CheckPointIter};
7+
use crate::{Anchor, BlockId, CanonicalParams, CanonicalView, Merge, TxGraph};
8+
use bdk_core::{ChainQuery, ToBlockHash};
9+
pub use bdk_core::{CheckPoint, CheckPointEntry, CheckPointIter};
1110
use bitcoin::block::Header;
1211
use bitcoin::BlockHash;
1312

@@ -61,7 +60,7 @@ where
6160
Ok(init_cp)
6261
}
6362

64-
/// This is a local implementation of [`ChainOracle`].
63+
/// A local chain of checkpoints.
6564
#[derive(Debug, Clone)]
6665
pub struct LocalChain<D = BlockHash> {
6766
tip: CheckPoint<D>,
@@ -73,33 +72,38 @@ impl<D> PartialEq for LocalChain<D> {
7372
}
7473
}
7574

76-
impl<D> ChainOracle for LocalChain<D> {
77-
type Error = Infallible;
78-
79-
fn is_block_in_chain(
80-
&self,
81-
block: BlockId,
82-
chain_tip: BlockId,
83-
) -> Result<Option<bool>, Self::Error> {
75+
// Methods for `LocalChain<BlockHash>`
76+
impl LocalChain<BlockHash> {
77+
/// Check if a block is in the chain.
78+
///
79+
/// # Arguments
80+
/// * `block` - The block to check
81+
/// * `chain_tip` - The chain tip to check against
82+
///
83+
/// # Returns
84+
/// * `Some(true)` if the block is in the chain
85+
/// * `Some(false)` if the block is not in the chain
86+
/// * `None` if it cannot be determined
87+
pub fn is_block_in_chain(&self, block: BlockId, chain_tip: BlockId) -> Option<bool> {
8488
let chain_tip_cp = match self.tip.get(chain_tip.height) {
8589
// we can only determine whether `block` is in chain of `chain_tip` if `chain_tip` can
8690
// be identified in chain
8791
Some(cp) if cp.hash() == chain_tip.hash => cp,
88-
_ => return Ok(None),
92+
_ => return None,
8993
};
90-
match chain_tip_cp.get(block.height) {
91-
Some(cp) => Ok(Some(cp.hash() == block.hash)),
92-
None => Ok(None),
93-
}
94+
chain_tip_cp
95+
.get(block.height)
96+
.map(|cp| cp.hash() == block.hash)
9497
}
9598

96-
fn get_chain_tip(&self) -> Result<BlockId, Self::Error> {
97-
Ok(self.tip.block_id())
99+
/// Get the chain tip.
100+
///
101+
/// # Returns
102+
/// The [`BlockId`] of the chain tip.
103+
pub fn chain_tip(&self) -> BlockId {
104+
self.tip.block_id()
98105
}
99-
}
100106

101-
// Methods for `LocalChain<BlockHash>`
102-
impl LocalChain<BlockHash> {
103107
/// Canonicalize a transaction graph using this chain.
104108
///
105109
/// This method processes any type implementing [`ChainQuery`], handling all its requests
@@ -125,11 +129,7 @@ impl LocalChain<BlockHash> {
125129
while let Some(request) = task.next_query() {
126130
let mut best_block_id = None;
127131
for block_id in &request {
128-
if self
129-
.is_block_in_chain(*block_id, chain_tip)
130-
.expect("infallible")
131-
== Some(true)
132-
{
132+
if self.is_block_in_chain(*block_id, chain_tip) == Some(true) {
133133
best_block_id = Some(*block_id);
134134
break;
135135
}

crates/chain/tests/test_indexed_tx_graph.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ fn insert_relevant_txs() {
303303
}
304304

305305
/// Ensure consistency IndexedTxGraph list_* and balance methods. These methods lists
306-
/// relevant txouts and utxos from the information fetched from a ChainOracle (here a LocalChain).
306+
/// relevant txouts and utxos from the information fetched from a LocalChain.
307307
///
308308
/// Test Setup:
309309
///

crates/chain/tests/test_tx_graph.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use bdk_chain::{
77
local_chain::LocalChain,
88
tx_graph::{self, CalculateFeeError},
99
tx_graph::{ChangeSet, TxGraph},
10-
Anchor, ChainOracle, ChainPosition, Merge,
10+
Anchor, ChainPosition, Merge,
1111
};
1212
use bdk_testenv::{block_id, hash, utils::new_tx};
1313
use bitcoin::hex::FromHex;
@@ -758,7 +758,7 @@ fn test_walk_ancestors() {
758758
let tx_node = graph.get_tx_node(tx.compute_txid())?;
759759
for block in tx_node.anchors {
760760
match local_chain.is_block_in_chain(block.anchor_block(), tip.block_id()) {
761-
Ok(Some(true)) => return None,
761+
Some(true) => return None,
762762
_ => continue,
763763
}
764764
}

0 commit comments

Comments
 (0)