Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into diverse_accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
nuttycom committed Mar 6, 2024
2 parents a461a19 + 8130359 commit bc8e8f3
Show file tree
Hide file tree
Showing 62 changed files with 1,807 additions and 1,210 deletions.
16 changes: 15 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ members = [
"components/f4jumble",
"components/zcash_address",
"components/zcash_encoding",
"components/zcash_protocol",
"zcash_client_backend",
"zcash_client_sqlite",
"zcash_extensions",
Expand Down Expand Up @@ -32,6 +33,8 @@ zcash_address = { version = "0.3", path = "components/zcash_address" }
zcash_client_backend = { version = "0.11", path = "zcash_client_backend" }
zcash_encoding = { version = "0.2", path = "components/zcash_encoding" }
zcash_keys = { version = "0.1", path = "zcash_keys" }
zcash_protocol = { version = "0.1", path = "components/zcash_protocol" }

zcash_note_encryption = "0.4"
zcash_primitives = { version = "0.14", path = "zcash_primitives", default-features = false }
zcash_proofs = { version = "0.14", path = "zcash_proofs", default-features = false }
Expand Down
7 changes: 7 additions & 0 deletions components/zcash_address/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ and this library adheres to Rust's notion of

## [Unreleased]

## [0.3.2] - 2024-03-06
### Added
- `zcash_address::convert`:
- `TryFromRawAddress::try_from_raw_tex`
- `TryFromAddress::try_from_tex`
- `ToAddress::from_tex`

## [0.3.1] - 2024-01-12
### Fixed
- Stubs for `zcash_address::convert` traits that are created by `rust-analyzer`
Expand Down
5 changes: 3 additions & 2 deletions components/zcash_address/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "zcash_address"
description = "Zcash address parsing and serialization"
version = "0.3.1"
version = "0.3.2"
authors = [
"Jack Grigg <[email protected]>",
]
Expand All @@ -22,7 +22,8 @@ rustdoc-args = ["--cfg", "docsrs"]
bech32 = "0.9"
bs58 = { version = "0.5", features = ["check"] }
f4jumble = { version = "0.1", path = "../f4jumble" }
zcash_encoding = { version = "0.2", path = "../zcash_encoding" }
zcash_protocol.workspace = true
zcash_encoding.workspace = true

[dev-dependencies]
assert_matches = "1.3.0"
Expand Down
27 changes: 27 additions & 0 deletions components/zcash_address/src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,13 @@ pub trait TryFromRawAddress: Sized {
"transparent P2SH",
)))
}

fn try_from_raw_tex(data: [u8; 20]) -> Result<Self, ConversionError<Self::Error>> {
let _ = data;
Err(ConversionError::Unsupported(UnsupportedAddress(
"transparent-source restricted P2PKH",
)))
}
}

/// A helper trait for converting a [`ZcashAddress`] into another type.
Expand Down Expand Up @@ -225,6 +232,13 @@ pub trait TryFromAddress: Sized {
"transparent P2SH",
)))
}

fn try_from_tex(net: Network, data: [u8; 20]) -> Result<Self, ConversionError<Self::Error>> {
let _ = (net, data);
Err(ConversionError::Unsupported(UnsupportedAddress(
"transparent-source restricted P2PKH",
)))
}
}

impl<T: TryFromRawAddress> TryFromAddress for (Network, T) {
Expand Down Expand Up @@ -261,6 +275,10 @@ impl<T: TryFromRawAddress> TryFromAddress for (Network, T) {
) -> Result<Self, ConversionError<Self::Error>> {
T::try_from_raw_transparent_p2sh(data).map(|addr| (net, addr))
}

fn try_from_tex(net: Network, data: [u8; 20]) -> Result<Self, ConversionError<Self::Error>> {
T::try_from_raw_tex(data).map(|addr| (net, addr))
}
}

/// A helper trait for converting another type into a [`ZcashAddress`].
Expand Down Expand Up @@ -304,6 +322,8 @@ pub trait ToAddress: private::Sealed {
fn from_transparent_p2pkh(net: Network, data: [u8; 20]) -> Self;

fn from_transparent_p2sh(net: Network, data: [u8; 20]) -> Self;

fn from_tex(net: Network, data: [u8; 20]) -> Self;
}

impl ToAddress for ZcashAddress {
Expand Down Expand Up @@ -353,6 +373,13 @@ impl ToAddress for ZcashAddress {
kind: AddressKind::P2sh(data),
}
}

fn from_tex(net: Network, data: [u8; 20]) -> Self {
ZcashAddress {
net,
kind: AddressKind::Tex(data),
}
}
}

mod private {
Expand Down
Loading

0 comments on commit bc8e8f3

Please sign in to comment.