Move HRPs into from public Unified trait to SealedContainer trait.
Co-authored-by: Jack Grigg <jack@electriccoin.co>
This commit is contained in:
parent
b8ff3d2d48
commit
c31db1b839
|
@ -2,7 +2,7 @@ use std::{convert::TryInto, error::Error, fmt, str::FromStr};
|
|||
|
||||
use bech32::{self, FromBase32, ToBase32, Variant};
|
||||
|
||||
use crate::kind::unified::Unified;
|
||||
use crate::kind::unified::{private::SealedContainer, Unified};
|
||||
use crate::{kind::*, AddressKind, Network, ZcashAddress};
|
||||
|
||||
/// An error while attempting to parse a string as a Zcash address.
|
||||
|
|
|
@ -123,7 +123,7 @@ impl fmt::Display for ParseError {
|
|||
|
||||
impl Error for ParseError {}
|
||||
|
||||
mod private {
|
||||
pub(crate) mod private {
|
||||
use super::{ParseError, Typecode};
|
||||
use std::{cmp, convert::TryFrom};
|
||||
|
||||
|
@ -136,6 +136,10 @@ mod private {
|
|||
}
|
||||
|
||||
pub trait SealedContainer {
|
||||
const MAINNET: &'static str;
|
||||
const TESTNET: &'static str;
|
||||
const REGTEST: &'static str;
|
||||
|
||||
type Receiver: SealedReceiver;
|
||||
|
||||
fn from_inner(receivers: Vec<Self::Receiver>) -> Self;
|
||||
|
@ -146,10 +150,6 @@ use private::SealedReceiver;
|
|||
|
||||
/// Trait providing common encoding logic for Unified containers.
|
||||
pub trait Unified: private::SealedContainer + std::marker::Sized {
|
||||
const MAINNET: &'static str;
|
||||
const TESTNET: &'static str;
|
||||
const REGTEST: &'static str;
|
||||
|
||||
fn try_from_bytes(hrp: &str, buf: &[u8]) -> Result<Self, ParseError> {
|
||||
fn read_receiver<R: SealedReceiver>(
|
||||
mut cursor: &mut std::io::Cursor<&[u8]>,
|
||||
|
|
|
@ -76,14 +76,6 @@ impl SealedReceiver for Receiver {
|
|||
pub struct Address(pub(crate) Vec<Receiver>);
|
||||
|
||||
impl super::private::SealedContainer for Address {
|
||||
type Receiver = Receiver;
|
||||
|
||||
fn from_inner(receivers: Vec<Self::Receiver>) -> Self {
|
||||
Self(receivers)
|
||||
}
|
||||
}
|
||||
|
||||
impl super::Unified for Address {
|
||||
/// The HRP for a Bech32m-encoded mainnet Unified Address.
|
||||
///
|
||||
/// Defined in [ZIP 316][zip-0316].
|
||||
|
@ -101,6 +93,14 @@ impl super::Unified for Address {
|
|||
/// The HRP for a Bech32m-encoded regtest Unified Address.
|
||||
const REGTEST: &'static str = "uregtest";
|
||||
|
||||
type Receiver = Receiver;
|
||||
|
||||
fn from_inner(receivers: Vec<Self::Receiver>) -> Self {
|
||||
Self(receivers)
|
||||
}
|
||||
}
|
||||
|
||||
impl super::Unified for Address {
|
||||
/// Returns the receivers contained within this address, in the order they were
|
||||
/// parsed from the string encoding.
|
||||
///
|
||||
|
@ -117,7 +117,7 @@ pub(crate) mod test_vectors;
|
|||
mod tests {
|
||||
use assert_matches::assert_matches;
|
||||
|
||||
use crate::kind::unified::Unified;
|
||||
use crate::kind::unified::{private::SealedContainer, Unified};
|
||||
use proptest::{
|
||||
array::{uniform11, uniform20, uniform32},
|
||||
prelude::*,
|
||||
|
|
Loading…
Reference in New Issue