Allow transparent-only unified addresses and viewing keys.

This commit is contained in:
Kris Nuttycombe 2024-04-22 12:27:31 -06:00
parent cab4d84464
commit 5e60c275b2
5 changed files with 12 additions and 18 deletions

View File

@ -561,7 +561,6 @@ pub(crate) mod private {
) -> Result<Self, ParseError> {
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<T: Into<Vec<u8>>>(hrp: &str, buf: T) -> Result<Self, ParseError> {

View File

@ -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(_));
}
}

View File

@ -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(_));
}
}

View File

@ -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

View File

@ -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.sapling.is_some() || self.orchard.is_some())
{
Revision::R1
} else {
Revision::R0