/// Infallibly return a derived address using the external descriptor, see [`AddressIndex`] for
/// available address index selection strategies. If none of the keys in the descriptor are derivable
/// (i.e. does not end with /*) then the same address will always be returned for any [`AddressIndex`].
+ ///
+ /// # Panics
+ ///
+ /// This panics when the caller requests for an address of derivation index greater than the
+ /// BIP32 max index.
pub fn get_address(&mut self, address_index: AddressIndex) -> AddressInfo {
self.try_get_address(address_index).unwrap()
}
/// see [`AddressIndex`] for available address index selection strategies. If none of the keys
/// in the descriptor are derivable (i.e. does not end with /*) then the same address will always
/// be returned for any [`AddressIndex`].
+ ///
+ /// # Panics
+ ///
+ /// This panics when the caller requests for an address of derivation index greater than the
+ /// BIP32 max index.
pub fn get_internal_address(&mut self, address_index: AddressIndex) -> AddressInfo {
self.try_get_internal_address(address_index).unwrap()
}
///
/// A `PersistBackend<ChangeSet>::WriteError` will result if unable to persist the new address
/// to the `PersistBackend`.
+ ///
+ /// # Panics
+ ///
+ /// This panics when the caller requests for an address of derivation index greater than the
+ /// BIP32 max index.
pub fn try_get_address(
&mut self,
address_index: AddressIndex,
/// see [`AddressIndex`] for available address index selection strategies. If none of the keys
/// in the descriptor are derivable (i.e. does not end with /*) then the same address will always
/// be returned for any [`AddressIndex`].
+ ///
+ /// # Panics
+ ///
+ /// This panics when the caller requests for an address of derivation index greater than the
+ /// BIP32 max index.
pub fn try_get_internal_address(
&mut self,
address_index: AddressIndex,
/// See [`AddressIndex`] for available address index selection strategies. If none of the keys
/// in the descriptor are derivable (i.e. does not end with /*) then the same address will
/// always be returned for any [`AddressIndex`].
+ ///
+ /// # Panics
+ ///
+ /// This panics when the caller requests for an address of derivation index greater than the
+ /// BIP32 max index.
fn _get_address(
&mut self,
keychain: KeychainKind,
let ((index, spk), index_changeset) = txout_index.next_unused_spk(&keychain);
(index, spk.into(), Some(index_changeset))
}
- AddressIndex::Peek(index) => {
- let (index, spk) = txout_index
- .unbounded_spk_iter(&keychain)
- .take(index as usize + 1)
- .last()
- .unwrap();
+ AddressIndex::Peek(mut peek_index) => {
+ let mut spk_iter = txout_index.unbounded_spk_iter(&keychain);
+ if !spk_iter.descriptor().has_wildcard() {
+ peek_index = 0;
+ }
+ let (index, spk) = spk_iter
+ .nth(peek_index as usize)
+ .expect("derivation index is out of bounds");
(index, spk, None)
}
};