From b7458256af860472caf99abd5281fa874993d1f2 Mon Sep 17 00:00:00 2001 From: Velnbur Date: Thu, 30 May 2024 12:58:29 +0300 Subject: [PATCH 1/2] Add `const` modifier to `Magic::from_bytes` Resolves: rust-bitcoin/rust-bitcoin#2814 --- bitcoin/src/p2p/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bitcoin/src/p2p/mod.rs b/bitcoin/src/p2p/mod.rs index 42d49030b..a7bedce1f 100644 --- a/bitcoin/src/p2p/mod.rs +++ b/bitcoin/src/p2p/mod.rs @@ -223,7 +223,7 @@ impl Magic { pub const REGTEST: Self = Self([0xFA, 0xBF, 0xB5, 0xDA]); /// Create network magic from bytes. - pub fn from_bytes(bytes: [u8; 4]) -> Magic { Magic(bytes) } + pub const fn from_bytes(bytes: [u8; 4]) -> Magic { Magic(bytes) } /// Get network magic bytes. pub fn to_bytes(self) -> [u8; 4] { self.0 } From d2be969a513095815b545cc4cb38ad97943e2994 Mon Sep 17 00:00:00 2001 From: Velnbur Date: Thu, 30 May 2024 13:14:34 +0300 Subject: [PATCH 2/2] Add `const fn Magic::from_bytes` patch for API files To reflect changes from b7458256af860472caf99abd5281fa874993d1f2 --- api/bitcoin/all-features.txt | 2 +- api/bitcoin/default-features.txt | 2 +- api/bitcoin/no-features.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/api/bitcoin/all-features.txt b/api/bitcoin/all-features.txt index 695267b39..e9f5703ee 100644 --- a/api/bitcoin/all-features.txt +++ b/api/bitcoin/all-features.txt @@ -6368,6 +6368,7 @@ pub const fn bitcoin::blockdata::witness::Witness::new() -> Self pub const fn bitcoin::consensus::encode::VarInt::size(&self) -> usize pub const fn bitcoin::consensus::params::Params::new(network: bitcoin::network::Network) -> Self pub const fn bitcoin::network::Network::params(self) -> &'static bitcoin::consensus::params::Params +pub const fn bitcoin::p2p::Magic::from_bytes(bytes: [u8; 4]) -> bitcoin::p2p::Magic pub const fn bitcoin::transaction::predict_weight_from_slices(inputs: &[bitcoin::blockdata::transaction::InputWeightPrediction], output_script_lens: &[usize]) -> bitcoin_units::weight::Weight pub enum bitcoin::EcdsaSighashType pub enum bitcoin::NetworkKind @@ -8840,7 +8841,6 @@ pub fn bitcoin::p2p::Magic::consensus_encode bool pub fn bitcoin::p2p::Magic::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::result::Result<(), core::fmt::Error> pub fn bitcoin::p2p::Magic::from(network: bitcoin::network::Network) -> bitcoin::p2p::Magic -pub fn bitcoin::p2p::Magic::from_bytes(bytes: [u8; 4]) -> bitcoin::p2p::Magic pub fn bitcoin::p2p::Magic::from_params(params: impl core::convert::AsRef) -> Self pub fn bitcoin::p2p::Magic::from_str(s: &str) -> core::result::Result pub fn bitcoin::p2p::Magic::hash<__H: core::hash::Hasher>(&self, state: &mut __H) diff --git a/api/bitcoin/default-features.txt b/api/bitcoin/default-features.txt index 373ec1fe5..7d367b006 100644 --- a/api/bitcoin/default-features.txt +++ b/api/bitcoin/default-features.txt @@ -6067,6 +6067,7 @@ pub const fn bitcoin::blockdata::witness::Witness::new() -> Self pub const fn bitcoin::consensus::encode::VarInt::size(&self) -> usize pub const fn bitcoin::consensus::params::Params::new(network: bitcoin::network::Network) -> Self pub const fn bitcoin::network::Network::params(self) -> &'static bitcoin::consensus::params::Params +pub const fn bitcoin::p2p::Magic::from_bytes(bytes: [u8; 4]) -> bitcoin::p2p::Magic pub const fn bitcoin::transaction::predict_weight_from_slices(inputs: &[bitcoin::blockdata::transaction::InputWeightPrediction], output_script_lens: &[usize]) -> bitcoin_units::weight::Weight pub enum bitcoin::EcdsaSighashType pub enum bitcoin::NetworkKind @@ -8374,7 +8375,6 @@ pub fn bitcoin::p2p::Magic::consensus_encode bool pub fn bitcoin::p2p::Magic::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::result::Result<(), core::fmt::Error> pub fn bitcoin::p2p::Magic::from(network: bitcoin::network::Network) -> bitcoin::p2p::Magic -pub fn bitcoin::p2p::Magic::from_bytes(bytes: [u8; 4]) -> bitcoin::p2p::Magic pub fn bitcoin::p2p::Magic::from_params(params: impl core::convert::AsRef) -> Self pub fn bitcoin::p2p::Magic::from_str(s: &str) -> core::result::Result pub fn bitcoin::p2p::Magic::hash<__H: core::hash::Hasher>(&self, state: &mut __H) diff --git a/api/bitcoin/no-features.txt b/api/bitcoin/no-features.txt index ef75358df..3212a5f7e 100644 --- a/api/bitcoin/no-features.txt +++ b/api/bitcoin/no-features.txt @@ -5449,6 +5449,7 @@ pub const fn bitcoin::blockdata::witness::Witness::new() -> Self pub const fn bitcoin::consensus::encode::VarInt::size(&self) -> usize pub const fn bitcoin::consensus::params::Params::new(network: bitcoin::network::Network) -> Self pub const fn bitcoin::network::Network::params(self) -> &'static bitcoin::consensus::params::Params +pub const fn bitcoin::p2p::Magic::from_bytes(bytes: [u8; 4]) -> bitcoin::p2p::Magic pub const fn bitcoin::transaction::predict_weight_from_slices(inputs: &[bitcoin::blockdata::transaction::InputWeightPrediction], output_script_lens: &[usize]) -> bitcoin_units::weight::Weight pub enum bitcoin::EcdsaSighashType pub enum bitcoin::NetworkKind @@ -7707,7 +7708,6 @@ pub fn bitcoin::p2p::Magic::consensus_encode bool pub fn bitcoin::p2p::Magic::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::result::Result<(), core::fmt::Error> pub fn bitcoin::p2p::Magic::from(network: bitcoin::network::Network) -> bitcoin::p2p::Magic -pub fn bitcoin::p2p::Magic::from_bytes(bytes: [u8; 4]) -> bitcoin::p2p::Magic pub fn bitcoin::p2p::Magic::from_params(params: impl core::convert::AsRef) -> Self pub fn bitcoin::p2p::Magic::from_str(s: &str) -> core::result::Result pub fn bitcoin::p2p::Magic::hash<__H: core::hash::Hasher>(&self, state: &mut __H)