Skip to content

Commit

Permalink
zcash_keys: Add Address::to_transparent_address
Browse files Browse the repository at this point in the history
  • Loading branch information
nuttycom committed Dec 30, 2024
1 parent a250648 commit 90de61f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions zcash_keys/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
12 changes: 12 additions & 0 deletions zcash_keys/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 90de61f

Please sign in to comment.