Skip to content

Commit

Permalink
refactor(electrum): make LocalChain generic
Browse files Browse the repository at this point in the history
  • Loading branch information
LagginTimes committed Jun 14, 2024
1 parent b4a847f commit 0ae0911
Show file tree
Hide file tree
Showing 8 changed files with 569 additions and 341 deletions.
8 changes: 4 additions & 4 deletions crates/bitcoind_rpc/tests/test_emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use bdk_bitcoind_rpc::Emitter;
use bdk_chain::{
bitcoin::{Address, Amount, Txid},
keychain::Balance,
local_chain::{CheckPoint, LocalChain},
local_chain::{ChangeSet, CheckPoint, LocalChain},
Append, BlockId, IndexedTxGraph, SpkTxOutIndex,
};
use bdk_testenv::{anyhow, TestEnv};
Expand Down Expand Up @@ -48,7 +48,7 @@ pub fn test_sync_local_chain() -> anyhow::Result<()> {

assert_eq!(
local_chain.apply_update(emission.checkpoint,)?,
BTreeMap::from([(height, Some(hash))]),
ChangeSet::from_iter([(height, Some(BlockId { height, hash }))]),
"chain update changeset is unexpected",
);
}
Expand Down Expand Up @@ -94,11 +94,11 @@ pub fn test_sync_local_chain() -> anyhow::Result<()> {
assert_eq!(
local_chain.apply_update(emission.checkpoint,)?,
if exp_height == exp_hashes.len() - reorged_blocks.len() {
core::iter::once((height, Some(hash)))
core::iter::once((height, Some(BlockId { height, hash })))
.chain((height + 1..exp_hashes.len() as u32).map(|h| (h, None)))
.collect::<bdk_chain::local_chain::ChangeSet>()
} else {
BTreeMap::from([(height, Some(hash))])
ChangeSet::from_iter([(height, Some(BlockId { height, hash }))])
},
"chain update changeset is unexpected",
);
Expand Down
6 changes: 6 additions & 0 deletions crates/chain/src/chain_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ pub struct BlockId {
pub hash: BlockHash,
}

impl AsRef<BlockId> for BlockId {
fn as_ref(&self) -> &BlockId {
self
}
}

impl Anchor for BlockId {
fn anchor_block(&self) -> Self {
*self
Expand Down
Loading

0 comments on commit 0ae0911

Please sign in to comment.