diff --git a/zebra-network/Cargo.toml b/zebra-network/Cargo.toml index 5244c08f..cfd83a65 100644 --- a/zebra-network/Cargo.toml +++ b/zebra-network/Cargo.toml @@ -9,16 +9,19 @@ edition = "2018" [dependencies] bitflags = "1.2" -bytes = "0.4" -rand = "0.7" byteorder = "1.3" +bytes = "0.4" chrono = "0.4" thiserror = "1" serde = { version = "1", features = ["serde_derive"] } pin-project = "0.4" -# indexmap has rayon support for parallel iteration, +hex = "0.4" +# indexmap has rayon support for parallel iteration, # which we don't use, so disable it to drop the dependencies. indexmap = { version = "1.2", default-features = false } +pin-project = "0.4" +rand = "0.7" +serde = { version = "1", features = ["serde_derive"] } tokio = "=0.2.0-alpha.6" futures-preview = "=0.3.0-alpha.19" diff --git a/zebra-network/src/protocol/types.rs b/zebra-network/src/protocol/types.rs index 15e3feff..c1344e08 100644 --- a/zebra-network/src/protocol/types.rs +++ b/zebra-network/src/protocol/types.rs @@ -1,9 +1,18 @@ //! Newtype wrappers assigning semantic meaning to primitive types. +use hex; +use std::fmt; + /// A magic number identifying the network. -#[derive(Copy, Clone, Debug, Eq, PartialEq)] +#[derive(Copy, Clone, Eq, PartialEq)] pub struct Magic(pub [u8; 4]); +impl fmt::Debug for Magic { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_tuple("Magic").field(&hex::encode(&self.0)).finish() + } +} + /// A protocol version number. #[derive(Copy, Clone, Debug, Eq, PartialEq)] pub struct Version(pub u32); @@ -34,3 +43,15 @@ impl Default for Nonce { Self(thread_rng().gen()) } } + +#[cfg(test)] +mod tests { + + use crate::constants::magics; + + #[test] + fn magic_debug() { + assert_eq!(format!("{:?}", magics::MAINNET), "Magic(\"24e92764\")"); + assert_eq!(format!("{:?}", magics::TESTNET), "Magic(\"fa1af9bf\")"); + } +}