Trait zcash_address::FromAddress
source · [−]pub trait FromAddress: Sized {
fn from_sprout(
net: Network,
data: [u8; 64]
) -> Result<Self, UnsupportedAddress> { ... }
fn from_sapling(
net: Network,
data: [u8; 43]
) -> Result<Self, UnsupportedAddress> { ... }
fn from_unified(
net: Network,
data: Address
) -> Result<Self, UnsupportedAddress> { ... }
fn from_transparent_p2pkh(
net: Network,
data: [u8; 20]
) -> Result<Self, UnsupportedAddress> { ... }
fn from_transparent_p2sh(
net: Network,
data: [u8; 20]
) -> Result<Self, UnsupportedAddress> { ... }
}
Expand description
A helper trait for converting a ZcashAddress
into another type.
Examples
use zcash_address::{FromAddress, Network, UnsupportedAddress, ZcashAddress};
#[derive(Debug)]
struct MySapling([u8; 43]);
// Implement the FromAddress trait, overriding whichever conversion methods match your
// requirements for the resulting type.
impl FromAddress for MySapling {
fn from_sapling(net: Network, data: [u8; 43]) -> Result<Self, UnsupportedAddress> {
Ok(MySapling(data))
}
}
// For a supported address type, the conversion works.
let addr: ZcashAddress =
"zs1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqpq6d8g"
.parse()
.unwrap();
assert!(addr.convert::<MySapling>().is_ok());
// For an unsupported address type, we get an error.
let addr: ZcashAddress = "t1Hsc1LR8yKnbbe3twRp88p6vFfC5t7DLbs".parse().unwrap();
assert_eq!(
addr.convert::<MySapling>().unwrap_err().to_string(),
"Zcash transparent P2PKH addresses are not supported",
);