@@ -43,18 +43,24 @@ impl<D> SpkIterator<D>
4343where
4444 D : Borrow < Descriptor < DescriptorPublicKey > > ,
4545{
46- /// Creates a new script pubkey iterator starting at 0 from a descriptor.
46+ /// Create a new script pubkey iterator from `descriptor`.
47+ ///
48+ /// This iterates from derivation index 0 and stops at index 0x7FFFFFFF (as specified in
49+ /// BIP-32). Non-wildcard descriptors will only return one script pubkey at derivation index 0.
50+ ///
51+ /// Use [`new_with_range`](SpkIterator::new_with_range) to create an iterator with a specified
52+ /// derivation index range.
4753 pub fn new ( descriptor : D ) -> Self {
4854 SpkIterator :: new_with_range ( descriptor, 0 ..=BIP32_MAX_INDEX )
4955 }
5056
51- // Creates a new script pubkey iterator from a descriptor with a given range.
52- // If the descriptor doesn't have a wildcard, we shorten whichever range you pass in
53- // to have length <= 1. This means that if you pass in 0..0 or 0..1 the range will
54- // remain the same, but if you pass in 0..10, we'll shorten it to 0..1
55- // Also note that if the descriptor doesn't have a wildcard, passing in a range starting
56- // from n > 0, will return an empty iterator .
57- pub ( crate ) fn new_with_range < R > ( descriptor : D , range : R ) -> Self
57+ /// Create a new script pubkey iterator from ` descriptor` and a given ` range` .
58+ ///
59+ /// Non-wildcard descriptors will only emit a single script pubkey (at derivation index 0).
60+ /// Wildcard descriptors have an end-bound of 0x7FFFFFFF (inclusive).
61+ ///
62+ /// Refer to [`new`](SpkIterator::new) for more .
63+ pub fn new_with_range < R > ( descriptor : D , range : R ) -> Self
5864 where
5965 R : RangeBounds < u32 > ,
6066 {
7379 // Because `end` is exclusive, we want the maximum value to be BIP32_MAX_INDEX + 1.
7480 end = end. min ( BIP32_MAX_INDEX + 1 ) ;
7581
76- if !descriptor. borrow ( ) . has_wildcard ( ) {
77- // The length of the range should be at most 1
78- if end != start {
79- end = start + 1 ;
80- }
81- }
82-
8382 Self {
8483 next_index : start,
8584 end,
@@ -250,6 +249,14 @@ mod test {
250249 SpkIterator :: new_with_range( & no_wildcard_descriptor, 1 ..=2 ) . next( ) ,
251250 None
252251 ) ;
252+ assert_eq ! (
253+ SpkIterator :: new_with_range( & no_wildcard_descriptor, 10 ..11 ) . next( ) ,
254+ None
255+ ) ;
256+ assert_eq ! (
257+ SpkIterator :: new_with_range( & no_wildcard_descriptor, 10 ..=10 ) . next( ) ,
258+ None
259+ ) ;
253260 }
254261
255262 // The following dummy traits were created to test if SpkIterator is working properly.
0 commit comments