From 90de61f6f28fc17074d0908121262140566318a1 Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Fri, 27 Dec 2024 21:07:27 -0700 Subject: [PATCH] zcash_keys: Add `Address::to_transparent_address` --- zcash_keys/CHANGELOG.md | 1 + zcash_keys/src/address.rs | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/zcash_keys/CHANGELOG.md b/zcash_keys/CHANGELOG.md index cabedc12a..014f3d921 100644 --- a/zcash_keys/CHANGELOG.md +++ b/zcash_keys/CHANGELOG.md @@ -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` diff --git a/zcash_keys/src/address.rs b/zcash_keys/src/address.rs index 15b7fb8fd..3a196ecf9 100644 --- a/zcash_keys/src/address.rs +++ b/zcash_keys/src/address.rs @@ -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 { + 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(