@@ -4,7 +4,7 @@ use crate::{
4
4
collections:: BTreeMap ,
5
5
CheckPoint , ConfirmationBlockTime , Indexed ,
6
6
} ;
7
- use bitcoin:: { OutPoint , Script , ScriptBuf , Txid } ;
7
+ use bitcoin:: { BlockHash , OutPoint , Script , ScriptBuf , Txid } ;
8
8
9
9
type InspectSync < I > = dyn FnMut ( SyncItem < I > , SyncProgress ) + Send + ' static ;
10
10
@@ -90,8 +90,8 @@ impl SyncProgress {
90
90
///
91
91
/// Construct with [`SyncRequest::builder`].
92
92
#[ must_use]
93
- pub struct SyncRequestBuilder < I = ( ) > {
94
- inner : SyncRequest < I > ,
93
+ pub struct SyncRequestBuilder < I = ( ) , B = BlockHash > {
94
+ inner : SyncRequest < I , B > ,
95
95
}
96
96
97
97
impl SyncRequestBuilder < ( ) > {
@@ -101,11 +101,11 @@ impl SyncRequestBuilder<()> {
101
101
}
102
102
}
103
103
104
- impl < I > SyncRequestBuilder < I > {
104
+ impl < I , B > SyncRequestBuilder < I , B > {
105
105
/// Set the initial chain tip for the sync request.
106
106
///
107
107
/// This is used to update [`LocalChain`](../../bdk_chain/local_chain/struct.LocalChain.html).
108
- pub fn chain_tip ( mut self , cp : CheckPoint ) -> Self {
108
+ pub fn chain_tip ( mut self , cp : CheckPoint < B > ) -> Self {
109
109
self . inner . chain_tip = Some ( cp) ;
110
110
self
111
111
}
@@ -118,6 +118,7 @@ impl<I> SyncRequestBuilder<I> {
118
118
/// [`KeychainTxOutIndex`](../../bdk_chain/indexer/keychain_txout/struct.KeychainTxOutIndex.html).
119
119
///
120
120
/// ```rust
121
+ /// # use bdk_chain::bitcoin::BlockHash;
121
122
/// # use bdk_chain::spk_client::SyncRequest;
122
123
/// # use bdk_chain::indexer::keychain_txout::KeychainTxOutIndex;
123
124
/// # use bdk_chain::miniscript::{Descriptor, DescriptorPublicKey};
@@ -135,15 +136,15 @@ impl<I> SyncRequestBuilder<I> {
135
136
/// let (newly_revealed_spks, _changeset) = indexer
136
137
/// .reveal_to_target("descriptor_a", 21)
137
138
/// .expect("keychain must exist");
138
- /// let _request = SyncRequest::builder()
139
+ /// let _request: SyncRequest<u32, BlockHash> = SyncRequest::builder()
139
140
/// .spks_with_indexes(newly_revealed_spks)
140
141
/// .build();
141
142
///
142
143
/// // Sync all revealed spks in the indexer. This time, spks may be derived from different
143
144
/// // keychains. Each spk will be indexed with `(&'static str, u32)` where `&'static str` is
144
145
/// // the keychain identifier and `u32` is the derivation index.
145
146
/// let all_revealed_spks = indexer.revealed_spks(..);
146
- /// let _request = SyncRequest::builder()
147
+ /// let _request: SyncRequest<(&str, u32), BlockHash> = SyncRequest::builder()
147
148
/// .spks_with_indexes(all_revealed_spks)
148
149
/// .build();
149
150
/// # Ok::<_, bdk_chain::keychain_txout::InsertDescriptorError<_>>(())
@@ -175,7 +176,7 @@ impl<I> SyncRequestBuilder<I> {
175
176
}
176
177
177
178
/// Build the [`SyncRequest`].
178
- pub fn build ( self ) -> SyncRequest < I > {
179
+ pub fn build ( self ) -> SyncRequest < I , B > {
179
180
self . inner
180
181
}
181
182
}
@@ -203,9 +204,9 @@ impl<I> SyncRequestBuilder<I> {
203
204
/// .build();
204
205
/// ```
205
206
#[ must_use]
206
- pub struct SyncRequest < I = ( ) > {
207
+ pub struct SyncRequest < I = ( ) , B = BlockHash > {
207
208
start_time : u64 ,
208
- chain_tip : Option < CheckPoint > ,
209
+ chain_tip : Option < CheckPoint < B > > ,
209
210
spks : VecDeque < ( I , ScriptBuf ) > ,
210
211
spks_consumed : usize ,
211
212
txids : VecDeque < Txid > ,
@@ -215,13 +216,13 @@ pub struct SyncRequest<I = ()> {
215
216
inspect : Box < InspectSync < I > > ,
216
217
}
217
218
218
- impl < I > From < SyncRequestBuilder < I > > for SyncRequest < I > {
219
- fn from ( builder : SyncRequestBuilder < I > ) -> Self {
219
+ impl < I , B > From < SyncRequestBuilder < I , B > > for SyncRequest < I , B > {
220
+ fn from ( builder : SyncRequestBuilder < I , B > ) -> Self {
220
221
builder. inner
221
222
}
222
223
}
223
224
224
- impl < I > SyncRequest < I > {
225
+ impl < I , B > SyncRequest < I , B > {
225
226
/// Start building [`SyncRequest`] with a given `start_time`.
226
227
///
227
228
/// `start_time` specifies the start time of sync. Chain sources can use this value to set
@@ -230,7 +231,7 @@ impl<I> SyncRequest<I> {
230
231
///
231
232
/// Use [`SyncRequest::builder`] to use the current timestamp as `start_time` (this requires
232
233
/// `feature = "std"`).
233
- pub fn builder_at ( start_time : u64 ) -> SyncRequestBuilder < I > {
234
+ pub fn builder_at ( start_time : u64 ) -> SyncRequestBuilder < I , B > {
234
235
SyncRequestBuilder {
235
236
inner : Self {
236
237
start_time,
@@ -252,7 +253,7 @@ impl<I> SyncRequest<I> {
252
253
/// is not available.
253
254
#[ cfg( feature = "std" ) ]
254
255
#[ cfg_attr( docsrs, doc( cfg( feature = "std" ) ) ) ]
255
- pub fn builder ( ) -> SyncRequestBuilder < I > {
256
+ pub fn builder ( ) -> SyncRequestBuilder < I , B > {
256
257
let start_time = std:: time:: UNIX_EPOCH
257
258
. elapsed ( )
258
259
. expect ( "failed to get current timestamp" )
@@ -278,7 +279,7 @@ impl<I> SyncRequest<I> {
278
279
}
279
280
280
281
/// Get the chain tip [`CheckPoint`] of this request (if any).
281
- pub fn chain_tip ( & self ) -> Option < CheckPoint > {
282
+ pub fn chain_tip ( & self ) -> Option < CheckPoint < B > > {
282
283
self . chain_tip . clone ( )
283
284
}
284
285
@@ -314,17 +315,17 @@ impl<I> SyncRequest<I> {
314
315
315
316
/// Iterate over [`ScriptBuf`]s contained in this request.
316
317
pub fn iter_spks ( & mut self ) -> impl ExactSizeIterator < Item = ScriptBuf > + ' _ {
317
- SyncIter :: < I , ScriptBuf > :: new ( self )
318
+ SyncIter :: < I , B , ScriptBuf > :: new ( self )
318
319
}
319
320
320
321
/// Iterate over [`Txid`]s contained in this request.
321
322
pub fn iter_txids ( & mut self ) -> impl ExactSizeIterator < Item = Txid > + ' _ {
322
- SyncIter :: < I , Txid > :: new ( self )
323
+ SyncIter :: < I , B , Txid > :: new ( self )
323
324
}
324
325
325
326
/// Iterate over [`OutPoint`]s contained in this request.
326
327
pub fn iter_outpoints ( & mut self ) -> impl ExactSizeIterator < Item = OutPoint > + ' _ {
327
- SyncIter :: < I , OutPoint > :: new ( self )
328
+ SyncIter :: < I , B , OutPoint > :: new ( self )
328
329
}
329
330
330
331
fn _call_inspect ( & mut self , item : SyncItem < I > ) {
@@ -338,14 +339,14 @@ impl<I> SyncRequest<I> {
338
339
/// See also [`SyncRequest`].
339
340
#[ must_use]
340
341
#[ derive( Debug ) ]
341
- pub struct SyncResponse < A = ConfirmationBlockTime > {
342
+ pub struct SyncResponse < B = BlockHash , A = ConfirmationBlockTime > {
342
343
/// Relevant transaction data discovered during the scan.
343
344
pub tx_update : crate :: TxUpdate < A > ,
344
345
/// Changes to the chain discovered during the scan.
345
- pub chain_update : Option < CheckPoint > ,
346
+ pub chain_update : Option < CheckPoint < B > > ,
346
347
}
347
348
348
- impl < A > Default for SyncResponse < A > {
349
+ impl < B , A > Default for SyncResponse < B , A > {
349
350
fn default ( ) -> Self {
350
351
Self {
351
352
tx_update : Default :: default ( ) ,
@@ -358,15 +359,15 @@ impl<A> Default for SyncResponse<A> {
358
359
///
359
360
/// Construct with [`FullScanRequest::builder`].
360
361
#[ must_use]
361
- pub struct FullScanRequestBuilder < K > {
362
- inner : FullScanRequest < K > ,
362
+ pub struct FullScanRequestBuilder < K , B = BlockHash > {
363
+ inner : FullScanRequest < K , B > ,
363
364
}
364
365
365
- impl < K : Ord > FullScanRequestBuilder < K > {
366
+ impl < K : Ord , B > FullScanRequestBuilder < K , B > {
366
367
/// Set the initial chain tip for the full scan request.
367
368
///
368
369
/// This is used to update [`LocalChain`](../../bdk_chain/local_chain/struct.LocalChain.html).
369
- pub fn chain_tip ( mut self , tip : CheckPoint ) -> Self {
370
+ pub fn chain_tip ( mut self , tip : CheckPoint < B > ) -> Self {
370
371
self . inner . chain_tip = Some ( tip) ;
371
372
self
372
373
}
@@ -393,7 +394,7 @@ impl<K: Ord> FullScanRequestBuilder<K> {
393
394
}
394
395
395
396
/// Build the [`FullScanRequest`].
396
- pub fn build ( self ) -> FullScanRequest < K > {
397
+ pub fn build ( self ) -> FullScanRequest < K , B > {
397
398
self . inner
398
399
}
399
400
}
@@ -406,20 +407,20 @@ impl<K: Ord> FullScanRequestBuilder<K> {
406
407
/// used scripts is not known. The full scan process also updates the chain from the given
407
408
/// [`chain_tip`](FullScanRequestBuilder::chain_tip) (if provided).
408
409
#[ must_use]
409
- pub struct FullScanRequest < K > {
410
+ pub struct FullScanRequest < K , B = BlockHash > {
410
411
start_time : u64 ,
411
- chain_tip : Option < CheckPoint > ,
412
+ chain_tip : Option < CheckPoint < B > > ,
412
413
spks_by_keychain : BTreeMap < K , Box < dyn Iterator < Item = Indexed < ScriptBuf > > + Send > > ,
413
414
inspect : Box < InspectFullScan < K > > ,
414
415
}
415
416
416
- impl < K > From < FullScanRequestBuilder < K > > for FullScanRequest < K > {
417
- fn from ( builder : FullScanRequestBuilder < K > ) -> Self {
417
+ impl < K , B > From < FullScanRequestBuilder < K , B > > for FullScanRequest < K , B > {
418
+ fn from ( builder : FullScanRequestBuilder < K , B > ) -> Self {
418
419
builder. inner
419
420
}
420
421
}
421
422
422
- impl < K : Ord + Clone > FullScanRequest < K > {
423
+ impl < K : Ord + Clone , B > FullScanRequest < K , B > {
423
424
/// Start building a [`FullScanRequest`] with a given `start_time`.
424
425
///
425
426
/// `start_time` specifies the start time of sync. Chain sources can use this value to set
@@ -428,7 +429,7 @@ impl<K: Ord + Clone> FullScanRequest<K> {
428
429
///
429
430
/// Use [`FullScanRequest::builder`] to use the current timestamp as `start_time` (this
430
431
/// requires `feature = "std`).
431
- pub fn builder_at ( start_time : u64 ) -> FullScanRequestBuilder < K > {
432
+ pub fn builder_at ( start_time : u64 ) -> FullScanRequestBuilder < K , B > {
432
433
FullScanRequestBuilder {
433
434
inner : Self {
434
435
start_time,
@@ -445,7 +446,7 @@ impl<K: Ord + Clone> FullScanRequest<K> {
445
446
/// "std"` is not available.
446
447
#[ cfg( feature = "std" ) ]
447
448
#[ cfg_attr( docsrs, doc( cfg( feature = "std" ) ) ) ]
448
- pub fn builder ( ) -> FullScanRequestBuilder < K > {
449
+ pub fn builder ( ) -> FullScanRequestBuilder < K , B > {
449
450
let start_time = std:: time:: UNIX_EPOCH
450
451
. elapsed ( )
451
452
. expect ( "failed to get current timestamp" )
@@ -459,7 +460,7 @@ impl<K: Ord + Clone> FullScanRequest<K> {
459
460
}
460
461
461
462
/// Get the chain tip [`CheckPoint`] of this request (if any).
462
- pub fn chain_tip ( & self ) -> Option < CheckPoint > {
463
+ pub fn chain_tip ( & self ) -> Option < CheckPoint < B > > {
463
464
self . chain_tip . clone ( )
464
465
}
465
466
@@ -491,17 +492,17 @@ impl<K: Ord + Clone> FullScanRequest<K> {
491
492
/// See also [`FullScanRequest`].
492
493
#[ must_use]
493
494
#[ derive( Debug ) ]
494
- pub struct FullScanResponse < K , A = ConfirmationBlockTime > {
495
+ pub struct FullScanResponse < K , B = BlockHash , A = ConfirmationBlockTime > {
495
496
/// Relevant transaction data discovered during the scan.
496
497
pub tx_update : crate :: TxUpdate < A > ,
497
498
/// Last active indices for the corresponding keychains (`K`). An index is active if it had a
498
499
/// transaction associated with the script pubkey at that index.
499
500
pub last_active_indices : BTreeMap < K , u32 > ,
500
501
/// Changes to the chain discovered during the scan.
501
- pub chain_update : Option < CheckPoint > ,
502
+ pub chain_update : Option < CheckPoint < B > > ,
502
503
}
503
504
504
- impl < K , A > Default for FullScanResponse < K , A > {
505
+ impl < K , B , A > Default for FullScanResponse < K , B , A > {
505
506
fn default ( ) -> Self {
506
507
Self {
507
508
tx_update : Default :: default ( ) ,
@@ -527,23 +528,26 @@ impl<K: Ord + Clone> Iterator for KeychainSpkIter<'_, K> {
527
528
}
528
529
}
529
530
530
- struct SyncIter < ' r , I , Item > {
531
- request : & ' r mut SyncRequest < I > ,
531
+ struct SyncIter < ' r , I , B , Item > {
532
+ request : & ' r mut SyncRequest < I , B > ,
532
533
marker : core:: marker:: PhantomData < Item > ,
533
534
}
534
535
535
- impl < ' r , I , Item > SyncIter < ' r , I , Item > {
536
- fn new ( request : & ' r mut SyncRequest < I > ) -> Self {
536
+ impl < ' r , I , B , Item > SyncIter < ' r , I , B , Item > {
537
+ fn new ( request : & ' r mut SyncRequest < I , B > ) -> Self {
537
538
Self {
538
539
request,
539
540
marker : core:: marker:: PhantomData ,
540
541
}
541
542
}
542
543
}
543
544
544
- impl < ' r , I , Item > ExactSizeIterator for SyncIter < ' r , I , Item > where SyncIter < ' r , I , Item > : Iterator { }
545
+ impl < ' r , I , B , Item > ExactSizeIterator for SyncIter < ' r , I , B , Item > where
546
+ SyncIter < ' r , I , B , Item > : Iterator
547
+ {
548
+ }
545
549
546
- impl < I > Iterator for SyncIter < ' _ , I , ScriptBuf > {
550
+ impl < I , B > Iterator for SyncIter < ' _ , I , B , ScriptBuf > {
547
551
type Item = ScriptBuf ;
548
552
549
553
fn next ( & mut self ) -> Option < Self :: Item > {
@@ -556,7 +560,7 @@ impl<I> Iterator for SyncIter<'_, I, ScriptBuf> {
556
560
}
557
561
}
558
562
559
- impl < I > Iterator for SyncIter < ' _ , I , Txid > {
563
+ impl < I , B > Iterator for SyncIter < ' _ , I , B , Txid > {
560
564
type Item = Txid ;
561
565
562
566
fn next ( & mut self ) -> Option < Self :: Item > {
@@ -569,7 +573,7 @@ impl<I> Iterator for SyncIter<'_, I, Txid> {
569
573
}
570
574
}
571
575
572
- impl < I > Iterator for SyncIter < ' _ , I , OutPoint > {
576
+ impl < I , B > Iterator for SyncIter < ' _ , I , B , OutPoint > {
573
577
type Item = OutPoint ;
574
578
575
579
fn next ( & mut self ) -> Option < Self :: Item > {
0 commit comments