/// 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<Option<bool>, Self::Error>;
}
}
}
- /// Get a reference to the inner map of block height to hash.
- pub fn inner(&self) -> &BTreeMap<u32, BlockHash> {
+ /// Get a reference to a map of block height to hash.
+ pub fn blocks(&self) -> &BTreeMap<u32, BlockHash> {
&self.blocks
}
.map(|(&height, &hash)| BlockId { height, hash })
}
- /// Get a [`BlockHash`] at the given height.
- pub fn get_blockhash(&self, height: u32) -> Option<BlockHash> {
- 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<ChangeSet, UpdateNotConnectedError> {
(
*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,
let fetch =
|height: u32,
graph: &IndexedTxGraph<ConfirmationHeightAnchor, KeychainTxOutIndex<String>>| {
+ 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::<Vec<_>>();
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::<Vec<_>>();
- 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);