diff --git a/crates/chain/src/chain_oracle.rs b/crates/chain/src/chain_oracle.rs index 2b4ad36f..58fbf6c1 100644 --- a/crates/chain/src/chain_oracle.rs +++ b/crates/chain/src/chain_oracle.rs @@ -10,12 +10,13 @@ pub trait ChainOracle { /// Error type. type Error: core::fmt::Debug; - /// Determines whether `block` of [`BlockId`] exists as an ancestor of `static_block`. + /// Determines whether `block` of [`BlockId`] exists as an ancestor of `chain_tip`. /// - /// If `None` is returned, it means the implementation cannot determine whether `block` exists. + /// If `None` is returned, it means the implementation cannot determine whether `block` exists + /// under `chain_tip`. fn is_block_in_chain( &self, block: BlockId, - static_block: BlockId, + chain_tip: BlockId, ) -> Result, Self::Error>; } diff --git a/crates/chain/src/local_chain.rs b/crates/chain/src/local_chain.rs index 74dbb5a8..a32a615c 100644 --- a/crates/chain/src/local_chain.rs +++ b/crates/chain/src/local_chain.rs @@ -64,8 +64,8 @@ impl LocalChain { } } - /// Get a reference to the inner map of block height to hash. - pub fn inner(&self) -> &BTreeMap { + /// Get a reference to a map of block height to hash. + pub fn blocks(&self) -> &BTreeMap { &self.blocks } @@ -76,11 +76,6 @@ impl LocalChain { .map(|(&height, &hash)| BlockId { height, hash }) } - /// Get a [`BlockHash`] at the given height. - pub fn get_blockhash(&self, height: u32) -> Option { - self.blocks.get(&height).cloned() - } - /// This is like the sparsechain's logic, expect we must guarantee that all invalidated heights /// are to be re-filled. pub fn determine_changeset(&self, update: &Self) -> Result { diff --git a/crates/chain/tests/test_indexed_tx_graph.rs b/crates/chain/tests/test_indexed_tx_graph.rs index f5011c3e..f32ffe4f 100644 --- a/crates/chain/tests/test_indexed_tx_graph.rs +++ b/crates/chain/tests/test_indexed_tx_graph.rs @@ -212,8 +212,9 @@ fn test_list_owned_txouts() { ( *tx, local_chain - .get_blockhash(height) - .map(|hash| BlockId { height, hash }) + .blocks() + .get(&height) + .map(|&hash| BlockId { height, hash }) .map(|anchor_block| ConfirmationHeightAnchor { anchor_block, confirmation_height: anchor_block.height, @@ -229,34 +230,22 @@ fn test_list_owned_txouts() { let fetch = |height: u32, graph: &IndexedTxGraph>| { + let chain_tip = local_chain + .blocks() + .get(&height) + .map(|&hash| BlockId { height, hash }) + .expect("block must exist"); let txouts = graph - .list_owned_txouts( - &local_chain, - local_chain - .get_blockhash(height) - .map(|hash| BlockId { height, hash }) - .unwrap(), - ) + .list_owned_txouts(&local_chain, chain_tip) .collect::>(); let utxos = graph - .list_owned_unspents( - &local_chain, - local_chain - .get_blockhash(height) - .map(|hash| BlockId { height, hash }) - .unwrap(), - ) + .list_owned_unspents(&local_chain, chain_tip) .collect::>(); - let balance = graph.balance( - &local_chain, - local_chain - .get_blockhash(height) - .map(|hash| BlockId { height, hash }) - .unwrap(), - |spk: &Script| trusted_spks.contains(spk), - ); + let balance = graph.balance(&local_chain, chain_tip, |spk: &Script| { + trusted_spks.contains(spk) + }); assert_eq!(txouts.len(), 5); assert_eq!(utxos.len(), 4); diff --git a/crates/chain/tests/test_tx_graph.rs b/crates/chain/tests/test_tx_graph.rs index 427de71e..2b845611 100644 --- a/crates/chain/tests/test_tx_graph.rs +++ b/crates/chain/tests/test_tx_graph.rs @@ -694,7 +694,6 @@ fn test_chain_spends() { .iter() .zip([&tx_0, &tx_1].into_iter()) .for_each(|(ht, tx)| { - // let block_id = local_chain.get_block(*ht).expect("block expected"); let _ = graph.insert_anchor( tx.txid(), ConfirmationHeightAnchor {