Skip to content

Commit 77ee454

Browse files
author
ChallengeDev210
committed
Merge rust-bitcoin/rust-bitcoin#1006: Feature use-serde renamed to serde
2e7effc Feature `use-serde` renamed to `serde` (Martin Habovstiak) Pull request description: 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. Replaces #373 ACKs for top commit: apoelstra: ACK 2e7effc Tree-SHA512: b20364b9e8f30c2269bef915e821b2b2ec929e71dd0e88af2bc3a021821f87011d35e095cb8efe99add77a23dde940a17537eb387fb4582b05c57c8679969eb0
2 parents 4e08c43 + bd94887 commit 77ee454

File tree

14 files changed

+38
-7
lines changed

14 files changed

+38
-7
lines changed

Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ edition = "2018"
1717
default = [ "std", "secp-recovery" ]
1818
unstable = []
1919
rand = ["secp256k1/rand-std"]
20-
use-serde = ["serde", "bitcoin_hashes/serde", "secp256k1/serde"]
20+
serde = ["actual-serde", "bitcoin_hashes/serde", "secp256k1/serde"]
2121
secp-lowmemory = ["secp256k1/lowmemory"]
2222
secp-recovery = ["secp256k1/recovery"]
2323

@@ -30,7 +30,7 @@ std = ["secp256k1/std", "bitcoin_hashes/std", "bech32/std"]
3030
no-std = ["hashbrown", "core2/alloc", "bitcoin_hashes/alloc", "secp256k1/alloc"]
3131

3232
[package.metadata.docs.rs]
33-
features = [ "std", "secp-recovery", "base64", "rand", "use-serde", "bitcoinconsensus" ]
33+
features = [ "std", "secp-recovery", "base64", "rand", "serde", "bitcoinconsensus" ]
3434
rustdoc-args = ["--cfg", "docsrs"]
3535

3636
[dependencies]
@@ -41,7 +41,8 @@ core2 = { version = "0.3.0", optional = true, default-features = false }
4141

4242
base64 = { version = "0.13.0", optional = true }
4343
bitcoinconsensus = { version = "0.19.0-3", optional = true }
44-
serde = { version = "1", default-features = false, features = [ "derive", "alloc" ], optional = true }
44+
# Do NOT use this as a feature! Use the `serde` feature instead.
45+
actual-serde = { package = "serde", version = "1", default-features = false, features = [ "derive", "alloc" ], optional = true }
4546
hashbrown = { version = "0.8", optional = true }
4647

4748
[dev-dependencies]

contrib/test.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh -ex
22

3-
FEATURES="base64 bitcoinconsensus use-serde rand secp-recovery"
3+
FEATURES="base64 bitcoinconsensus serde rand secp-recovery"
44

55
# Use toolchain if explicitly specified
66
if [ -n "$TOOLCHAIN" ]
@@ -80,7 +80,7 @@ if [ "$AS_DEPENDENCY" = true ]
8080
then
8181
cargo new dep_test
8282
cd dep_test
83-
echo 'bitcoin = { path = "..", features = ["use-serde"] }' >> Cargo.toml
83+
echo 'bitcoin = { path = "..", features = ["serde"] }' >> Cargo.toml
8484

8585
cargo test --verbose
8686
fi

