From e1ae9d86bbe8a77cb1363978442df4acca09e76e Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Fri, 5 Aug 2022 13:37:41 +1000 Subject: [PATCH] Move the address module out of util The identifier 'util' does not convey any information. We have a whole bunch of modules inside the `util` module. As part of work to reduce the amount of arbitrary things in the `util` module move the `address` module to the crate root level. --- examples/bip32.rs | 2 +- examples/ecdsa-psbt.rs | 3 +-- fuzz/fuzz_targets/deserialize_address.rs | 2 +- fuzz/fuzz_targets/deserialize_script.rs | 2 +- src/{util => }/address.rs | 2 +- src/blockdata/script.rs | 2 +- src/lib.rs | 3 ++- src/util/key.rs | 2 +- src/util/misc.rs | 2 +- src/util/mod.rs | 8 +++++++- 10 files changed, 17 insertions(+), 11 deletions(-) rename src/{util => }/address.rs (99%) diff --git a/examples/bip32.rs b/examples/bip32.rs index 8ebdd845..3ec6939d 100644 --- a/examples/bip32.rs +++ b/examples/bip32.rs @@ -6,7 +6,7 @@ use std::{env, process}; use bitcoin::hashes::hex::FromHex; use bitcoin::secp256k1::ffi::types::AlignedType; use bitcoin::secp256k1::Secp256k1; -use bitcoin::util::address::Address; +use bitcoin::address::Address; use bitcoin::util::bip32::{ChildNumber, DerivationPath, ExtendedPrivKey, ExtendedPubKey}; use bitcoin::PublicKey; diff --git a/examples/ecdsa-psbt.rs b/examples/ecdsa-psbt.rs index 4522406e..5e9fdaaf 100644 --- a/examples/ecdsa-psbt.rs +++ b/examples/ecdsa-psbt.rs @@ -35,7 +35,6 @@ use std::str::FromStr; use bitcoin::consensus::encode; use bitcoin::hashes::hex::{self, FromHex}; use bitcoin::secp256k1::{Secp256k1, Signing, Verification}; -use bitcoin::util::address; use bitcoin::util::amount::ParseAmountError; use bitcoin::util::bip32::{ self, ChildNumber, DerivationPath, ExtendedPrivKey, ExtendedPubKey, Fingerprint, @@ -44,7 +43,7 @@ use bitcoin::util::bip32::{ use bitcoin::util::psbt::{self, Input, Psbt, PsbtSighashType}; use bitcoin::{ Address, Amount, Network, OutPoint, PackedLockTime, PrivateKey, PublicKey, Script, Sequence, - Transaction, TxIn, TxOut, Txid, Witness, + Transaction, TxIn, TxOut, Txid, Witness, address, }; use self::psbt_sign::*; diff --git a/fuzz/fuzz_targets/deserialize_address.rs b/fuzz/fuzz_targets/deserialize_address.rs index 3bfad559..637c59bd 100644 --- a/fuzz/fuzz_targets/deserialize_address.rs +++ b/fuzz/fuzz_targets/deserialize_address.rs @@ -2,7 +2,7 @@ extern crate bitcoin; use std::str::FromStr; fn do_test(data: &[u8]) { let data_str = String::from_utf8_lossy(data); - let addr = match bitcoin::util::address::Address::from_str(&data_str) { + let addr = match bitcoin::address::Address::from_str(&data_str) { Ok(addr) => addr, Err(_) => return, }; diff --git a/fuzz/fuzz_targets/deserialize_script.rs b/fuzz/fuzz_targets/deserialize_script.rs index 2ecc51c0..8cd25ae3 100644 --- a/fuzz/fuzz_targets/deserialize_script.rs +++ b/fuzz/fuzz_targets/deserialize_script.rs @@ -1,6 +1,6 @@ extern crate bitcoin; -use bitcoin::util::address::Address; +use bitcoin::address::Address; use bitcoin::network::constants::Network; use bitcoin::blockdata::script; use bitcoin::consensus::encode; diff --git a/src/util/address.rs b/src/address.rs similarity index 99% rename from src/util/address.rs rename to src/address.rs index e73fb725..7da66120 100644 --- a/src/util/address.rs +++ b/src/address.rs @@ -9,7 +9,7 @@ //! //! ```rust //! use bitcoin::network::constants::Network; -//! use bitcoin::util::address::Address; +//! use bitcoin::address::Address; //! use bitcoin::PublicKey; //! use bitcoin::secp256k1::Secp256k1; //! use bitcoin::secp256k1::rand::thread_rng; diff --git a/src/blockdata/script.rs b/src/blockdata/script.rs index 0bac5849..c5c2e172 100644 --- a/src/blockdata/script.rs +++ b/src/blockdata/script.rs @@ -32,7 +32,7 @@ use crate::policy::DUST_RELAY_TX_FEE; use crate::OutPoint; use crate::util::key::PublicKey; -use crate::util::address::WitnessVersion; +use crate::address::WitnessVersion; use crate::util::taproot::{LeafVersion, TapBranchHash, TapLeafHash}; use secp256k1::{Secp256k1, Verification, XOnlyPublicKey}; use crate::schnorr::{TapTweak, TweakedPublicKey, UntweakedPublicKey}; diff --git a/src/lib.rs b/src/lib.rs index 9a570f70..e7123581 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -79,6 +79,7 @@ mod serde_utils; #[macro_use] pub mod network; +pub mod address; pub mod blockdata; pub mod consensus; pub mod error; @@ -104,7 +105,7 @@ pub use crate::blockdata::witness::Witness; pub use crate::consensus::encode::VarInt; pub use crate::hash_types::*; pub use crate::network::constants::Network; -pub use crate::util::address::{Address, AddressType}; +pub use crate::address::{Address, AddressType}; pub use crate::util::amount::{Amount, Denomination, SignedAmount}; pub use crate::util::ecdsa::{self, EcdsaSig, EcdsaSigError}; pub use crate::util::key::{KeyPair, PrivateKey, PublicKey, XOnlyPublicKey}; diff --git a/src/util/key.rs b/src/util/key.rs index b72388a4..c4dce143 100644 --- a/src/util/key.rs +++ b/src/util/key.rs @@ -552,7 +552,7 @@ mod tests { use crate::hashes::hex::{FromHex, ToHex}; use crate::network::constants::Network::Testnet; use crate::network::constants::Network::Bitcoin; - use crate::util::address::Address; + use crate::address::Address; #[test] fn test_key_derivation() { diff --git a/src/util/misc.rs b/src/util/misc.rs index 4f8ecd8d..dea34063 100644 --- a/src/util/misc.rs +++ b/src/util/misc.rs @@ -32,7 +32,7 @@ mod message_signing { use secp256k1::ecdsa::{RecoveryId, RecoverableSignature}; use crate::util::key::PublicKey; - use crate::util::address::{Address, AddressType}; + use crate::address::{Address, AddressType}; use crate::internal_macros::write_err; /// An error used for dealing with Bitcoin Signed Messages. diff --git a/src/util/mod.rs b/src/util/mod.rs index d3754794..36ed53d0 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -9,7 +9,6 @@ pub mod key; pub mod ecdsa; pub mod schnorr; -pub mod address; pub mod amount; pub mod base58; pub mod bip32; @@ -111,3 +110,10 @@ pub(crate) fn read_to_end(mut d: D) -> Result, io::Error> { } Ok(result) } + +/// The `address` module now lives at the crate root, re-export everything so as not to break the +/// API, however deprecate the re-exports so folks know to upgrade sooner or later. +#[deprecated(since = "0.30.0", note = "Please use crate::address")] +pub mod address { + pub use crate::address::*; +}