diff --git a/components/zcash_address/src/kind/unified.rs b/components/zcash_address/src/kind/unified.rs index 8d7042325..5600ad7a6 100644 --- a/components/zcash_address/src/kind/unified.rs +++ b/components/zcash_address/src/kind/unified.rs @@ -561,7 +561,6 @@ pub(crate) mod private { ) -> Result { assert!(u32::from(Typecode::P2SH) == u32::from(Typecode::P2PKH) + 1); - let mut only_transparent = true; let mut prev_code = None; // less than any Some for item in &items { let t = item.typecode(); @@ -576,16 +575,11 @@ pub(crate) mod private { return Err(ParseError::BothP2phkAndP2sh); } else { prev_code = t_code; - only_transparent = only_transparent && item.is_transparent_data_item(); } } - if only_transparent { - Err(ParseError::OnlyTransparent) - } else { - // All checks pass! - Ok(Self::from_inner(revision, items)) - } + // All checks pass! + Ok(Self::from_inner(revision, items)) } fn parse_internal>>(hrp: &str, buf: T) -> Result { diff --git a/components/zcash_address/src/kind/unified/fvk.rs b/components/zcash_address/src/kind/unified/fvk.rs index f12adcd96..643f78e40 100644 --- a/components/zcash_address/src/kind/unified/fvk.rs +++ b/components/zcash_address/src/kind/unified/fvk.rs @@ -357,9 +357,6 @@ mod tests { 0xf4, 0xf5, 0x16, 0xef, 0x5c, 0xe0, 0x26, 0xbc, 0x23, 0x73, 0x76, 0x3f, 0x4b, ]; - assert_eq!( - Ufvk::parse_internal(Ufvk::MAINNET_R0, &encoded[..]), - Err(ParseError::OnlyTransparent) - ); + assert_matches!(Ufvk::parse_internal(Ufvk::MAINNET_R0, &encoded[..]), Ok(_)); } } diff --git a/components/zcash_address/src/kind/unified/ivk.rs b/components/zcash_address/src/kind/unified/ivk.rs index 5abe1d20b..8d0c5c95e 100644 --- a/components/zcash_address/src/kind/unified/ivk.rs +++ b/components/zcash_address/src/kind/unified/ivk.rs @@ -339,9 +339,6 @@ mod tests { 0xbd, 0xfe, 0xa4, 0xb7, 0x47, 0x20, 0x92, 0x6, 0xf0, 0x0, 0xf9, 0x64, ]; - assert_eq!( - Uivk::parse_internal(Uivk::MAINNET_R0, &encoded[..]), - Err(ParseError::OnlyTransparent) - ); + assert_matches!(Uivk::parse_internal(Uivk::MAINNET_R0, &encoded[..]), Ok(_)); } } diff --git a/zcash_keys/src/address.rs b/zcash_keys/src/address.rs index 96353a085..e7b3ae966 100644 --- a/zcash_keys/src/address.rs +++ b/zcash_keys/src/address.rs @@ -278,7 +278,10 @@ impl UnifiedAddress { .chain(self.expiry_time.map(unified::MetadataItem::ExpiryTime)); let ua = unified::Address::try_from_items( - if self.expiry_height().is_some() || self.expiry_time().is_some() { + if self.expiry_height().is_some() + || self.expiry_time().is_some() + || !(self.has_orchard() || self.has_sapling()) + { Revision::R1 } else { Revision::R0 diff --git a/zcash_keys/src/keys.rs b/zcash_keys/src/keys.rs index 1c01c54ad..592217b94 100644 --- a/zcash_keys/src/keys.rs +++ b/zcash_keys/src/keys.rs @@ -855,7 +855,10 @@ impl UnifiedFullViewingKey { .chain(self.expiry_time.map(unified::MetadataItem::ExpiryTime)); zcash_address::unified::Ufvk::try_from_items( - if self.expiry_height().is_some() || self.expiry_time().is_some() { + if self.expiry_height().is_some() + || self.expiry_time().is_some() + || !(self.has_sapling() || self.has_orchard()) + { Revision::R1 } else { Revision::R0 @@ -901,12 +904,28 @@ impl UnifiedFullViewingKey { self.sapling.as_ref() } + /// Returns whether this UFVK contains a Sapling item. + pub fn has_sapling(&self) -> bool { + #[cfg(feature = "sapling")] + return self.sapling.is_some(); + #[cfg(not(feature = "sapling"))] + return false; + } + /// Returns the Orchard full viewing key component of this unified key. #[cfg(feature = "orchard")] pub fn orchard(&self) -> Option<&orchard::keys::FullViewingKey> { self.orchard.as_ref() } + /// Returns whether this UFVK contains an Orchard item. + pub fn has_orchard(&self) -> bool { + #[cfg(feature = "orchard")] + return self.orchard.is_some(); + #[cfg(not(feature = "orchard"))] + return false; + } + /// Returns any unknown data items parsed from the encoded form of the key. pub fn unknown_data(&self) -> &[(u32, Vec)] { self.unknown_data.as_ref()