diff --git a/components/zcash_address/src/encoding.rs b/components/zcash_address/src/encoding.rs index ab7d7768b..aca51dce8 100644 --- a/components/zcash_address/src/encoding.rs +++ b/components/zcash_address/src/encoding.rs @@ -13,6 +13,14 @@ pub enum ParseError { NotZcash, } +impl From for ParseError { + fn from(e: unified::ParseError) -> Self { + match e { + unified::ParseError::InvalidEncoding => Self::InvalidEncoding, + } + } +} + impl fmt::Display for ParseError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { diff --git a/components/zcash_address/src/kind/unified.rs b/components/zcash_address/src/kind/unified.rs index c734ceecf..0a810b0ee 100644 --- a/components/zcash_address/src/kind/unified.rs +++ b/components/zcash_address/src/kind/unified.rs @@ -1,7 +1,9 @@ use std::convert::{TryFrom, TryInto}; +use std::error::Error; +use std::fmt; use std::iter; -use crate::{kind, ParseError}; +use crate::kind; mod f4jumble; @@ -57,6 +59,23 @@ impl From for u8 { } } +/// An error while attempting to parse a string as a Zcash address. +#[derive(Debug, PartialEq)] +pub enum ParseError { + /// The string is an invalid encoding. + InvalidEncoding, +} + +impl fmt::Display for ParseError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + ParseError::InvalidEncoding => write!(f, "Invalid encoding"), + } + } +} + +impl Error for ParseError {} + /// The set of known Receivers for Unified Addresses. /// /// This enum is an internal-only type, and is maintained in preference order, so that the