Move params to network module
The `Params` struct is currently defined in the `consensus` module which has become a collection of orthogonal consensus-ish things. We would like to put things in more descriptive places. The `Params` struct defines constants that are network specific so it makes sense to put it in the `network` module. As soft proof of this argument note in this patch how often the `Params` type is imported along with the `Network` type. API break: The type is no longer available at `bitcoin::consensus::Params` but rather is re-exported at `bitcoin::network::Params`.
This commit is contained in:
parent
045a661ebe
commit
54c30556a2
|
@ -39,7 +39,6 @@ use hashes::{hash160, HashEngine};
|
||||||
use secp256k1::{Secp256k1, Verification, XOnlyPublicKey};
|
use secp256k1::{Secp256k1, Verification, XOnlyPublicKey};
|
||||||
|
|
||||||
use crate::address::script_pubkey::ScriptBufExt as _;
|
use crate::address::script_pubkey::ScriptBufExt as _;
|
||||||
use crate::consensus::Params;
|
|
||||||
use crate::constants::{
|
use crate::constants::{
|
||||||
PUBKEY_ADDRESS_PREFIX_MAIN, PUBKEY_ADDRESS_PREFIX_TEST, SCRIPT_ADDRESS_PREFIX_MAIN,
|
PUBKEY_ADDRESS_PREFIX_MAIN, PUBKEY_ADDRESS_PREFIX_TEST, SCRIPT_ADDRESS_PREFIX_MAIN,
|
||||||
SCRIPT_ADDRESS_PREFIX_TEST,
|
SCRIPT_ADDRESS_PREFIX_TEST,
|
||||||
|
@ -47,7 +46,7 @@ use crate::constants::{
|
||||||
use crate::crypto::key::{
|
use crate::crypto::key::{
|
||||||
CompressedPublicKey, PubkeyHash, PublicKey, TweakedPublicKey, UntweakedPublicKey,
|
CompressedPublicKey, PubkeyHash, PublicKey, TweakedPublicKey, UntweakedPublicKey,
|
||||||
};
|
};
|
||||||
use crate::network::{Network, NetworkKind};
|
use crate::network::{Network, NetworkKind, Params};
|
||||||
use crate::prelude::{String, ToOwned};
|
use crate::prelude::{String, ToOwned};
|
||||||
use crate::script::witness_program::WitnessProgram;
|
use crate::script::witness_program::WitnessProgram;
|
||||||
use crate::script::witness_version::WitnessVersion;
|
use crate::script::witness_version::WitnessVersion;
|
||||||
|
@ -892,7 +891,7 @@ mod tests {
|
||||||
use hex_lit::hex;
|
use hex_lit::hex;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::consensus::params;
|
use crate::network::params;
|
||||||
use crate::network::Network::{Bitcoin, Testnet};
|
use crate::network::Network::{Bitcoin, Testnet};
|
||||||
|
|
||||||
fn roundtrips(addr: &Address, network: Network) {
|
fn roundtrips(addr: &Address, network: Network) {
|
||||||
|
|
|
@ -13,9 +13,10 @@ use hashes::{sha256d, HashEngine};
|
||||||
use io::{BufRead, Write};
|
use io::{BufRead, Write};
|
||||||
|
|
||||||
use super::Weight;
|
use super::Weight;
|
||||||
use crate::consensus::{encode, Decodable, Encodable, Params};
|
use crate::consensus::{encode, Decodable, Encodable};
|
||||||
use crate::internal_macros::{impl_consensus_encoding, impl_hashencode};
|
use crate::internal_macros::{impl_consensus_encoding, impl_hashencode};
|
||||||
use crate::merkle_tree::{MerkleNode as _, TxMerkleNode, WitnessMerkleNode};
|
use crate::merkle_tree::{MerkleNode as _, TxMerkleNode, WitnessMerkleNode};
|
||||||
|
use crate::network::Params;
|
||||||
use crate::pow::{CompactTarget, Target, Work};
|
use crate::pow::{CompactTarget, Target, Work};
|
||||||
use crate::prelude::Vec;
|
use crate::prelude::Vec;
|
||||||
use crate::transaction::{Transaction, Wtxid};
|
use crate::transaction::{Transaction, Wtxid};
|
||||||
|
|
|
@ -10,10 +10,9 @@ use hashes::sha256d;
|
||||||
use internals::impl_array_newtype;
|
use internals::impl_array_newtype;
|
||||||
|
|
||||||
use crate::block::{self, Block};
|
use crate::block::{self, Block};
|
||||||
use crate::consensus::Params;
|
|
||||||
use crate::internal_macros::impl_array_newtype_stringify;
|
use crate::internal_macros::impl_array_newtype_stringify;
|
||||||
use crate::locktime::absolute;
|
use crate::locktime::absolute;
|
||||||
use crate::network::Network;
|
use crate::network::{Network, Params};
|
||||||
use crate::opcodes::all::*;
|
use crate::opcodes::all::*;
|
||||||
use crate::pow::CompactTarget;
|
use crate::pow::CompactTarget;
|
||||||
use crate::transaction::{self, OutPoint, Transaction, TxIn, TxOut};
|
use crate::transaction::{self, OutPoint, Transaction, TxIn, TxOut};
|
||||||
|
@ -216,7 +215,7 @@ mod test {
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::consensus::encode::serialize;
|
use crate::consensus::encode::serialize;
|
||||||
use crate::consensus::params;
|
use crate::network::params;
|
||||||
use crate::Txid;
|
use crate::Txid;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -118,9 +118,8 @@ impl OutPoint {
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// use bitcoin::consensus::params;
|
|
||||||
/// use bitcoin::constants::genesis_block;
|
/// use bitcoin::constants::genesis_block;
|
||||||
/// use bitcoin::Network;
|
/// use bitcoin::{params, Network};
|
||||||
///
|
///
|
||||||
/// let block = genesis_block(¶ms::MAINNET);
|
/// let block = genesis_block(¶ms::MAINNET);
|
||||||
/// let tx = &block.txdata[0];
|
/// let tx = &block.txdata[0];
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
//! conform to Bitcoin consensus.
|
//! conform to Bitcoin consensus.
|
||||||
|
|
||||||
pub mod encode;
|
pub mod encode;
|
||||||
pub mod params;
|
|
||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "serde")]
|
||||||
pub mod serde;
|
pub mod serde;
|
||||||
#[cfg(feature = "bitcoinconsensus")]
|
#[cfg(feature = "bitcoinconsensus")]
|
||||||
|
@ -23,7 +22,6 @@ use crate::consensus;
|
||||||
#[doc(inline)]
|
#[doc(inline)]
|
||||||
pub use self::{
|
pub use self::{
|
||||||
encode::{deserialize, deserialize_partial, serialize, Decodable, Encodable, ReadExt, WriteExt},
|
encode::{deserialize, deserialize_partial, serialize, Decodable, Encodable, ReadExt, WriteExt},
|
||||||
params::Params,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(feature = "bitcoinconsensus")]
|
#[cfg(feature = "bitcoinconsensus")]
|
||||||
|
|
|
@ -123,12 +123,12 @@ pub use crate::{
|
||||||
blockdata::weight::Weight,
|
blockdata::weight::Weight,
|
||||||
blockdata::witness::{self, Witness},
|
blockdata::witness::{self, Witness},
|
||||||
consensus::encode::VarInt,
|
consensus::encode::VarInt,
|
||||||
consensus::params,
|
|
||||||
crypto::ecdsa,
|
crypto::ecdsa,
|
||||||
crypto::key::{self, PrivateKey, PubkeyHash, PublicKey, CompressedPublicKey, WPubkeyHash, XOnlyPublicKey},
|
crypto::key::{self, PrivateKey, PubkeyHash, PublicKey, CompressedPublicKey, WPubkeyHash, XOnlyPublicKey},
|
||||||
crypto::sighash::{self, LegacySighash, SegwitV0Sighash, TapSighash, TapSighashTag},
|
crypto::sighash::{self, LegacySighash, SegwitV0Sighash, TapSighash, TapSighashTag},
|
||||||
merkle_tree::{MerkleBlock, TxMerkleNode, WitnessMerkleNode},
|
merkle_tree::{MerkleBlock, TxMerkleNode, WitnessMerkleNode},
|
||||||
network::{Network, NetworkKind},
|
network::{Network, NetworkKind},
|
||||||
|
network::params::{self, Params},
|
||||||
pow::{CompactTarget, Target, Work},
|
pow::{CompactTarget, Target, Work},
|
||||||
psbt::Psbt,
|
psbt::Psbt,
|
||||||
sighash::{EcdsaSighashType, TapSighashType},
|
sighash::{EcdsaSighashType, TapSighashType},
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
//! assert_eq!(&bytes[..], &[0xF9, 0xBE, 0xB4, 0xD9]);
|
//! assert_eq!(&bytes[..], &[0xF9, 0xBE, 0xB4, 0xD9]);
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
|
pub mod params;
|
||||||
|
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
use core::str::FromStr;
|
use core::str::FromStr;
|
||||||
|
|
||||||
|
@ -25,11 +27,14 @@ use internals::write_err;
|
||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "serde")]
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::consensus::Params;
|
|
||||||
use crate::constants::ChainHash;
|
use crate::constants::ChainHash;
|
||||||
use crate::p2p::Magic;
|
use crate::p2p::Magic;
|
||||||
use crate::prelude::{String, ToOwned};
|
use crate::prelude::{String, ToOwned};
|
||||||
|
|
||||||
|
#[rustfmt::skip] // Keep public re-exports separate.
|
||||||
|
#[doc(inline)]
|
||||||
|
pub use self::params::Params;
|
||||||
|
|
||||||
/// What kind of network we are on.
|
/// What kind of network we are on.
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
pub enum NetworkKind {
|
pub enum NetworkKind {
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
//! custom type that can be used is such places you might want to do the following:
|
//! custom type that can be used is such places you might want to do the following:
|
||||||
//!
|
//!
|
||||||
//! ```
|
//! ```
|
||||||
//! use bitcoin::consensus::Params;
|
//! use bitcoin::network::Params;
|
||||||
//! use bitcoin::{p2p, Script, ScriptBuf, Network, Target};
|
//! use bitcoin::{p2p, Script, ScriptBuf, Network, Target};
|
||||||
//!
|
//!
|
||||||
//! const POW_TARGET_SPACING: u64 = 120; // Two minutes.
|
//! const POW_TARGET_SPACING: u64 = 120; // Two minutes.
|
|
@ -28,9 +28,8 @@ use internals::{debug_from_display, write_err};
|
||||||
use io::{BufRead, Write};
|
use io::{BufRead, Write};
|
||||||
|
|
||||||
use crate::consensus::encode::{self, Decodable, Encodable};
|
use crate::consensus::encode::{self, Decodable, Encodable};
|
||||||
use crate::consensus::Params;
|
use crate::network::{Network, Params};
|
||||||
use crate::prelude::{Borrow, BorrowMut, String, ToOwned};
|
use crate::prelude::{Borrow, BorrowMut, String, ToOwned};
|
||||||
use crate::Network;
|
|
||||||
|
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
#[doc(inline)]
|
#[doc(inline)]
|
||||||
|
|
|
@ -15,7 +15,7 @@ use units::parse::{self, ParseIntError, PrefixedHexError, UnprefixedHexError};
|
||||||
|
|
||||||
use crate::block::{BlockHash, Header};
|
use crate::block::{BlockHash, Header};
|
||||||
use crate::consensus::encode::{self, Decodable, Encodable};
|
use crate::consensus::encode::{self, Decodable, Encodable};
|
||||||
use crate::consensus::Params;
|
use crate::network::Params;
|
||||||
|
|
||||||
/// Implement traits and methods shared by `Target` and `Work`.
|
/// Implement traits and methods shared by `Target` and `Work`.
|
||||||
macro_rules! do_impl {
|
macro_rules! do_impl {
|
||||||
|
|
Loading…
Reference in New Issue