Allow transparent-only unified addresses and viewing keys.
This commit is contained in:
parent
cab4d84464
commit
fa225d479a
|
@ -561,7 +561,6 @@ pub(crate) mod private {
|
||||||
) -> Result<Self, ParseError> {
|
) -> Result<Self, ParseError> {
|
||||||
assert!(u32::from(Typecode::P2SH) == u32::from(Typecode::P2PKH) + 1);
|
assert!(u32::from(Typecode::P2SH) == u32::from(Typecode::P2PKH) + 1);
|
||||||
|
|
||||||
let mut only_transparent = true;
|
|
||||||
let mut prev_code = None; // less than any Some
|
let mut prev_code = None; // less than any Some
|
||||||
for item in &items {
|
for item in &items {
|
||||||
let t = item.typecode();
|
let t = item.typecode();
|
||||||
|
@ -576,17 +575,12 @@ pub(crate) mod private {
|
||||||
return Err(ParseError::BothP2phkAndP2sh);
|
return Err(ParseError::BothP2phkAndP2sh);
|
||||||
} else {
|
} else {
|
||||||
prev_code = t_code;
|
prev_code = t_code;
|
||||||
only_transparent = only_transparent && item.is_transparent_data_item();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if only_transparent {
|
|
||||||
Err(ParseError::OnlyTransparent)
|
|
||||||
} else {
|
|
||||||
// All checks pass!
|
// All checks pass!
|
||||||
Ok(Self::from_inner(revision, items))
|
Ok(Self::from_inner(revision, items))
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fn parse_internal<T: Into<Vec<u8>>>(hrp: &str, buf: T) -> Result<Self, ParseError> {
|
fn parse_internal<T: Into<Vec<u8>>>(hrp: &str, buf: T) -> Result<Self, ParseError> {
|
||||||
Self::parse_items(hrp, buf)
|
Self::parse_items(hrp, buf)
|
||||||
|
|
|
@ -357,9 +357,6 @@ mod tests {
|
||||||
0xf4, 0xf5, 0x16, 0xef, 0x5c, 0xe0, 0x26, 0xbc, 0x23, 0x73, 0x76, 0x3f, 0x4b,
|
0xf4, 0xf5, 0x16, 0xef, 0x5c, 0xe0, 0x26, 0xbc, 0x23, 0x73, 0x76, 0x3f, 0x4b,
|
||||||
];
|
];
|
||||||
|
|
||||||
assert_eq!(
|
assert_matches!(Ufvk::parse_internal(Ufvk::MAINNET_R0, &encoded[..]), Ok(_));
|
||||||
Ufvk::parse_internal(Ufvk::MAINNET_R0, &encoded[..]),
|
|
||||||
Err(ParseError::OnlyTransparent)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -339,9 +339,6 @@ mod tests {
|
||||||
0xbd, 0xfe, 0xa4, 0xb7, 0x47, 0x20, 0x92, 0x6, 0xf0, 0x0, 0xf9, 0x64,
|
0xbd, 0xfe, 0xa4, 0xb7, 0x47, 0x20, 0x92, 0x6, 0xf0, 0x0, 0xf9, 0x64,
|
||||||
];
|
];
|
||||||
|
|
||||||
assert_eq!(
|
assert_matches!(Uivk::parse_internal(Uivk::MAINNET_R0, &encoded[..]), Ok(_));
|
||||||
Uivk::parse_internal(Uivk::MAINNET_R0, &encoded[..]),
|
|
||||||
Err(ParseError::OnlyTransparent)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -278,7 +278,10 @@ impl UnifiedAddress {
|
||||||
.chain(self.expiry_time.map(unified::MetadataItem::ExpiryTime));
|
.chain(self.expiry_time.map(unified::MetadataItem::ExpiryTime));
|
||||||
|
|
||||||
let ua = unified::Address::try_from_items(
|
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
|
Revision::R1
|
||||||
} else {
|
} else {
|
||||||
Revision::R0
|
Revision::R0
|
||||||
|
|
|
@ -855,7 +855,10 @@ impl UnifiedFullViewingKey {
|
||||||
.chain(self.expiry_time.map(unified::MetadataItem::ExpiryTime));
|
.chain(self.expiry_time.map(unified::MetadataItem::ExpiryTime));
|
||||||
|
|
||||||
zcash_address::unified::Ufvk::try_from_items(
|
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
|
Revision::R1
|
||||||
} else {
|
} else {
|
||||||
Revision::R0
|
Revision::R0
|
||||||
|
@ -901,12 +904,28 @@ impl UnifiedFullViewingKey {
|
||||||
self.sapling.as_ref()
|
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.
|
/// Returns the Orchard full viewing key component of this unified key.
|
||||||
#[cfg(feature = "orchard")]
|
#[cfg(feature = "orchard")]
|
||||||
pub fn orchard(&self) -> Option<&orchard::keys::FullViewingKey> {
|
pub fn orchard(&self) -> Option<&orchard::keys::FullViewingKey> {
|
||||||
self.orchard.as_ref()
|
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.
|
/// Returns any unknown data items parsed from the encoded form of the key.
|
||||||
pub fn unknown_data(&self) -> &[(u32, Vec<u8>)] {
|
pub fn unknown_data(&self) -> &[(u32, Vec<u8>)] {
|
||||||
self.unknown_data.as_ref()
|
self.unknown_data.as_ref()
|
||||||
|
|
Loading…
Reference in New Issue