Trait zcash_address::ToAddress
source · pub trait ToAddress: Sealed {
// Required methods
fn from_sprout(net: Network, data: [u8; 64]) -> Self;
fn from_sapling(net: Network, data: [u8; 43]) -> Self;
fn from_unified(net: Network, data: Address) -> Self;
fn from_transparent_p2pkh(net: Network, data: [u8; 20]) -> Self;
fn from_transparent_p2sh(net: Network, data: [u8; 20]) -> Self;
fn from_tex(net: Network, data: [u8; 20]) -> Self;
}
Expand description
A helper trait for converting another type into a ZcashAddress
.
This trait is sealed and cannot be implemented for types outside this crate. Its
purpose is to move these conversion functions out of the main ZcashAddress
API
documentation, as they are only required when creating addresses (rather than when
parsing addresses, which is a more common occurrence).
§Examples
use zcash_address::{ToAddress, Network, ZcashAddress};
#[derive(Debug)]
struct MySapling([u8; 43]);
impl MySapling {
/// Encodes this Sapling address for the given network.
fn encode(&self, net: Network) -> ZcashAddress {
ZcashAddress::from_sapling(net, self.0)
}
}
let addr = MySapling([0; 43]);
let encoded = addr.encode(Network::Main);
assert_eq!(
encoded.to_string(),
"zs1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqpq6d8g",
);
Required Methods§
fn from_sprout(net: Network, data: [u8; 64]) -> Self
fn from_sapling(net: Network, data: [u8; 43]) -> Self
fn from_unified(net: Network, data: Address) -> Self
fn from_transparent_p2pkh(net: Network, data: [u8; 20]) -> Self
fn from_transparent_p2sh(net: Network, data: [u8; 20]) -> Self
fn from_tex(net: Network, data: [u8; 20]) -> Self
Object Safety§
This trait is not object safe.