|
1 |
| -use std::collections::{BTreeSet, HashSet}; |
2 |
| -use std::thread::JoinHandle; |
3 |
| - |
4 |
| -use bdk_chain::collections::BTreeMap; |
5 |
| -use bdk_chain::spk_client::{FullScanRequest, FullScanResult, SyncRequest, SyncResult}; |
6 |
| -use bdk_chain::{ |
| 1 | +use bdk_core::collections::{BTreeMap, BTreeSet, HashSet}; |
| 2 | +use bdk_core::spk_client::{FullScanRequest, FullScanResult, SyncRequest, SyncResult}; |
| 3 | +use bdk_core::{ |
7 | 4 | bitcoin::{BlockHash, OutPoint, ScriptBuf, Txid},
|
8 |
| - local_chain::CheckPoint, |
9 |
| - BlockId, ConfirmationBlockTime, |
| 5 | + tx_graph, BlockId, CheckPoint, ConfirmationBlockTime, Indexed, |
10 | 6 | };
|
11 |
| -use bdk_chain::{tx_graph, Anchor, Indexed}; |
12 | 7 | use esplora_client::{OutputStatus, Tx};
|
| 8 | +use std::thread::JoinHandle; |
13 | 9 |
|
14 | 10 | use crate::{insert_anchor_from_status, insert_prevouts};
|
15 | 11 |
|
@@ -199,11 +195,11 @@ fn fetch_block(
|
199 | 195 | ///
|
200 | 196 | /// We want to have a corresponding checkpoint per anchor height. However, checkpoints fetched
|
201 | 197 | /// should not surpass `latest_blocks`.
|
202 |
| -fn chain_update<A: Anchor>( |
| 198 | +fn chain_update( |
203 | 199 | client: &esplora_client::BlockingClient,
|
204 | 200 | latest_blocks: &BTreeMap<u32, BlockHash>,
|
205 | 201 | local_tip: &CheckPoint,
|
206 |
| - anchors: &BTreeSet<(A, Txid)>, |
| 202 | + anchors: &BTreeSet<(ConfirmationBlockTime, Txid)>, |
207 | 203 | ) -> Result<CheckPoint, Error> {
|
208 | 204 | let mut point_of_agreement = None;
|
209 | 205 | let mut conflicts = vec![];
|
@@ -232,8 +228,8 @@ fn chain_update<A: Anchor>(
|
232 | 228 | .extend(conflicts.into_iter().rev())
|
233 | 229 | .expect("evicted are in order");
|
234 | 230 |
|
235 |
| - for anchor in anchors { |
236 |
| - let height = anchor.0.anchor_block().height; |
| 231 | + for (anchor, _) in anchors { |
| 232 | + let height = anchor.block_id.height; |
237 | 233 | if tip.get(height).is_none() {
|
238 | 234 | let hash = match fetch_block(client, latest_blocks, height)? {
|
239 | 235 | Some(hash) => hash,
|
@@ -475,6 +471,7 @@ mod test {
|
475 | 471 | use bdk_chain::bitcoin::Txid;
|
476 | 472 | use bdk_chain::local_chain::LocalChain;
|
477 | 473 | use bdk_chain::BlockId;
|
| 474 | + use bdk_core::ConfirmationBlockTime; |
478 | 475 | use bdk_testenv::{anyhow, bitcoincore_rpc::RpcApi, TestEnv};
|
479 | 476 | use esplora_client::{BlockHash, Builder};
|
480 | 477 | use std::collections::{BTreeMap, BTreeSet};
|
@@ -561,9 +558,12 @@ mod test {
|
561 | 558 | .iter()
|
562 | 559 | .map(|&height| -> anyhow::Result<_> {
|
563 | 560 | Ok((
|
564 |
| - BlockId { |
565 |
| - height, |
566 |
| - hash: env.bitcoind.client.get_block_hash(height as _)?, |
| 561 | + ConfirmationBlockTime { |
| 562 | + block_id: BlockId { |
| 563 | + height, |
| 564 | + hash: env.bitcoind.client.get_block_hash(height as _)?, |
| 565 | + }, |
| 566 | + confirmation_time: height as _, |
567 | 567 | },
|
568 | 568 | Txid::all_zeros(),
|
569 | 569 | ))
|
@@ -598,9 +598,12 @@ mod test {
|
598 | 598 | .iter()
|
599 | 599 | .map(|&(height, txid)| -> anyhow::Result<_> {
|
600 | 600 | Ok((
|
601 |
| - BlockId { |
602 |
| - height, |
603 |
| - hash: env.bitcoind.client.get_block_hash(height as _)?, |
| 601 | + ConfirmationBlockTime { |
| 602 | + block_id: BlockId { |
| 603 | + height, |
| 604 | + hash: env.bitcoind.client.get_block_hash(height as _)?, |
| 605 | + }, |
| 606 | + confirmation_time: height as _, |
604 | 607 | },
|
605 | 608 | txid,
|
606 | 609 | ))
|
@@ -794,9 +797,12 @@ mod test {
|
794 | 797 | let txid: Txid = bdk_chain::bitcoin::hashes::Hash::hash(
|
795 | 798 | &format!("txid_at_height_{}", h).into_bytes(),
|
796 | 799 | );
|
797 |
| - let anchor = BlockId { |
798 |
| - height: h, |
799 |
| - hash: anchor_blockhash, |
| 800 | + let anchor = ConfirmationBlockTime { |
| 801 | + block_id: BlockId { |
| 802 | + height: h, |
| 803 | + hash: anchor_blockhash, |
| 804 | + }, |
| 805 | + confirmation_time: h as _, |
800 | 806 | };
|
801 | 807 | (anchor, txid)
|
802 | 808 | })
|
|
0 commit comments