Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Daira-Emma Hopwood <[email protected]>
  • Loading branch information
nuttycom and daira authored Mar 5, 2024
1 parent 60494b9 commit 4992ff7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
4 changes: 3 additions & 1 deletion components/zcash_address/src/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ impl FromStr for ZcashAddress {
let net = match hrp.as_str() {
tex::MAINNET => Network::Main,
tex::TESTNET => Network::Test,
tex::REGTEST => Network::Regtest,
// Not recognized as a Zcash address type
_ => {
return Err(ParseError::NotZcash);
Expand Down Expand Up @@ -179,7 +180,8 @@ impl fmt::Display for ZcashAddress {
AddressKind::Tex(data) => encode_bech32(
match self.net {
Network::Main => tex::MAINNET,
Network::Test | Network::Regtest => tex::TESTNET,
Network::Test => tex::TESTNET,
Network::Regtest => tex::REGTEST,
},
data,
Variant::Bech32m,
Expand Down
8 changes: 6 additions & 2 deletions components/zcash_address/src/kind/tex.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
/// The prefix for a Base58Check-encoded mainnet transparent
/// The prefix for a Bech32m-encoded mainnet transparent
/// [ZIP 320](https://zips.z.cash/zip-0320.html) TEX address.
pub(crate) const MAINNET: &str = "tex";

/// The prefix for a Base58Check-encoded testnet transparent
/// The prefix for a Bech32m-encoded testnet transparent
/// [ZIP 320](https://zips.z.cash/zip-0320.html) TEX address.
pub(crate) const TESTNET: &str = "textest";

/// The prefix for a Bech32m-encoded regtest transparent
/// [ZIP 320](https://zips.z.cash/zip-0320.html) TEX address.
pub(crate) const REGTEST: &str = "texregtest";
3 changes: 3 additions & 0 deletions components/zcash_address/src/kind/unified.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,9 @@ pub(crate) mod private {
length
)));
}
// The "as usize" casts cannot change the values, because both
// cursor.position() and addr_end are u64 values <= buf.len()
// which is usize.
let data = &buf[cursor.position() as usize..addr_end as usize];
let result = match Typecode::try_from(typecode)? {
Typecode::Data(tc) => Item::Data(R::parse(tc, data)?),
Expand Down

0 comments on commit 4992ff7

Please sign in to comment.