diff --git a/Cargo.lock b/Cargo.lock index 9f28140b..f7282ab9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -196,6 +196,9 @@ name = "bs58" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b170cd256a3f9fa6b9edae3e44a7dfdfc77e8124dbc3e2612d75f9c3e2396dae" +dependencies = [ + "sha2", +] [[package]] name = "byte-tools" diff --git a/zebra-chain/Cargo.toml b/zebra-chain/Cargo.toml index f0a487ef..3a51c78b 100644 --- a/zebra-chain/Cargo.toml +++ b/zebra-chain/Cargo.toml @@ -8,7 +8,7 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -bs58 = "0.3.0" +bs58 = { version = "0.3", features = ["check"] } byteorder = "1.3" chrono = "0.4" futures = "0.3" diff --git a/zebra-chain/src/addresses.rs b/zebra-chain/src/addresses.rs index b9d0d32c..9373f545 100644 --- a/zebra-chain/src/addresses.rs +++ b/zebra-chain/src/addresses.rs @@ -107,7 +107,7 @@ impl fmt::Debug for TransparentAddress { let _ = self.zcash_serialize(&mut bytes); f.debug_tuple("TransparentAddress") - .field(&bs58::encode(bytes.get_ref()).into_string()) + .field(&bs58::encode(bytes.get_ref()).with_check().into_string()) .finish() } } @@ -146,6 +146,7 @@ impl ZcashSerialize for TransparentAddress { writer.write_all(&pub_key_hash.0)? } } + Ok(()) } } @@ -181,3 +182,41 @@ impl ZcashDeserialize for TransparentAddress { } } } + +#[cfg(test)] +mod tests { + + use secp256k1::PublicKey; + + use crate::types::Script; + + use super::*; + + #[test] + fn pubkey() { + let pub_key = PublicKey::from_slice(&[ + 3, 23, 183, 225, 206, 31, 159, 148, 195, 42, 67, 115, 146, 41, 248, 140, 11, 3, 51, 41, + 111, 180, 110, 143, 114, 134, 88, 73, 198, 174, 52, 184, 78, + ]) + .expect("A PublicKey from slice"); + + let t_addr = TransparentAddress::from(pub_key); + + assert_eq!( + format!("{:?}", t_addr), + "TransparentAddress(\"t1bmMa1wJDFdbc2TiURQP5BbBz6jHjUBuHq\")" + ); + } + + #[test] + fn empty_script() { + let script = Script(vec![0; 20]); + + let t_addr = TransparentAddress::from(script); + + assert_eq!( + format!("{:?}", t_addr), + "TransparentAddress(\"t3Y5pHwfgHbS6pDjj1HLuMFxhFFip1fcJ6g\")" + ); + } +}