@@ -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
@@ -88,11 +88,11 @@ impl SyncProgress {
88
88
89
89
/// Builds a [`SyncRequest`].
90
90
#[ must_use]
91
- pub struct SyncRequestBuilder < I = ( ) > {
92
- inner : SyncRequest < I > ,
91
+ pub struct SyncRequestBuilder < I = ( ) , B = BlockHash > {
92
+ inner : SyncRequest < I , B > ,
93
93
}
94
94
95
- impl < I > Default for SyncRequestBuilder < I > {
95
+ impl < I , B > Default for SyncRequestBuilder < I , B > {
96
96
fn default ( ) -> Self {
97
97
Self {
98
98
inner : Default :: default ( ) ,
@@ -107,11 +107,11 @@ impl SyncRequestBuilder<()> {
107
107
}
108
108
}
109
109
110
- impl < I > SyncRequestBuilder < I > {
110
+ impl < I , B > SyncRequestBuilder < I , B > {
111
111
/// Set the initial chain tip for the sync request.
112
112
///
113
113
/// This is used to update [`LocalChain`](../../bdk_chain/local_chain/struct.LocalChain.html).
114
- pub fn chain_tip ( mut self , cp : CheckPoint ) -> Self {
114
+ pub fn chain_tip ( mut self , cp : CheckPoint < B > ) -> Self {
115
115
self . inner . chain_tip = Some ( cp) ;
116
116
self
117
117
}
@@ -124,6 +124,7 @@ impl<I> SyncRequestBuilder<I> {
124
124
/// [`KeychainTxOutIndex`](../../bdk_chain/indexer/keychain_txout/struct.KeychainTxOutIndex.html).
125
125
///
126
126
/// ```rust
127
+ /// # use bdk_chain::bitcoin::BlockHash;
127
128
/// # use bdk_chain::spk_client::SyncRequest;
128
129
/// # use bdk_chain::indexer::keychain_txout::KeychainTxOutIndex;
129
130
/// # use bdk_chain::miniscript::{Descriptor, DescriptorPublicKey};
@@ -141,15 +142,15 @@ impl<I> SyncRequestBuilder<I> {
141
142
/// let (newly_revealed_spks, _changeset) = indexer
142
143
/// .reveal_to_target("descriptor_a", 21)
143
144
/// .expect("keychain must exist");
144
- /// let _request = SyncRequest::builder()
145
+ /// let _request: SyncRequest<u32, BlockHash> = SyncRequest::builder()
145
146
/// .spks_with_indexes(newly_revealed_spks)
146
147
/// .build();
147
148
///
148
149
/// // Sync all revealed spks in the indexer. This time, spks may be derived from different
149
150
/// // keychains. Each spk will be indexed with `(&'static str, u32)` where `&'static str` is
150
151
/// // the keychain identifier and `u32` is the derivation index.
151
152
/// let all_revealed_spks = indexer.revealed_spks(..);
152
- /// let _request = SyncRequest::builder()
153
+ /// let _request: SyncRequest<(&str, u32), BlockHash> = SyncRequest::builder()
153
154
/// .spks_with_indexes(all_revealed_spks)
154
155
/// .build();
155
156
/// # Ok::<_, bdk_chain::keychain_txout::InsertDescriptorError<_>>(())
@@ -181,7 +182,7 @@ impl<I> SyncRequestBuilder<I> {
181
182
}
182
183
183
184
/// Build the [`SyncRequest`].
184
- pub fn build ( self ) -> SyncRequest < I > {
185
+ pub fn build ( self ) -> SyncRequest < I , B > {
185
186
self . inner
186
187
}
187
188
}
@@ -209,8 +210,8 @@ impl<I> SyncRequestBuilder<I> {
209
210
/// .build();
210
211
/// ```
211
212
#[ must_use]
212
- pub struct SyncRequest < I = ( ) > {
213
- chain_tip : Option < CheckPoint > ,
213
+ pub struct SyncRequest < I = ( ) , B = BlockHash > {
214
+ chain_tip : Option < CheckPoint < B > > ,
214
215
spks : VecDeque < ( I , ScriptBuf ) > ,
215
216
spks_consumed : usize ,
216
217
txids : VecDeque < Txid > ,
@@ -220,7 +221,7 @@ pub struct SyncRequest<I = ()> {
220
221
inspect : Box < InspectSync < I > > ,
221
222
}
222
223
223
- impl < I > Default for SyncRequest < I > {
224
+ impl < I , B > Default for SyncRequest < I , B > {
224
225
fn default ( ) -> Self {
225
226
Self {
226
227
chain_tip : None ,
@@ -235,15 +236,15 @@ impl<I> Default for SyncRequest<I> {
235
236
}
236
237
}
237
238
238
- impl < I > From < SyncRequestBuilder < I > > for SyncRequest < I > {
239
- fn from ( builder : SyncRequestBuilder < I > ) -> Self {
239
+ impl < I , B > From < SyncRequestBuilder < I , B > > for SyncRequest < I , B > {
240
+ fn from ( builder : SyncRequestBuilder < I , B > ) -> Self {
240
241
builder. inner
241
242
}
242
243
}
243
244
244
- impl < I > SyncRequest < I > {
245
+ impl < I , B > SyncRequest < I , B > {
245
246
/// Start building a [`SyncRequest`].
246
- pub fn builder ( ) -> SyncRequestBuilder < I > {
247
+ pub fn builder ( ) -> SyncRequestBuilder < I , B > {
247
248
SyncRequestBuilder {
248
249
inner : Default :: default ( ) ,
249
250
}
@@ -262,7 +263,7 @@ impl<I> SyncRequest<I> {
262
263
}
263
264
264
265
/// Get the chain tip [`CheckPoint`] of this request (if any).
265
- pub fn chain_tip ( & self ) -> Option < CheckPoint > {
266
+ pub fn chain_tip ( & self ) -> Option < CheckPoint < B > > {
266
267
self . chain_tip . clone ( )
267
268
}
268
269
@@ -298,17 +299,17 @@ impl<I> SyncRequest<I> {
298
299
299
300
/// Iterate over [`ScriptBuf`]s contained in this request.
300
301
pub fn iter_spks ( & mut self ) -> impl ExactSizeIterator < Item = ScriptBuf > + ' _ {
301
- SyncIter :: < I , ScriptBuf > :: new ( self )
302
+ SyncIter :: < I , B , ScriptBuf > :: new ( self )
302
303
}
303
304
304
305
/// Iterate over [`Txid`]s contained in this request.
305
306
pub fn iter_txids ( & mut self ) -> impl ExactSizeIterator < Item = Txid > + ' _ {
306
- SyncIter :: < I , Txid > :: new ( self )
307
+ SyncIter :: < I , B , Txid > :: new ( self )
307
308
}
308
309
309
310
/// Iterate over [`OutPoint`]s contained in this request.
310
311
pub fn iter_outpoints ( & mut self ) -> impl ExactSizeIterator < Item = OutPoint > + ' _ {
311
- SyncIter :: < I , OutPoint > :: new ( self )
312
+ SyncIter :: < I , B , OutPoint > :: new ( self )
312
313
}
313
314
314
315
fn _call_inspect ( & mut self , item : SyncItem < I > ) {
@@ -322,14 +323,14 @@ impl<I> SyncRequest<I> {
322
323
/// See also [`SyncRequest`].
323
324
#[ must_use]
324
325
#[ derive( Debug ) ]
325
- pub struct SyncResult < A = ConfirmationBlockTime > {
326
+ pub struct SyncResult < B = BlockHash , A = ConfirmationBlockTime > {
326
327
/// Relevant transaction data discovered during the scan.
327
328
pub tx_update : crate :: TxUpdate < A > ,
328
329
/// Changes to the chain discovered during the scan.
329
- pub chain_update : Option < CheckPoint > ,
330
+ pub chain_update : Option < CheckPoint < B > > ,
330
331
}
331
332
332
- impl < A > Default for SyncResult < A > {
333
+ impl < B , A > Default for SyncResult < B , A > {
333
334
fn default ( ) -> Self {
334
335
Self {
335
336
tx_update : Default :: default ( ) ,
@@ -340,23 +341,23 @@ impl<A> Default for SyncResult<A> {
340
341
341
342
/// Builds a [`FullScanRequest`].
342
343
#[ must_use]
343
- pub struct FullScanRequestBuilder < K > {
344
- inner : FullScanRequest < K > ,
344
+ pub struct FullScanRequestBuilder < K , B = BlockHash > {
345
+ inner : FullScanRequest < K , B > ,
345
346
}
346
347
347
- impl < K > Default for FullScanRequestBuilder < K > {
348
+ impl < K , B > Default for FullScanRequestBuilder < K , B > {
348
349
fn default ( ) -> Self {
349
350
Self {
350
351
inner : Default :: default ( ) ,
351
352
}
352
353
}
353
354
}
354
355
355
- impl < K : Ord > FullScanRequestBuilder < K > {
356
+ impl < K : Ord , B > FullScanRequestBuilder < K , B > {
356
357
/// Set the initial chain tip for the full scan request.
357
358
///
358
359
/// This is used to update [`LocalChain`](../../bdk_chain/local_chain/struct.LocalChain.html).
359
- pub fn chain_tip ( mut self , tip : CheckPoint ) -> Self {
360
+ pub fn chain_tip ( mut self , tip : CheckPoint < B > ) -> Self {
360
361
self . inner . chain_tip = Some ( tip) ;
361
362
self
362
363
}
@@ -383,7 +384,7 @@ impl<K: Ord> FullScanRequestBuilder<K> {
383
384
}
384
385
385
386
/// Build the [`FullScanRequest`].
386
- pub fn build ( self ) -> FullScanRequest < K > {
387
+ pub fn build ( self ) -> FullScanRequest < K , B > {
387
388
self . inner
388
389
}
389
390
}
@@ -396,19 +397,19 @@ impl<K: Ord> FullScanRequestBuilder<K> {
396
397
/// used scripts is not known. The full scan process also updates the chain from the given
397
398
/// [`chain_tip`](FullScanRequestBuilder::chain_tip) (if provided).
398
399
#[ must_use]
399
- pub struct FullScanRequest < K > {
400
- chain_tip : Option < CheckPoint > ,
400
+ pub struct FullScanRequest < K , B = BlockHash > {
401
+ chain_tip : Option < CheckPoint < B > > ,
401
402
spks_by_keychain : BTreeMap < K , Box < dyn Iterator < Item = Indexed < ScriptBuf > > + Send > > ,
402
403
inspect : Box < InspectFullScan < K > > ,
403
404
}
404
405
405
- impl < K > From < FullScanRequestBuilder < K > > for FullScanRequest < K > {
406
- fn from ( builder : FullScanRequestBuilder < K > ) -> Self {
406
+ impl < K , B > From < FullScanRequestBuilder < K , B > > for FullScanRequest < K , B > {
407
+ fn from ( builder : FullScanRequestBuilder < K , B > ) -> Self {
407
408
builder. inner
408
409
}
409
410
}
410
411
411
- impl < K > Default for FullScanRequest < K > {
412
+ impl < K , B > Default for FullScanRequest < K , B > {
412
413
fn default ( ) -> Self {
413
414
Self {
414
415
chain_tip : None ,
@@ -418,16 +419,16 @@ impl<K> Default for FullScanRequest<K> {
418
419
}
419
420
}
420
421
421
- impl < K : Ord + Clone > FullScanRequest < K > {
422
+ impl < K : Ord + Clone , B > FullScanRequest < K , B > {
422
423
/// Start building a [`FullScanRequest`].
423
- pub fn builder ( ) -> FullScanRequestBuilder < K > {
424
+ pub fn builder ( ) -> FullScanRequestBuilder < K , B > {
424
425
FullScanRequestBuilder {
425
426
inner : Self :: default ( ) ,
426
427
}
427
428
}
428
429
429
430
/// Get the chain tip [`CheckPoint`] of this request (if any).
430
- pub fn chain_tip ( & self ) -> Option < CheckPoint > {
431
+ pub fn chain_tip ( & self ) -> Option < CheckPoint < B > > {
431
432
self . chain_tip . clone ( )
432
433
}
433
434
@@ -459,17 +460,17 @@ impl<K: Ord + Clone> FullScanRequest<K> {
459
460
/// See also [`FullScanRequest`].
460
461
#[ must_use]
461
462
#[ derive( Debug ) ]
462
- pub struct FullScanResult < K , A = ConfirmationBlockTime > {
463
+ pub struct FullScanResult < K , B = BlockHash , A = ConfirmationBlockTime > {
463
464
/// Relevant transaction data discovered during the scan.
464
465
pub tx_update : crate :: TxUpdate < A > ,
465
466
/// Last active indices for the corresponding keychains (`K`). An index is active if it had a
466
467
/// transaction associated with the script pubkey at that index.
467
468
pub last_active_indices : BTreeMap < K , u32 > ,
468
469
/// Changes to the chain discovered during the scan.
469
- pub chain_update : Option < CheckPoint > ,
470
+ pub chain_update : Option < CheckPoint < B > > ,
470
471
}
471
472
472
- impl < K , A > Default for FullScanResult < K , A > {
473
+ impl < K , B , A > Default for FullScanResult < K , B , A > {
473
474
fn default ( ) -> Self {
474
475
Self {
475
476
tx_update : Default :: default ( ) ,
@@ -495,23 +496,26 @@ impl<'r, K: Ord + Clone> Iterator for KeychainSpkIter<'r, K> {
495
496
}
496
497
}
497
498
498
- struct SyncIter < ' r , I , Item > {
499
- request : & ' r mut SyncRequest < I > ,
499
+ struct SyncIter < ' r , I , B , Item > {
500
+ request : & ' r mut SyncRequest < I , B > ,
500
501
marker : core:: marker:: PhantomData < Item > ,
501
502
}
502
503
503
- impl < ' r , I , Item > SyncIter < ' r , I , Item > {
504
- fn new ( request : & ' r mut SyncRequest < I > ) -> Self {
504
+ impl < ' r , I , B , Item > SyncIter < ' r , I , B , Item > {
505
+ fn new ( request : & ' r mut SyncRequest < I , B > ) -> Self {
505
506
Self {
506
507
request,
507
508
marker : core:: marker:: PhantomData ,
508
509
}
509
510
}
510
511
}
511
512
512
- impl < ' r , I , Item > ExactSizeIterator for SyncIter < ' r , I , Item > where SyncIter < ' r , I , Item > : Iterator { }
513
+ impl < ' r , I , B , Item > ExactSizeIterator for SyncIter < ' r , I , B , Item > where
514
+ SyncIter < ' r , I , B , Item > : Iterator
515
+ {
516
+ }
513
517
514
- impl < ' r , I > Iterator for SyncIter < ' r , I , ScriptBuf > {
518
+ impl < ' r , I , B > Iterator for SyncIter < ' r , I , B , ScriptBuf > {
515
519
type Item = ScriptBuf ;
516
520
517
521
fn next ( & mut self ) -> Option < Self :: Item > {
@@ -524,7 +528,7 @@ impl<'r, I> Iterator for SyncIter<'r, I, ScriptBuf> {
524
528
}
525
529
}
526
530
527
- impl < ' r , I > Iterator for SyncIter < ' r , I , Txid > {
531
+ impl < ' r , I , B > Iterator for SyncIter < ' r , I , B , Txid > {
528
532
type Item = Txid ;
529
533
530
534
fn next ( & mut self ) -> Option < Self :: Item > {
@@ -537,7 +541,7 @@ impl<'r, I> Iterator for SyncIter<'r, I, Txid> {
537
541
}
538
542
}
539
543
540
- impl < ' r , I > Iterator for SyncIter < ' r , I , OutPoint > {
544
+ impl < ' r , I , B > Iterator for SyncIter < ' r , I , B , OutPoint > {
541
545
type Item = OutPoint ;
542
546
543
547
fn next ( & mut self ) -> Option < Self :: Item > {
0 commit comments