diff --git a/components/zcash_address/src/kind/unified.rs b/components/zcash_address/src/kind/unified.rs index 1c499ff89..2360c201f 100644 --- a/components/zcash_address/src/kind/unified.rs +++ b/components/zcash_address/src/kind/unified.rs @@ -116,3 +116,16 @@ impl fmt::Display for ParseError { } impl Error for ParseError {} + +mod private { + use super::{ParseError, Typecode}; + use std::{cmp, convert::TryFrom}; + + /// A raw address or viewing key. + pub trait SealedReceiver: + for<'a> TryFrom<(u32, &'a [u8]), Error = ParseError> + cmp::Ord + cmp::PartialOrd + Clone + { + fn typecode(&self) -> Typecode; + fn data(&self) -> &[u8]; + } +} diff --git a/components/zcash_address/src/kind/unified/address.rs b/components/zcash_address/src/kind/unified/address.rs index 708a83606..1c2dd19fa 100644 --- a/components/zcash_address/src/kind/unified/address.rs +++ b/components/zcash_address/src/kind/unified/address.rs @@ -1,4 +1,4 @@ -use super::{ParseError, Typecode}; +use super::{private::SealedReceiver, ParseError, Typecode}; use crate::kind; use std::cmp; @@ -39,7 +39,7 @@ pub enum Receiver { impl cmp::Ord for Receiver { fn cmp(&self, other: &Self) -> cmp::Ordering { match self.typecode().cmp(&other.typecode()) { - cmp::Ordering::Equal => self.addr().cmp(other.addr()), + cmp::Ordering::Equal => self.data().cmp(other.data()), res => res, } } @@ -71,7 +71,7 @@ impl TryFrom<(u32, &[u8])> for Receiver { } } -impl Receiver { +impl SealedReceiver for Receiver { fn typecode(&self) -> Typecode { match self { Receiver::P2pkh(_) => Typecode::P2pkh, @@ -82,7 +82,7 @@ impl Receiver { } } - fn addr(&self) -> &[u8] { + fn data(&self) -> &[u8] { match self { Receiver::P2pkh(data) => data, Receiver::P2sh(data) => data, @@ -199,7 +199,7 @@ impl Address { let mut writer = std::io::Cursor::new(Vec::new()); for receiver in &self.0 { - let addr = receiver.addr(); + let addr = receiver.data(); CompactSize::write( &mut writer, ::from(receiver.typecode()).try_into().unwrap(),