|
1 |
| -use bdk_chain::{ |
| 1 | +use bdk_core::{ |
2 | 2 | bitcoin::{block::Header, BlockHash, OutPoint, ScriptBuf, Transaction, Txid},
|
3 | 3 | collections::{BTreeMap, HashMap},
|
4 |
| - local_chain::CheckPoint, |
5 | 4 | spk_client::{FullScanRequest, FullScanResult, SyncRequest, SyncResult},
|
6 |
| - tx_graph::{self, TxGraph}, |
7 |
| - Anchor, BlockId, ConfirmationBlockTime, |
| 5 | + tx_graph, BlockId, CheckPoint, ConfirmationBlockTime, |
8 | 6 | };
|
9 | 7 | use electrum_client::{ElectrumApi, Error, HeaderNotification};
|
10 | 8 | use std::{
|
@@ -39,14 +37,11 @@ impl<E: ElectrumApi> BdkElectrumClient<E> {
|
39 | 37 |
|
40 | 38 | /// Inserts transactions into the transaction cache so that the client will not fetch these
|
41 | 39 | /// transactions.
|
42 |
| - pub fn populate_tx_cache<A>(&self, tx_graph: impl AsRef<TxGraph<A>>) { |
43 |
| - let txs = tx_graph |
44 |
| - .as_ref() |
45 |
| - .full_txs() |
46 |
| - .map(|tx_node| (tx_node.txid, tx_node.tx)); |
47 |
| - |
| 40 | + pub fn populate_tx_cache(&self, txs: impl IntoIterator<Item = impl Into<Arc<Transaction>>>) { |
48 | 41 | let mut tx_cache = self.tx_cache.lock().unwrap();
|
49 |
| - for (txid, tx) in txs { |
| 42 | + for tx in txs { |
| 43 | + let tx = tx.into(); |
| 44 | + let txid = tx.compute_txid(); |
50 | 45 | tx_cache.insert(txid, tx);
|
51 | 46 | }
|
52 | 47 | }
|
@@ -121,9 +116,10 @@ impl<E: ElectrumApi> BdkElectrumClient<E> {
|
121 | 116 | /// [`CalculateFeeError::MissingTxOut`] error if those `TxOut`s are not
|
122 | 117 | /// present in the transaction graph.
|
123 | 118 | ///
|
124 |
| - /// [`CalculateFeeError::MissingTxOut`]: bdk_chain::tx_graph::CalculateFeeError::MissingTxOut |
125 |
| - /// [`Wallet.calculate_fee`]: https://docs.rs/bdk_wallet/latest/bdk_wallet/struct.Wallet.html#method.calculate_fee |
126 |
| - /// [`Wallet.calculate_fee_rate`]: https://docs.rs/bdk_wallet/latest/bdk_wallet/struct.Wallet.html#method.calculate_fee_rate |
| 119 | + /// [`bdk_chain`]: ../bdk_chain/index.html |
| 120 | + /// [`CalculateFeeError::MissingTxOut`]: ../bdk_chain/tx_graph/enum.CalculateFeeError.html#variant.MissingTxOut |
| 121 | + /// [`Wallet.calculate_fee`]: ../bdk_wallet/struct.Wallet.html#method.calculate_fee |
| 122 | + /// [`Wallet.calculate_fee_rate`]: ../bdk_wallet/struct.Wallet.html#method.calculate_fee_rate |
127 | 123 | pub fn full_scan<K: Ord + Clone>(
|
128 | 124 | &self,
|
129 | 125 | request: impl Into<FullScanRequest<K>>,
|
@@ -189,9 +185,10 @@ impl<E: ElectrumApi> BdkElectrumClient<E> {
|
189 | 185 | /// may include scripts that have been used, use [`full_scan`] with the keychain.
|
190 | 186 | ///
|
191 | 187 | /// [`full_scan`]: Self::full_scan
|
192 |
| - /// [`CalculateFeeError::MissingTxOut`]: bdk_chain::tx_graph::CalculateFeeError::MissingTxOut |
193 |
| - /// [`Wallet.calculate_fee`]: https://docs.rs/bdk_wallet/latest/bdk_wallet/struct.Wallet.html#method.calculate_fee |
194 |
| - /// [`Wallet.calculate_fee_rate`]: https://docs.rs/bdk_wallet/latest/bdk_wallet/struct.Wallet.html#method.calculate_fee_rate |
| 188 | + /// [`bdk_chain`]: ../bdk_chain/index.html |
| 189 | + /// [`CalculateFeeError::MissingTxOut`]: ../bdk_chain/tx_graph/enum.CalculateFeeError.html#variant.MissingTxOut |
| 190 | + /// [`Wallet.calculate_fee`]: ../bdk_wallet/struct.Wallet.html#method.calculate_fee |
| 191 | + /// [`Wallet.calculate_fee_rate`]: ../bdk_wallet/struct.Wallet.html#method.calculate_fee_rate |
195 | 192 | pub fn sync<I: 'static>(
|
196 | 193 | &self,
|
197 | 194 | request: impl Into<SyncRequest<I>>,
|
@@ -514,20 +511,20 @@ fn fetch_tip_and_latest_blocks(
|
514 | 511 |
|
515 | 512 | // Add a corresponding checkpoint per anchor height if it does not yet exist. Checkpoints should not
|
516 | 513 | // surpass `latest_blocks`.
|
517 |
| -fn chain_update<A: Anchor>( |
| 514 | +fn chain_update( |
518 | 515 | mut tip: CheckPoint,
|
519 | 516 | latest_blocks: &BTreeMap<u32, BlockHash>,
|
520 |
| - anchors: impl Iterator<Item = (A, Txid)>, |
| 517 | + anchors: impl Iterator<Item = (ConfirmationBlockTime, Txid)>, |
521 | 518 | ) -> Result<CheckPoint, Error> {
|
522 |
| - for anchor in anchors { |
523 |
| - let height = anchor.0.anchor_block().height; |
| 519 | + for (anchor, _txid) in anchors { |
| 520 | + let height = anchor.block_id.height; |
524 | 521 |
|
525 | 522 | // Checkpoint uses the `BlockHash` from `latest_blocks` so that the hash will be consistent
|
526 | 523 | // in case of a re-org.
|
527 | 524 | if tip.get(height).is_none() && height <= tip.height() {
|
528 | 525 | let hash = match latest_blocks.get(&height) {
|
529 | 526 | Some(&hash) => hash,
|
530 |
| - None => anchor.0.anchor_block().hash, |
| 527 | + None => anchor.block_id.hash, |
531 | 528 | };
|
532 | 529 | tip = tip.insert(BlockId { hash, height });
|
533 | 530 | }
|
|
0 commit comments