Merge rust-bitcoin/rust-bitcoin#1387: Add rand-std feature
941083ec4e
Remove rand-std dev-dependency from secp256k1 (Tobin C. Harding)f71335f971
Add rand-std feature (Tobin C. Harding) Pull request description: This PR uncovered incorrect feature gating in `secp256k1`, fixed in https://github.com/rust-bitcoin/rust-secp256k1/pull/519 Currently we enable "secp256k1/rand-std" in the "rand" feature, this is incorrect because it means "rand" implies "std" which it does not. Add a "rand-std" feature that turns on "seck256k1/rand-std" and make the "rand" feature turn on "seck256k1/rand". Fix: #1384 ACKs for top commit: sanket1729: ACK941083ec4e
apoelstra: ACK941083ec4e
Tree-SHA512: e1d12196766c2b3082b488fe7d0c03a865ebbfc70ffa6f128c57074df14da71e56c31ea92982991d376ac62fa86c6639049ce17aac93613b523ddcc99677c269
This commit is contained in:
commit
3b11ff6607
|
@ -15,7 +15,8 @@ edition = "2018"
|
|||
# Please don't forget to add relevant features to docs.rs below
|
||||
[features]
|
||||
default = [ "std", "secp-recovery" ]
|
||||
rand = ["secp256k1/rand-std"]
|
||||
rand-std = ["secp256k1/rand-std"]
|
||||
rand = ["secp256k1/rand"]
|
||||
serde = ["actual-serde", "bitcoin_hashes/serde", "secp256k1/serde"]
|
||||
secp-lowmemory = ["secp256k1/lowmemory"]
|
||||
secp-recovery = ["secp256k1/recovery"]
|
||||
|
@ -51,7 +52,7 @@ hashbrown = { version = "0.8", optional = true }
|
|||
serde_json = "1.0.0"
|
||||
serde_test = "1.0.19"
|
||||
serde_derive = "1.0.103"
|
||||
secp256k1 = { version = "0.25.0", features = [ "recovery", "rand-std" ] }
|
||||
secp256k1 = { version = "0.25.0", features = ["recovery"] }
|
||||
bincode = "1.3.1"
|
||||
|
||||
[target.'cfg(mutate)'.dev-dependencies]
|
||||
|
@ -62,7 +63,7 @@ name = "bip32"
|
|||
|
||||
[[example]]
|
||||
name = "handshake"
|
||||
required-features = ["std"]
|
||||
required-features = ["std", "rand-std"]
|
||||
|
||||
[[example]]
|
||||
name = "ecdsa-psbt"
|
||||
|
@ -70,4 +71,4 @@ required-features = ["std", "bitcoinconsensus"]
|
|||
|
||||
[[example]]
|
||||
name = "taproot-psbt"
|
||||
required-features = ["std", "bitcoinconsensus"]
|
||||
required-features = ["std", "rand-std", "bitcoinconsensus"]
|
||||
|
|
|
@ -31,9 +31,9 @@ if [ "$DO_LINT" = true ]
|
|||
then
|
||||
cargo clippy --all-features --all-targets -- -D warnings
|
||||
cargo clippy --example bip32 -- -D warnings
|
||||
cargo clippy --example handshake -- -D warnings
|
||||
cargo clippy --example handshake --features=rand-std -- -D warnings
|
||||
cargo clippy --example ecdsa-psbt --features=bitcoinconsensus -- -D warnings
|
||||
cargo clippy --example taproot-psbt --features=bitcoinconsensus -- -D warnings
|
||||
cargo clippy --example taproot-psbt --features=rand-std,bitcoinconsensus -- -D warnings
|
||||
fi
|
||||
|
||||
echo "********* Testing std *************"
|
||||
|
@ -77,7 +77,7 @@ do
|
|||
done
|
||||
|
||||
cargo run --example ecdsa-psbt --features=bitcoinconsensus
|
||||
cargo run --example taproot-psbt --features=bitcoinconsensus
|
||||
cargo run --example taproot-psbt --features=rand-std,bitcoinconsensus
|
||||
|
||||
# Build the docs if told to (this only works with the nightly toolchain)
|
||||
if [ "$DO_DOCS" = true ]; then
|
||||
|
|
|
@ -8,24 +8,23 @@
|
|||
//! # Example: creating a new address from a randomly-generated key pair
|
||||
//!
|
||||
//! ```rust
|
||||
//! use bitcoin::network::constants::Network;
|
||||
//! use bitcoin::address::Address;
|
||||
//! use bitcoin::PublicKey;
|
||||
//! use bitcoin::secp256k1::Secp256k1;
|
||||
//! use bitcoin::secp256k1::rand::thread_rng;
|
||||
//! # #[cfg(feature = "rand-std")] {
|
||||
//! use bitcoin::{Address, PublicKey, Network};
|
||||
//! use bitcoin::secp256k1::{rand, Secp256k1};
|
||||
//!
|
||||
//! // Generate random key pair.
|
||||
//! let s = Secp256k1::new();
|
||||
//! let public_key = PublicKey::new(s.generate_keypair(&mut thread_rng()).1);
|
||||
//! let public_key = PublicKey::new(s.generate_keypair(&mut rand::thread_rng()).1);
|
||||
//!
|
||||
//! // Generate pay-to-pubkey-hash address.
|
||||
//! let address = Address::p2pkh(&public_key, Network::Bitcoin);
|
||||
//! # }
|
||||
//! ```
|
||||
//!
|
||||
//! # Note: creating a new address requires the rand feature flag
|
||||
//! # Note: creating a new address requires the rand-std feature flag
|
||||
//!
|
||||
//! ```toml
|
||||
//! bitcoin = { version = "...", features = ["rand"] }
|
||||
//! bitcoin = { version = "...", features = ["rand-std"] }
|
||||
//! ```
|
||||
|
||||
use core::convert::TryFrom;
|
||||
|
|
|
@ -816,7 +816,6 @@ mod tests {
|
|||
use super::{deserialize, serialize, Error, CheckedData, VarInt};
|
||||
use super::{Transaction, BlockHash, FilterHash, TxMerkleNode, TxOut, TxIn};
|
||||
use crate::consensus::{Encodable, deserialize_partial, Decodable};
|
||||
use secp256k1::rand::{thread_rng, Rng};
|
||||
#[cfg(feature = "std")]
|
||||
use crate::network::{Address, message_blockdata::Inventory};
|
||||
|
||||
|
@ -1088,7 +1087,10 @@ mod tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "rand-std")]
|
||||
fn serialization_round_trips() {
|
||||
use secp256k1::rand::{thread_rng, Rng};
|
||||
|
||||
macro_rules! round_trip {
|
||||
($($val_type:ty),*) => {
|
||||
$(
|
||||
|
|
|
@ -499,20 +499,23 @@ impl Decodable for MerkleBlock {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use core::cmp::min;
|
||||
|
||||
#[cfg(feature = "rand-std")]
|
||||
use secp256k1::rand::prelude::*;
|
||||
|
||||
use super::*;
|
||||
use crate::consensus::encode::{deserialize, serialize};
|
||||
use crate::hash_types::{TxMerkleNode, Txid};
|
||||
#[cfg(feature = "rand-std")]
|
||||
use crate::hash_types::TxMerkleNode;
|
||||
use crate::hashes::hex::{FromHex, ToHex};
|
||||
#[cfg(feature = "rand-std")]
|
||||
use crate::hashes::Hash;
|
||||
use crate::{merkle_tree, Block};
|
||||
use crate::{Block, Txid};
|
||||
|
||||
/// accepts `pmt_test_$num`
|
||||
#[cfg(feature = "rand-std")]
|
||||
fn pmt_test_from_name(name: &str) { pmt_test(name[9..].parse().unwrap()) }
|
||||
|
||||
#[cfg(feature = "rand-std")]
|
||||
macro_rules! pmt_tests {
|
||||
($($name:ident),* $(,)?) => {
|
||||
$(
|
||||
|
@ -523,6 +526,7 @@ mod tests {
|
|||
)*
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "rand-std")]
|
||||
pmt_tests!(
|
||||
pmt_test_1,
|
||||
pmt_test_4,
|
||||
|
@ -538,7 +542,11 @@ mod tests {
|
|||
pmt_test_4095
|
||||
);
|
||||
|
||||
#[cfg(feature = "rand-std")]
|
||||
fn pmt_test(tx_count: usize) {
|
||||
use core::cmp::min;
|
||||
use crate::merkle_tree;
|
||||
|
||||
let mut rng = thread_rng();
|
||||
// Create some fake tx ids
|
||||
let tx_ids = (1..=tx_count)
|
||||
|
@ -713,6 +721,7 @@ mod tests {
|
|||
assert_eq!(index.len(), 0);
|
||||
}
|
||||
|
||||
#[cfg(feature = "rand-std")]
|
||||
impl PartialMerkleTree {
|
||||
/// Flip one bit in one of the hashes - this should break the authentication
|
||||
fn damage(&mut self, rng: &mut ThreadRng) {
|
||||
|
|
|
@ -887,7 +887,7 @@ mod tests {
|
|||
use crate::hash_types::Txid;
|
||||
|
||||
use secp256k1::{Secp256k1, self};
|
||||
#[cfg(feature = "rand")]
|
||||
#[cfg(feature = "rand-std")]
|
||||
use secp256k1::{All, SecretKey};
|
||||
|
||||
use crate::blockdata::script::ScriptBuf;
|
||||
|
@ -1685,7 +1685,7 @@ mod tests {
|
|||
assert_eq!(psbt1, psbt2);
|
||||
}
|
||||
|
||||
#[cfg(feature = "rand")]
|
||||
#[cfg(feature = "rand-std")]
|
||||
fn gen_keys() -> (PrivateKey, PublicKey, Secp256k1<All>) {
|
||||
use secp256k1::rand::thread_rng;
|
||||
|
||||
|
@ -1699,7 +1699,7 @@ mod tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "rand")]
|
||||
#[cfg(feature = "rand-std")]
|
||||
fn get_key_btree_map() {
|
||||
let (priv_key, pk, secp) = gen_keys();
|
||||
|
||||
|
@ -1811,7 +1811,7 @@ mod tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "rand")]
|
||||
#[cfg(feature = "rand-std")]
|
||||
fn sign_psbt() {
|
||||
use crate::WPubkeyHash;
|
||||
use crate::bip32::{Fingerprint, DerivationPath};
|
||||
|
|
|
@ -225,7 +225,7 @@ mod tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(all(feature = "secp-recovery", feature = "base64"))]
|
||||
#[cfg(all(feature = "secp-recovery", feature = "base64", feature = "rand-std"))]
|
||||
fn test_message_signature() {
|
||||
use core::str::FromStr;
|
||||
|
||||
|
|
Loading…
Reference in New Issue