Remove standalone Orchard address Display, FromStr impls and related parts
NU5 proposes Unified Addresses, which would supplant any classic standalone pool address for Orchard. https://github.com/ZcashFoundation/zebra/pull/1885#discussion_r607000460
This commit is contained in:
parent
72491df4ff
commit
48674a9749
|
@ -1,28 +1,14 @@
|
||||||
//! Orchard shielded payment addresses.
|
//! Orchard shielded payment addresses.
|
||||||
|
|
||||||
use std::{
|
use std::fmt;
|
||||||
fmt,
|
|
||||||
io::{self, Read, Write},
|
|
||||||
};
|
|
||||||
|
|
||||||
use bech32::{self, FromBase32, ToBase32, Variant};
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
use proptest::prelude::*;
|
use proptest::prelude::*;
|
||||||
|
|
||||||
use crate::{
|
use crate::parameters::Network;
|
||||||
parameters::Network,
|
|
||||||
serialization::{ReadZcashExt, SerializationError},
|
|
||||||
};
|
|
||||||
|
|
||||||
use super::keys;
|
use super::keys;
|
||||||
|
|
||||||
/// Human-Readable Parts for input to bech32 encoding.
|
|
||||||
mod human_readable_parts {
|
|
||||||
pub const MAINNET: &str = "zo";
|
|
||||||
pub const TESTNET: &str = "ztestorchard";
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A Orchard _shielded payment address_.
|
/// A Orchard _shielded payment address_.
|
||||||
///
|
///
|
||||||
/// Also known as a _diversified payment address_ for Orchard, as
|
/// Also known as a _diversified payment address_ for Orchard, as
|
||||||
|
@ -46,50 +32,6 @@ impl fmt::Debug for Address {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for Address {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
||||||
let mut bytes = io::Cursor::new(Vec::new());
|
|
||||||
|
|
||||||
let _ = bytes.write_all(&<[u8; 11]>::from(self.diversifier));
|
|
||||||
let _ = bytes.write_all(&<[u8; 32]>::from(self.transmission_key));
|
|
||||||
|
|
||||||
let hrp = match self.network {
|
|
||||||
Network::Mainnet => human_readable_parts::MAINNET,
|
|
||||||
Network::Testnet => human_readable_parts::TESTNET,
|
|
||||||
};
|
|
||||||
|
|
||||||
bech32::encode_to_fmt(f, hrp, bytes.get_ref().to_base32(), Variant::Bech32).unwrap()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl std::str::FromStr for Address {
|
|
||||||
type Err = SerializationError;
|
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
||||||
match bech32::decode(s) {
|
|
||||||
Ok((hrp, bytes, Variant::Bech32)) => {
|
|
||||||
let mut decoded_bytes = io::Cursor::new(Vec::<u8>::from_base32(&bytes).unwrap());
|
|
||||||
|
|
||||||
let mut diversifier_bytes = [0; 11];
|
|
||||||
decoded_bytes.read_exact(&mut diversifier_bytes)?;
|
|
||||||
|
|
||||||
let transmission_key_bytes = decoded_bytes.read_32_bytes()?;
|
|
||||||
|
|
||||||
Ok(Address {
|
|
||||||
network: match hrp.as_str() {
|
|
||||||
human_readable_parts::MAINNET => Network::Mainnet,
|
|
||||||
human_readable_parts::TESTNET => Network::Testnet,
|
|
||||||
_ => return Err(SerializationError::Parse("unknown network")),
|
|
||||||
},
|
|
||||||
diversifier: keys::Diversifier::from(diversifier_bytes),
|
|
||||||
transmission_key: keys::TransmissionKey::from(transmission_key_bytes),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
_ => Err(SerializationError::Parse("bech32 decoding error")),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
impl Arbitrary for Address {
|
impl Arbitrary for Address {
|
||||||
type Parameters = ();
|
type Parameters = ();
|
||||||
|
@ -141,19 +83,3 @@ mod tests {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
proptest! {
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn orchard_address_roundtrip(zaddr in any::<Address>()) {
|
|
||||||
zebra_test::init();
|
|
||||||
|
|
||||||
let string = zaddr.to_string();
|
|
||||||
|
|
||||||
let zaddr2 = string.parse::<Address>()
|
|
||||||
.expect("randomized orchard z-addr should deserialize");
|
|
||||||
|
|
||||||
prop_assert_eq![zaddr, zaddr2];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue