|
52 | 52 | // If the descriptor doesn't have a wildcard, we shorten whichever range you pass in
|
53 | 53 | // to have length <= 1. This means that if you pass in 0..0 or 0..1 the range will
|
54 | 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. |
55 | 57 | pub(crate) fn new_with_range<R>(descriptor: D, range: R) -> Self
|
56 | 58 | where
|
57 | 59 | R: RangeBounds<u32>,
|
@@ -100,6 +102,11 @@ where
|
100 | 102 | return None;
|
101 | 103 | }
|
102 | 104 |
|
| 105 | + // If the descriptor is non-wildcard, only index 0 will return an spk. |
| 106 | + if !self.descriptor.borrow().has_wildcard() && self.next_index != 0 { |
| 107 | + return None; |
| 108 | + } |
| 109 | + |
103 | 110 | let script = self
|
104 | 111 | .descriptor
|
105 | 112 | .borrow()
|
@@ -220,6 +227,24 @@ mod test {
|
220 | 227 |
|
221 | 228 | assert_eq!(external_spk.nth(0).unwrap(), (0, external_spk_0));
|
222 | 229 | assert_eq!(external_spk.nth(0), None);
|
| 230 | + |
| 231 | + // non index-0 should NOT return an spk |
| 232 | + assert_eq!( |
| 233 | + SpkIterator::new_with_range(&no_wildcard_descriptor, 1..1).next(), |
| 234 | + None |
| 235 | + ); |
| 236 | + assert_eq!( |
| 237 | + SpkIterator::new_with_range(&no_wildcard_descriptor, 1..=1).next(), |
| 238 | + None |
| 239 | + ); |
| 240 | + assert_eq!( |
| 241 | + SpkIterator::new_with_range(&no_wildcard_descriptor, 1..2).next(), |
| 242 | + None |
| 243 | + ); |
| 244 | + assert_eq!( |
| 245 | + SpkIterator::new_with_range(&no_wildcard_descriptor, 1..=2).next(), |
| 246 | + None |
| 247 | + ); |
223 | 248 | }
|
224 | 249 |
|
225 | 250 | // The following dummy traits were created to test if SpkIterator is working properly.
|
|
0 commit comments