[bdk_chain_redesign] chain_oracle::Cache

Introduce `chain_oracle::Cache` which is a cache for requests to the
chain oracle. `ChainOracle` has also been moved to the `chain_oracle`
module.

Introduce `get_tip_in_best_chain` method to the `ChainOracle` trait.
This allows for guaranteeing that chain state can be consistent across
operations with `IndexedTxGraph`.
This commit is contained in:
志宇
2023-04-05 10:57:26 +08:00
parent a7eaebbb77
commit 6e59dce10b
6 changed files with 186 additions and 36 deletions

View File

@@ -586,11 +586,12 @@ impl<A: Clone + Ord> TxGraph<A> {
impl<A: BlockAnchor> TxGraph<A> {
/// Get all heights that are relevant to the graph.
pub fn relevant_heights(&self) -> BTreeSet<u32> {
pub fn relevant_heights(&self) -> impl Iterator<Item = u32> + '_ {
let mut visited = HashSet::new();
self.anchors
.iter()
.map(|(a, _)| a.anchor_block().height)
.collect()
.filter(move |&h| visited.insert(h))
}
/// Determines whether a transaction of `txid` is in the best chain.