diff --git a/Cargo.lock b/Cargo.lock index 453fccb0..098c9623 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -234,7 +234,7 @@ checksum = "acee9fd5073ab6b045a275b3e709c163dd36c90685219cb21804a147b58dba43" dependencies = [ "async-trait", "axum-core", - "bitflags", + "bitflags 1.3.2", "bytes", "futures-util", "http", @@ -352,7 +352,7 @@ version = "0.64.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4243e6031260db77ede97ad86c27e501d646a27ab57b59a574f725d98ab1fb4" dependencies = [ - "bitflags", + "bitflags 1.3.2", "cexpr", "clang-sys", "lazy_static", @@ -403,6 +403,22 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitflags" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5dd14596c0e5b954530d0e6f1fd99b89c03e313aa2086e8da4303701a09e1cf" + +[[package]] +name = "bitflags-serde-legacy" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfecf9fa72400de980120c09d7027140daa6541292245ff61a4ad3b89771680e" +dependencies = [ + "bitflags 2.0.1", + "serde", +] + [[package]] name = "bitvec" version = "1.0.1" @@ -735,7 +751,7 @@ checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" dependencies = [ "ansi_term 0.12.1", "atty", - "bitflags", + "bitflags 1.3.2", "strsim 0.8.0", "textwrap 0.11.0", "unicode-width", @@ -748,7 +764,7 @@ version = "3.2.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23b71c3ce99b7611011217b366d923f1d0a7e07a92bb2dbf1e84508c673ca3bd" dependencies = [ - "bitflags", + "bitflags 1.3.2", "clap_lex", "indexmap", "textwrap 0.15.0", @@ -1666,7 +1682,7 @@ version = "0.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ccf7f68c2995f392c49fffb4f95ae2c873297830eb25c6bc4c114ce8f4562acc" dependencies = [ - "bitflags", + "bitflags 1.3.2", "libc", "libgit2-sys", "log", @@ -2756,7 +2772,7 @@ version = "0.10.38" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c7ae222234c30df141154f159066c5093ff73b63204dcda7121eb082fc56a95" dependencies = [ - "bitflags", + "bitflags 1.3.2", "cfg-if 1.0.0", "foreign-types", "libc", @@ -3234,7 +3250,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12e6c80c1139113c28ee4670dc50cc42915228b51f56a9e407f0ec60f966646f" dependencies = [ "bit-set", - "bitflags", + "bitflags 1.3.2", "byteorder", "lazy_static", "num-traits", @@ -3475,7 +3491,7 @@ version = "10.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "929f54e29691d4e6a9cc558479de70db7aa3d98cd6fe7ab86d7507aa2886b9d2" dependencies = [ - "bitflags", + "bitflags 1.3.2", ] [[package]] @@ -3557,7 +3573,7 @@ version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8380fe0152551244f0747b1bf41737e0f8a74f97a14ccefd1148187271634f3c" dependencies = [ - "bitflags", + "bitflags 1.3.2", ] [[package]] @@ -3699,7 +3715,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "88073939a61e5b7680558e6be56b419e208420c2adb92be54921fa6b72283f1a" dependencies = [ "base64 0.13.0", - "bitflags", + "bitflags 1.3.2", "serde", ] @@ -3745,7 +3761,7 @@ version = "0.36.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4fdebc4b395b7fbb9ab11e462e20ed9051e7b16e42d24042c776eca0ac81b03" dependencies = [ - "bitflags", + "bitflags 1.3.2", "errno", "io-lifetimes", "libc", @@ -3868,7 +3884,7 @@ version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dc14f172faf8a0194a3aded622712b0de276821addc574fa54fc0a1167e10dc" dependencies = [ - "bitflags", + "bitflags 1.3.2", "core-foundation", "core-foundation-sys", "libc", @@ -4753,7 +4769,7 @@ version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c530c8675c1dbf98facee631536fa116b5fb6382d7dd6dc1b118d970eafe3ba" dependencies = [ - "bitflags", + "bitflags 1.3.2", "bytes", "futures-core", "futures-util", @@ -5683,7 +5699,8 @@ dependencies = [ name = "zebra-chain" version = "1.0.0-beta.21" dependencies = [ - "bitflags", + "bitflags 2.0.1", + "bitflags-serde-legacy", "bitvec", "blake2b_simd", "blake2s_simd", @@ -5787,7 +5804,7 @@ dependencies = [ name = "zebra-network" version = "1.0.0-beta.21" dependencies = [ - "bitflags", + "bitflags 2.0.1", "byteorder", "bytes", "chrono", diff --git a/zebra-chain/Cargo.toml b/zebra-chain/Cargo.toml index 6bd44173..9eb1f62d 100644 --- a/zebra-chain/Cargo.toml +++ b/zebra-chain/Cargo.toml @@ -34,7 +34,8 @@ bench = ["zebra-test"] # Cryptography bitvec = "1.0.1" -bitflags = "1.3.2" +bitflags = "2.0.1" +bitflags-serde-legacy = "0.1.0" blake2b_simd = "1.0.1" blake2s_simd = "1.0.1" bs58 = { version = "0.4.0", features = ["check"] } diff --git a/zebra-chain/src/orchard/shielded_data.rs b/zebra-chain/src/orchard/shielded_data.rs index 6b60a982..dc55d19a 100644 --- a/zebra-chain/src/orchard/shielded_data.rs +++ b/zebra-chain/src/orchard/shielded_data.rs @@ -223,7 +223,7 @@ bitflags! { /// /// ([`bitflags`](https://docs.rs/bitflags/1.2.1/bitflags/index.html) restricts its values to the /// set of valid flags) - #[derive(Deserialize, Serialize)] + #[derive(Copy, Clone, Debug, PartialEq, Eq)] pub struct Flags: u8 { /// Enable spending non-zero valued Orchard notes. /// @@ -234,6 +234,28 @@ bitflags! { } } +// We use the `bitflags 2.x` library to implement [`Flags`]. The +// `2.x` version of the library uses a different serialization +// format compared to `1.x`. +// This manual implementation uses the `bitflags_serde_legacy` crate +// to serialize `Flags` as `bitflags 1.x` would. +impl serde::Serialize for Flags { + fn serialize(&self, serializer: S) -> Result { + bitflags_serde_legacy::serialize(self, "Flags", serializer) + } +} + +// We use the `bitflags 2.x` library to implement [`Flags`]. The +// `2.x` version of the library uses a different deserialization +// format compared to `1.x`. +// This manual implementation uses the `bitflags_serde_legacy` crate +// to deserialize `Flags` as `bitflags 1.x` would. +impl<'de> serde::Deserialize<'de> for Flags { + fn deserialize>(deserializer: D) -> Result { + bitflags_serde_legacy::deserialize("Flags", deserializer) + } +} + impl ZcashSerialize for Flags { fn zcash_serialize(&self, mut writer: W) -> Result<(), io::Error> { writer.write_u8(self.bits())?; diff --git a/zebra-chain/src/transaction/sighash.rs b/zebra-chain/src/transaction/sighash.rs index 354430ed..ae0171b5 100644 --- a/zebra-chain/src/transaction/sighash.rs +++ b/zebra-chain/src/transaction/sighash.rs @@ -10,13 +10,14 @@ static ZIP143_EXPLANATION: &str = "Invalid transaction version: after Overwinter bitflags::bitflags! { /// The different SigHash types, as defined in + #[derive(Copy, Clone, Debug, PartialEq, Eq)] pub struct HashType: u32 { /// Sign all the outputs const ALL = 0b0000_0001; /// Sign none of the outputs - anyone can spend const NONE = 0b0000_0010; /// Sign one of the outputs - anyone can spend the rest - const SINGLE = Self::ALL.bits | Self::NONE.bits; + const SINGLE = Self::ALL.bits() | Self::NONE.bits(); /// Anyone can add inputs to this transaction const ANYONECANPAY = 0b1000_0000; } diff --git a/zebra-network/Cargo.toml b/zebra-network/Cargo.toml index 4ac3a4c9..fd20e0f8 100644 --- a/zebra-network/Cargo.toml +++ b/zebra-network/Cargo.toml @@ -14,7 +14,7 @@ default = [] proptest-impl = ["proptest", "proptest-derive", "zebra-chain/proptest-impl"] [dependencies] -bitflags = "1.3.2" +bitflags = "2.0.1" byteorder = "1.4.3" bytes = "1.4.0" chrono = { version = "0.4.24", default-features = false, features = ["clock", "std"] } diff --git a/zebra-network/src/protocol/external/types.rs b/zebra-network/src/protocol/external/types.rs index ffa881a5..8cf65765 100644 --- a/zebra-network/src/protocol/external/types.rs +++ b/zebra-network/src/protocol/external/types.rs @@ -121,7 +121,7 @@ bitflags! { /// /// Note that bits 24-31 are reserved for temporary experiments; other /// service bits should be allocated via the ZIP process. - #[derive(Default)] + #[derive(Copy, Clone, Debug, Default, Hash, PartialEq, Eq, PartialOrd, Ord)] pub struct PeerServices: u64 { /// NODE_NETWORK means that the node is a full node capable of serving /// blocks, as opposed to a light client that makes network requests but