src/blockdata/block.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ use crate::VarInt;
4141
/// the actual transactions
4242
#[derive(Copy, PartialEq, Eq, Clone, Debug)]
4343
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
44+
#[cfg_attr(feature = "serde", serde(crate = "actual_serde"))]
4445
pub struct BlockHeader {
4546
/// The protocol version. Should always be 1.
4647
pub version: i32,
@@ -159,6 +160,7 @@ impl BlockHeader {
159160
/// proof of work.
160161
#[derive(PartialEq, Eq, Clone, Debug)]
161162
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
163+
#[cfg_attr(feature = "serde", serde(crate = "actual_serde"))]
162164
pub struct Block {
163165
/// The block header
164166
pub header: BlockHeader,

src/blockdata/transaction.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ impl ::core::str::FromStr for OutPoint {
191191
/// A transaction input, which defines old coins to be consumed
192192
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
193193
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
194+
#[cfg_attr(feature = "serde", serde(crate = "actual_serde"))]
194195
pub struct TxIn {
195196
/// The reference to the previous output that is being used an an input.
196197
pub previous_output: OutPoint,
@@ -224,6 +225,7 @@ impl Default for TxIn {
224225
/// A transaction output, which defines new coins to be created from old ones.
225226
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
226227
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
228+
#[cfg_attr(feature = "serde", serde(crate = "actual_serde"))]
227229
pub struct TxOut {
228230
/// The value of the output, in satoshis.
229231
pub value: u64,
@@ -270,6 +272,7 @@ impl Default for TxOut {
270272
/// for 0-input transactions, which results in unambiguously parseable transactions.
271273
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
272274
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
275+
#[cfg_attr(feature = "serde", serde(crate = "actual_serde"))]
273276
pub struct Transaction {
274277
/// The protocol version, is currently expected to be 1 or 2 (BIP 68).
275278
pub version: i32,

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
//! * `base64` - (dependency), enables encoding of PSBTs and message signatures.
3333
//! * `unstable` - enables unstable features for testing.
3434
//! * `rand` - (dependency), makes it more convenient to generate random values.
35-
//! * `use-serde` - (dependency), implements `serde`-based serialization and
35+
//! * `serde` - (dependency), implements `serde`-based serialization and
3636
//! deserialization.
3737
//! * `secp-lowmemory` - optimizations for low-memory devices.
3838
//! * `no-std` - enables additional features required for this crate to be usable
@@ -90,7 +90,7 @@ extern crate hashbrown;
9090
pub extern crate base64;
9191

9292
#[cfg(feature="bitcoinconsensus")] extern crate bitcoinconsensus;
93-
#[cfg(feature = "serde")] #[macro_use] extern crate serde;
93+
#[cfg(feature = "serde")] #[macro_use] extern crate actual_serde as serde;
9494
#[cfg(all(test, feature = "serde"))] extern crate serde_json;
9595
#[cfg(all(test, feature = "serde"))] extern crate serde_test;
9696
#[cfg(all(test, feature = "serde"))] extern crate bincode;

src/serde_utils.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ pub mod btreemap_as_seq_byte_values {
152152

153153
/// A custom key-value pair type that serialized the bytes as hex.
154154
#[derive(Debug, Deserialize)]
155+
#[serde(crate = "actual_serde")]
155156
struct OwnedPair<T>(
156157
T,
157158
#[serde(deserialize_with = "crate::serde_utils::hex_bytes::deserialize")]
@@ -160,6 +161,7 @@ pub mod btreemap_as_seq_byte_values {
160161

161162
/// A custom key-value pair type that serialized the bytes as hex.
162163
#[derive(Debug, Serialize)]
164+
#[serde(crate = "actual_serde")]
163165
struct BorrowedPair<'a, T: 'static>(
164166
&'a T,
165167
#[serde(serialize_with = "crate::serde_utils::hex_bytes::serialize")]

src/util/amount.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,6 +1262,7 @@ pub mod serde {
12621262
//! use bitcoin::Amount;
12631263
//!
12641264
//! #[derive(Serialize, Deserialize)]
1265+
//! # #[serde(crate = "actual_serde")]
12651266
//! pub struct HasAmount {
12661267
//! #[serde(with = "bitcoin::util::amount::serde::as_btc")]
12671268
//! pub amount: Amount,
@@ -1976,6 +1977,7 @@ mod tests {
19761977
fn serde_as_sat() {
19771978

19781979
#[derive(Serialize, Deserialize, PartialEq, Debug)]
1980+
#[serde(crate = "actual_serde")]
19791981
struct T {
19801982
#[serde(with = "crate::util::amount::serde::as_sat")]
19811983
pub amt: Amount,
@@ -2005,6 +2007,7 @@ mod tests {
20052007
use serde_json;
20062008

20072009
#[derive(Serialize, Deserialize, PartialEq, Debug)]
2010+
#[serde(crate = "actual_serde")]
20082011
struct T {
20092012
#[serde(with = "crate::util::amount::serde::as_btc")]
20102013
pub amt: Amount,
@@ -2039,6 +2042,7 @@ mod tests {
20392042
use serde_json;
20402043

20412044
#[derive(Serialize, Deserialize, PartialEq, Debug, Eq)]
2045+
#[serde(crate = "actual_serde")]
20422046
struct T {
20432047
#[serde(default, with = "crate::util::amount::serde::as_btc::opt")]
20442048
pub amt: Option<Amount>,
@@ -2082,6 +2086,7 @@ mod tests {
20822086
use serde_json;
20832087

20842088
#[derive(Serialize, Deserialize, PartialEq, Debug, Eq)]
2089+
#[serde(crate = "actual_serde")]
20852090
struct T {
20862091
#[serde(default, with = "crate::util::amount::serde::as_sat::opt")]
20872092
pub amt: Option<Amount>,

src/util/ecdsa.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use crate::EcdsaSighashType;
2727
/// An ECDSA signature with the corresponding hash type.
2828
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
2929
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
30+
#[cfg_attr(feature = "serde", serde(crate = "actual_serde"))]
3031
pub struct EcdsaSig {
3132
/// The underlying ECDSA Signature
3233
pub sig: secp256k1::ecdsa::Signature,

src/util/psbt/map/input.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ const PSBT_IN_PROPRIETARY: u8 = 0xFC;
8181
/// transaction.
8282
#[derive(Clone, Default, Debug, PartialEq, Eq)]
8383
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
84+
#[cfg_attr(feature = "serde", serde(crate = "actual_serde"))]
8485
pub struct Input {
8586
/// The non-witness transaction this input spends from. Should only be
8687
/// [std::option::Option::Some] for inputs which spend non-segwit outputs or
@@ -153,6 +154,7 @@ pub struct Input {
153154
/// for converting to/from [`PsbtSighashType`] from/to the desired signature hash type they need.
154155
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
155156
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
157+
#[cfg_attr(feature = "serde", serde(crate = "actual_serde"))]
156158
pub struct PsbtSighashType {
157159
pub (in crate::util::psbt) inner: u32,
158160
}

src/util/psbt/map/output.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ const PSBT_OUT_PROPRIETARY: u8 = 0xFC;
4949
/// transaction.
5050
#[derive(Clone, Default, Debug, PartialEq, Eq)]
5151
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
52+
#[cfg_attr(feature = "serde", serde(crate = "actual_serde"))]
5253
pub struct Output {
5354
/// The redeem script for this output.
5455
pub redeem_script: Option<Script>,
@@ -124,6 +125,7 @@ impl std::error::Error for IncompleteTapTree {
124125
/// Taproot Tree representing a finalized [`TaprootBuilder`] (a complete binary tree).
125126
#[derive(Clone, Debug)]
126127
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
128+
#[cfg_attr(feature = "serde", serde(crate = "actual_serde"))]
127129
pub struct TapTree(pub(crate) TaprootBuilder);
128130

129131
impl PartialEq for TapTree {

0 commit comments

Comments
 (0)