Trait Converter

Source
pub trait Converter<T> {
    type Error;

    // Provided methods
    fn convert_sprout(
        &self,
        net: NetworkType,
        data: [u8; 64],
    ) -> Result<T, ConversionError<Self::Error>> { ... }
    fn convert_sapling(
        &self,
        net: NetworkType,
        data: [u8; 43],
    ) -> Result<T, ConversionError<Self::Error>> { ... }
    fn convert_unified(
        &self,
        net: NetworkType,
        data: Address,
    ) -> Result<T, ConversionError<Self::Error>> { ... }
    fn convert_transparent_p2pkh(
        &self,
        net: NetworkType,
        data: [u8; 20],
    ) -> Result<T, ConversionError<Self::Error>> { ... }
    fn convert_transparent_p2sh(
        &self,
        net: NetworkType,
        data: [u8; 20],
    ) -> Result<T, ConversionError<Self::Error>> { ... }
    fn convert_tex(
        &self,
        net: NetworkType,
        data: [u8; 20],
    ) -> Result<T, ConversionError<Self::Error>> { ... }
}
Expand description

A trait for converter types that can project from a ZcashAddress into another type.

§Examples

use zcash_address::{ConversionError, Converter, UnsupportedAddress, ZcashAddress};
use zcash_protocol::consensus::NetworkType;

struct KeyFinder { }

impl KeyFinder {
    fn find_sapling_extfvk(&self, data: [u8; 43]) -> Option<[u8; 73]> {
        todo!()
    }
}

// Makes it possible to use a KeyFinder to find the Sapling extfvk that corresponds
// to a given ZcashAddress.
impl Converter<Option<[u8; 73]>> for KeyFinder {
    type Error = &'static str;

    fn convert_sapling(
        &self,
        net: NetworkType,
        data: [u8; 43],
    ) -> Result<Option<[u8; 73]>, ConversionError<Self::Error>> {
        Ok(self.find_sapling_extfvk(data))
    }
}

Required Associated Types§

Source

type Error

Conversion errors for the user type (e.g. failing to parse the data passed to Self::convert_sapling as a valid Sapling address).

Provided Methods§

Source

fn convert_sprout( &self, net: NetworkType, data: [u8; 64], ) -> Result<T, ConversionError<Self::Error>>

Source

fn convert_sapling( &self, net: NetworkType, data: [u8; 43], ) -> Result<T, ConversionError<Self::Error>>

Source

fn convert_unified( &self, net: NetworkType, data: Address, ) -> Result<T, ConversionError<Self::Error>>

Source

fn convert_transparent_p2pkh( &self, net: NetworkType, data: [u8; 20], ) -> Result<T, ConversionError<Self::Error>>

Source

fn convert_transparent_p2sh( &self, net: NetworkType, data: [u8; 20], ) -> Result<T, ConversionError<Self::Error>>

Source

fn convert_tex( &self, net: NetworkType, data: [u8; 20], ) -> Result<T, ConversionError<Self::Error>>

Implementors§