FullViewingKey::address_at(impl Into<DiversifierIndex>)

This is a more usable API, which we can use when we have the full
viewing key and can obtain the DiversifierKey.
This commit is contained in:
Jack Grigg 2021-03-16 09:04:36 +13:00
parent e98f324d7d
commit e0b40cb3cb
1 changed files with 10 additions and 0 deletions

View File

@ -166,6 +166,16 @@ impl FullViewingKey {
.expect("Default address works by construction")
}
/// Returns the payment address for this key at the given index.
///
/// Returns `None` if the diversifier does not correspond to an address. This happens
/// with negligible probability; in most cases unwrapping the result will be fine, but
/// if you have specific stability requirements then you can either convert this into
/// an error, or try another diversifier index (e.g. incrementing).
pub fn address_at(&self, j: impl Into<DiversifierIndex>) -> Option<Address> {
self.address(DiversifierKey::from(self).get(j))
}
/// Returns the payment address for this key corresponding to the given diversifier.
///
/// Returns `None` if the diversifier does not correspond to an address. This happens