diff --git a/crates/chain/src/local_chain.rs b/crates/chain/src/local_chain.rs index 4993b5233d..d6d841c572 100644 --- a/crates/chain/src/local_chain.rs +++ b/crates/chain/src/local_chain.rs @@ -7,7 +7,6 @@ use core::u32; use crate::collections::BTreeMap; use crate::{BlockId, ChainOracle}; use alloc::sync::Arc; -use alloc::vec::Vec; use bitcoin::block::Header; use bitcoin::BlockHash; @@ -37,6 +36,14 @@ struct CPInner { prev: Option>, } +impl PartialEq for CheckPoint { + fn eq(&self, other: &Self) -> bool { + let self_cps = self.iter().map(|cp| cp.block_id()); + let other_cps = other.iter().map(|cp| cp.block_id()); + self_cps.eq(other_cps) + } +} + impl CheckPoint { /// Construct a new base block at the front of a linked list. pub fn new(block: BlockId) -> Self { @@ -224,7 +231,7 @@ impl IntoIterator for CheckPoint { /// Script-pubkey based syncing mechanisms may not introduce transactions in a chronological order /// so some updates require introducing older blocks (to anchor older transactions). For /// script-pubkey based syncing, `introduce_older_blocks` would typically be `true`. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq)] pub struct Update { /// The update chain's new tip. pub tip: CheckPoint, @@ -238,23 +245,11 @@ pub struct Update { } /// This is a local implementation of [`ChainOracle`]. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq)] pub struct LocalChain { tip: CheckPoint, } -impl PartialEq for LocalChain { - fn eq(&self, other: &Self) -> bool { - self.iter_checkpoints() - .map(|cp| cp.block_id()) - .collect::>() - == other - .iter_checkpoints() - .map(|cp| cp.block_id()) - .collect::>() - } -} - // TODO: Figure out whether we can get rid of this impl From for BTreeMap { fn from(value: LocalChain) -> Self {