From bd948873444208767aa26b02c28b4775f09b1f7b Mon Sep 17 00:00:00 2001 From: Martin Habovstiak Date: Wed, 25 May 2022 08:41:59 +0200 Subject: [PATCH] Feature `use-serde` renamed to `serde` Features activating external crates are supposed to have same name as those crates. However we depend on same feature in other crates so we need a separate feature. After MSRV bump it is possible to rename the crates and features so we can now fix this inconsistency. Sadly, derive can't see that the crate was renamed so all derives must be told to use the other one. --- Cargo.toml | 7 ++++--- contrib/test.sh | 4 ++-- src/blockdata/block.rs | 2 ++ src/blockdata/transaction.rs | 3 +++ src/lib.rs | 4 ++-- src/serde_utils.rs | 2 ++ src/util/amount.rs | 5 +++++ src/util/ecdsa.rs | 1 + src/util/psbt/map/input.rs | 2 ++ src/util/psbt/map/output.rs | 2 ++ src/util/psbt/mod.rs | 1 + src/util/psbt/raw.rs | 3 +++ src/util/schnorr.rs | 3 +++ src/util/taproot.rs | 6 ++++++ 14 files changed, 38 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8a0e14e..f2298ea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ default = [ "std", "secp-recovery" ] base64 = [ "base64-compat" ] unstable = [] rand = ["secp256k1/rand-std"] -use-serde = ["serde", "bitcoin_hashes/serde", "secp256k1/serde"] +serde = ["actual-serde", "bitcoin_hashes/serde", "secp256k1/serde"] secp-lowmemory = ["secp256k1/lowmemory"] secp-recovery = ["secp256k1/recovery"] @@ -31,7 +31,7 @@ std = ["secp256k1/std", "bitcoin_hashes/std", "bech32/std"] no-std = ["hashbrown", "core2/alloc", "bitcoin_hashes/alloc", "secp256k1/alloc"] [package.metadata.docs.rs] -features = [ "std", "secp-recovery", "base64", "rand", "use-serde", "bitcoinconsensus" ] +features = [ "std", "secp-recovery", "base64", "rand", "serde", "bitcoinconsensus" ] rustdoc-args = ["--cfg", "docsrs"] [dependencies] @@ -42,7 +42,8 @@ core2 = { version = "0.3.0", optional = true, default-features = false } base64-compat = { version = "1.0.0", optional = true } bitcoinconsensus = { version = "0.19.0-3", optional = true } -serde = { version = "1", default-features = false, features = [ "derive", "alloc" ], optional = true } +# Do NOT use this as a feature! Use the `serde` feature instead. +actual-serde = { package = "serde", version = "1", default-features = false, features = [ "derive", "alloc" ], optional = true } hashbrown = { version = "0.8", optional = true } [dev-dependencies] diff --git a/contrib/test.sh b/contrib/test.sh index 676e26b..3a276fb 100755 --- a/contrib/test.sh +++ b/contrib/test.sh @@ -1,6 +1,6 @@ #!/bin/sh -ex -FEATURES="base64 bitcoinconsensus use-serde rand secp-recovery" +FEATURES="base64 bitcoinconsensus serde rand secp-recovery" # Use toolchain if explicitly specified if [ -n "$TOOLCHAIN" ] @@ -80,7 +80,7 @@ if [ "$AS_DEPENDENCY" = true ] then cargo new dep_test cd dep_test - echo 'bitcoin = { path = "..", features = ["use-serde"] }' >> Cargo.toml + echo 'bitcoin = { path = "..", features = ["serde"] }' >> Cargo.toml cargo test --verbose fi diff --git a/src/blockdata/block.rs b/src/blockdata/block.rs index 06a5329..260aaa7 100644 --- a/src/blockdata/block.rs +++ b/src/blockdata/block.rs @@ -41,6 +41,7 @@ use crate::VarInt; /// the actual transactions #[derive(Copy, PartialEq, Eq, Clone, Debug)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", serde(crate = "actual_serde"))] pub struct BlockHeader { /// The protocol version. Should always be 1. pub version: i32, @@ -159,6 +160,7 @@ impl BlockHeader { /// proof of work. #[derive(PartialEq, Eq, Clone, Debug)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", serde(crate = "actual_serde"))] pub struct Block { /// The block header pub header: BlockHeader, diff --git a/src/blockdata/transaction.rs b/src/blockdata/transaction.rs index c35a1b6..a50f6a8 100644 --- a/src/blockdata/transaction.rs +++ b/src/blockdata/transaction.rs @@ -190,6 +190,7 @@ impl ::core::str::FromStr for OutPoint { /// A transaction input, which defines old coins to be consumed #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", serde(crate = "actual_serde"))] pub struct TxIn { /// The reference to the previous output that is being used an an input. pub previous_output: OutPoint, @@ -223,6 +224,7 @@ impl Default for TxIn { /// A transaction output, which defines new coins to be created from old ones. #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", serde(crate = "actual_serde"))] pub struct TxOut { /// The value of the output, in satoshis. pub value: u64, @@ -269,6 +271,7 @@ impl Default for TxOut { /// for 0-input transactions, which results in unambiguously parseable transactions. #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", serde(crate = "actual_serde"))] pub struct Transaction { /// The protocol version, is currently expected to be 1 or 2 (BIP 68). pub version: i32, diff --git a/src/lib.rs b/src/lib.rs index 5382026..96bc90e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -32,7 +32,7 @@ //! * `base64` - (dependency), enables encoding of PSBTs and message signatures. //! * `unstable` - enables unstable features for testing. //! * `rand` - (dependency), makes it more convenient to generate random values. -//! * `use-serde` - (dependency), implements `serde`-based serialization and +//! * `serde` - (dependency), implements `serde`-based serialization and //! deserialization. //! * `secp-lowmemory` - optimizations for low-memory devices. //! * `no-std` - enables additional features required for this crate to be usable @@ -90,7 +90,7 @@ extern crate hashbrown; pub extern crate base64; #[cfg(feature="bitcoinconsensus")] extern crate bitcoinconsensus; -#[cfg(feature = "serde")] #[macro_use] extern crate serde; +#[cfg(feature = "serde")] #[macro_use] extern crate actual_serde as serde; #[cfg(all(test, feature = "serde"))] extern crate serde_json; #[cfg(all(test, feature = "serde"))] extern crate serde_test; #[cfg(all(test, feature = "serde"))] extern crate bincode; diff --git a/src/serde_utils.rs b/src/serde_utils.rs index 48b462e..5c8c7fb 100644 --- a/src/serde_utils.rs +++ b/src/serde_utils.rs @@ -152,6 +152,7 @@ pub mod btreemap_as_seq_byte_values { /// A custom key-value pair type that serialized the bytes as hex. #[derive(Debug, Deserialize)] + #[serde(crate = "actual_serde")] struct OwnedPair( T, #[serde(deserialize_with = "crate::serde_utils::hex_bytes::deserialize")] @@ -160,6 +161,7 @@ pub mod btreemap_as_seq_byte_values { /// A custom key-value pair type that serialized the bytes as hex. #[derive(Debug, Serialize)] + #[serde(crate = "actual_serde")] struct BorrowedPair<'a, T: 'static>( &'a T, #[serde(serialize_with = "crate::serde_utils::hex_bytes::serialize")] diff --git a/src/util/amount.rs b/src/util/amount.rs index eebca34..ad26453 100644 --- a/src/util/amount.rs +++ b/src/util/amount.rs @@ -1226,6 +1226,7 @@ pub mod serde { //! use bitcoin::Amount; //! //! #[derive(Serialize, Deserialize)] + //! # #[serde(crate = "actual_serde")] //! pub struct HasAmount { //! #[serde(with = "bitcoin::util::amount::serde::as_btc")] //! pub amount: Amount, @@ -1940,6 +1941,7 @@ mod tests { fn serde_as_sat() { #[derive(Serialize, Deserialize, PartialEq, Debug)] + #[serde(crate = "actual_serde")] struct T { #[serde(with = "crate::util::amount::serde::as_sat")] pub amt: Amount, @@ -1969,6 +1971,7 @@ mod tests { use serde_json; #[derive(Serialize, Deserialize, PartialEq, Debug)] + #[serde(crate = "actual_serde")] struct T { #[serde(with = "crate::util::amount::serde::as_btc")] pub amt: Amount, @@ -2003,6 +2006,7 @@ mod tests { use serde_json; #[derive(Serialize, Deserialize, PartialEq, Debug, Eq)] + #[serde(crate = "actual_serde")] struct T { #[serde(default, with = "crate::util::amount::serde::as_btc::opt")] pub amt: Option, @@ -2046,6 +2050,7 @@ mod tests { use serde_json; #[derive(Serialize, Deserialize, PartialEq, Debug, Eq)] + #[serde(crate = "actual_serde")] struct T { #[serde(default, with = "crate::util::amount::serde::as_sat::opt")] pub amt: Option, diff --git a/src/util/ecdsa.rs b/src/util/ecdsa.rs index 185b22f..dc0c834 100644 --- a/src/util/ecdsa.rs +++ b/src/util/ecdsa.rs @@ -27,6 +27,7 @@ use crate::EcdsaSighashType; /// An ECDSA signature with the corresponding hash type. #[derive(Debug, Copy, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", serde(crate = "actual_serde"))] pub struct EcdsaSig { /// The underlying ECDSA Signature pub sig: secp256k1::ecdsa::Signature, diff --git a/src/util/psbt/map/input.rs b/src/util/psbt/map/input.rs index a58c439..cd78a27 100644 --- a/src/util/psbt/map/input.rs +++ b/src/util/psbt/map/input.rs @@ -81,6 +81,7 @@ const PSBT_IN_PROPRIETARY: u8 = 0xFC; /// transaction. #[derive(Clone, Default, Debug, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", serde(crate = "actual_serde"))] pub struct Input { /// The non-witness transaction this input spends from. Should only be /// [std::option::Option::Some] for inputs which spend non-segwit outputs or @@ -153,6 +154,7 @@ pub struct Input { /// for converting to/from [`PsbtSighashType`] from/to the desired signature hash type they need. #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", serde(crate = "actual_serde"))] pub struct PsbtSighashType { pub (in crate::util::psbt) inner: u32, } diff --git a/src/util/psbt/map/output.rs b/src/util/psbt/map/output.rs index 08ba533..9c44ea7 100644 --- a/src/util/psbt/map/output.rs +++ b/src/util/psbt/map/output.rs @@ -49,6 +49,7 @@ const PSBT_OUT_PROPRIETARY: u8 = 0xFC; /// transaction. #[derive(Clone, Default, Debug, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", serde(crate = "actual_serde"))] pub struct Output { /// The redeem script for this output. pub redeem_script: Option