Define Magic newtype as `[u8; 4]`, not `u32`.
The magic value isn't a u32, it's a byte string, so specifying it as such avoids ambiguity about endianness.
This commit is contained in:
parent
00cc1284ae
commit
8a3cabc686
|
@ -9,7 +9,7 @@ pub const CURRENT_VERSION: Version = Version(170_007);
|
||||||
pub mod magics {
|
pub mod magics {
|
||||||
use super::*;
|
use super::*;
|
||||||
/// The production mainnet.
|
/// The production mainnet.
|
||||||
pub const MAINNET: Magic = Magic(0x6427e924);
|
pub const MAINNET: Magic = Magic([0x24, 0xe9, 0x27, 0x64]);
|
||||||
/// The testnet.
|
/// The testnet.
|
||||||
pub const TESTNET: Magic = Magic(0xbff91afa);
|
pub const TESTNET: Magic = Magic([0xfa, 0x1a, 0xf9, 0xbf]);
|
||||||
}
|
}
|
|
@ -329,7 +329,7 @@ impl ZcashSerialization for Message {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Write the header and then the body.
|
// Write the header and then the body.
|
||||||
writer.write_u32::<LittleEndian>(magic.0)?;
|
writer.write_all(&magic.0)?;
|
||||||
writer.write_all(command)?;
|
writer.write_all(command)?;
|
||||||
writer.write_u32::<LittleEndian>(body.len() as u32)?;
|
writer.write_u32::<LittleEndian>(body.len() as u32)?;
|
||||||
writer.write_all(&Sha256dChecksum::from(&body[..]).0)?;
|
writer.write_all(&Sha256dChecksum::from(&body[..]).0)?;
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
/// A magic number identifying the network.
|
/// A magic number identifying the network.
|
||||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||||
pub struct Magic(pub u32);
|
pub struct Magic(pub [u8; 4]);
|
||||||
|
|
||||||
/// A protocol version number.
|
/// A protocol version number.
|
||||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||||
|
|
Loading…
Reference in New Issue