zcash_keys: Add `Address::to_transparent_address`

This commit is contained in:
Kris Nuttycombe 2024-12-27 21:07:27 -07:00
parent e4dac19eb6
commit c278405a63
2 changed files with 13 additions and 0 deletions

View File

@ -10,6 +10,7 @@ and this library adheres to Rust's notion of
- `no-std` compatibility (`alloc` is required). A default-enabled `std` feature
flag has been added gating the `std::error::Error` usage.
- `zcash_keys::keys::ReceiverRequirement`
- `zcash_keys::Address::to_transparent_address`
### Changed
- Migrated to `nonempty 0.11`

View File

@ -424,6 +424,18 @@ impl Address {
},
}
}
/// Returns the transparent address corresponding to this address, if it is a transparent
/// address, a Unified address with a transparent receiver, or ZIP 320 (TEX) address.
pub fn to_transparent_address(&self) -> Option<TransparentAddress> {
match self {
#[cfg(feature = "sapling")]
Address::Sapling(_) => None,
Address::Transparent(addr) => Some(*addr),
Address::Unified(ua) => ua.transparent().copied(),
Address::Tex(addr_bytes) => Some(TransparentAddress::PublicKeyHash(*addr_bytes)),
}
}
}
#[cfg(all(