From 8560baaca2b9463827353bbcea8b8778fba64b28 Mon Sep 17 00:00:00 2001 From: Riccardo Casatta Date: Tue, 25 Jul 2023 14:23:18 +0200 Subject: [PATCH] Make fields of RawNetworkMessage non public provide accessor method and new for downstream libs. This is done in order to more easily change the struct without impacting downstream and also in order to add another field while preserving struct invariant in future commit. --- bitcoin/src/network/message.rs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/bitcoin/src/network/message.rs b/bitcoin/src/network/message.rs index c083945d..3a1717bf 100644 --- a/bitcoin/src/network/message.rs +++ b/bitcoin/src/network/message.rs @@ -149,10 +149,8 @@ crate::error::impl_std_error!(CommandStringError); /// A Network message #[derive(Clone, Debug, PartialEq, Eq)] pub struct RawNetworkMessage { - /// Magic bytes to identify the network these messages are meant for - pub magic: Magic, - /// The actual message data - pub payload: NetworkMessage, + magic: Magic, + payload: NetworkMessage, } /// A Network message payload. Proper documentation is available on at @@ -302,6 +300,22 @@ impl NetworkMessage { } impl RawNetworkMessage { + + /// Creates a [RawNetworkMessage] + pub fn new(magic: Magic, payload: NetworkMessage) -> Self { + Self { magic, payload } + } + + /// The actual message data + pub fn payload(&self) -> &NetworkMessage { + &self.payload + } + + /// Magic bytes to identify the network these messages are meant for + pub fn magic(&self) -> &Magic { + &self.magic + } + /// Return the message command as a static string reference. /// /// This returns `"unknown"` for [NetworkMessage::Unknown],