Merge rust-bitcoin/rust-bitcoin#1277: Try to fix up sighash export mess

2001f44e46 Try to fix up sighash export mess (Tobin C. Harding)

Pull request description:

  Recently we moved a few types from `transaction` to `sighash`, while doing so I erroneously annotated code with the `deprecated` attribute hoping it would give downstream users a gentle upgrade experience. It turns out `deprecated` only works on functions.

  During that same work, we re-exported from the crate root a bunch of types from the `sighash` module that probably should not have been re-exported. We are currently trying to create a nice clean API surface, in an effort to move in the right direction we should remove the re-exports and just re-export the `sighash` module.

  Try to clean up the sighash export mess by doing:

  - Remove the re-exports from the `transaction` module
  - Remove crate level re-exports of `sighash` module types
  - Re-export `sighash` module

  Note, this patch is a breaking API change, justified by the fact that there is no good way to gently lead downstream when moving types since types cannot be deprecated with the `deprecated` attribute.

ACKs for top commit:
  apoelstra:
    ACK 2001f44e46
  Kixunil:
    ACK 2001f44e46

Tree-SHA512: 42a08bc15bacd4cf7c3fec002ddb29afe5b1be3c4eb74fbd8c63a9333c0d45cbc8493027532f5db6a3930d49b1e83048826371e0ed7d4ac3dc611e5885540bce
This commit is contained in:
Andrew Poelstra 2022-09-24 13:03:26 +00:00
commit 6101d8d31a
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
6 changed files with 10 additions and 22 deletions

View File

@ -382,12 +382,9 @@ mod psbt_sign {
use std::ops::Deref; use std::ops::Deref;
use bitcoin::psbt::{Input, Prevouts, Psbt, PsbtSighashType}; use bitcoin::psbt::{Input, Prevouts, Psbt, PsbtSighashType};
use bitcoin::util::sighash::{self, SighashCache}; use bitcoin::sighash::{self, SighashCache, EcdsaSighashType, SchnorrSighashType};
use bitcoin::util::taproot::TapLeafHash; use bitcoin::util::taproot::TapLeafHash;
use bitcoin::{ use bitcoin::{EcdsaSig, EcdsaSigError, PrivateKey, Script, Transaction, TxOut};
EcdsaSig, EcdsaSigError, EcdsaSighashType, PrivateKey, SchnorrSighashType, Script,
Transaction, TxOut,
};
use secp256k1::{Message, Secp256k1, Signing}; use secp256k1::{Message, Secp256k1, Signing};
/// Signs the input at `input_index` with private key `sk`. /// Signs the input at `input_index` with private key `sk`.

View File

@ -36,7 +36,7 @@ use crate::internal_macros::{impl_consensus_encoding, serde_struct_human_string_
use crate::parse::impl_parse_str_through_int; use crate::parse::impl_parse_str_through_int;
#[cfg(doc)] #[cfg(doc)]
use crate::util::sighash::SchnorrSighashType; use crate::sighash::{EcdsaSighashType, SchnorrSighashType};
/// A reference to a transaction output. /// A reference to a transaction output.
/// ///
@ -1014,13 +1014,6 @@ impl From<&Transaction> for Wtxid {
} }
} }
#[deprecated(since = "0.30.0", note = "use crate::NonStandardSighashType instead")]
pub use crate::util::sighash::NonStandardSighashType;
#[deprecated(since = "0.30.0", note = "use crate::EcdsaSighashType instead")]
pub use crate::util::sighash::EcdsaSighashType;
#[deprecated(since = "0.30.0", note = "use crate::SighashTypeParseError instead")]
pub use crate::util::sighash::SighashTypeParseError;
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
@ -1032,6 +1025,7 @@ mod tests {
use crate::blockdata::locktime::absolute; use crate::blockdata::locktime::absolute;
use crate::consensus::encode::serialize; use crate::consensus::encode::serialize;
use crate::consensus::encode::deserialize; use crate::consensus::encode::deserialize;
use crate::sighash::EcdsaSighashType;
use crate::hashes::hex::FromHex; use crate::hashes::hex::FromHex;

View File

@ -110,11 +110,7 @@ pub use crate::util::ecdsa::{self, EcdsaSig, EcdsaSigError};
pub use crate::util::key::{KeyPair, PrivateKey, PublicKey, XOnlyPublicKey}; pub use crate::util::key::{KeyPair, PrivateKey, PublicKey, XOnlyPublicKey};
pub use crate::util::merkleblock::MerkleBlock; pub use crate::util::merkleblock::MerkleBlock;
pub use crate::util::schnorr::{self, SchnorrSig, SchnorrSigError}; pub use crate::util::schnorr::{self, SchnorrSig, SchnorrSigError};
pub use crate::util::sighash::{ pub use crate::util::{psbt, sighash, Error};
EcdsaSighashType, NonStandardSighashType, SchnorrSighashType, SighashCache,
SighashTypeParseError,
};
pub use crate::util::{psbt, Error};
#[cfg(not(feature = "std"))] #[cfg(not(feature = "std"))]
mod io_extras { mod io_extras {

View File

@ -497,7 +497,7 @@ mod tests {
//! Create a full PSBT value with various fields filled and make sure it can be JSONized. //! Create a full PSBT value with various fields filled and make sure it can be JSONized.
use crate::hashes::sha256d; use crate::hashes::sha256d;
use crate::util::psbt::map::Input; use crate::util::psbt::map::Input;
use crate::EcdsaSighashType; use crate::sighash::EcdsaSighashType;
// create some values to use in the PSBT // create some values to use in the PSBT
let tx = Transaction { let tx = Transaction {

View File

@ -16,7 +16,7 @@ pub use secp256k1::{self, constants, Secp256k1, KeyPair, XOnlyPublicKey, Verific
use crate::prelude::*; use crate::prelude::*;
use crate::util::taproot::{TapBranchHash, TapTweakHash}; use crate::util::taproot::{TapBranchHash, TapTweakHash};
use crate::SchnorrSighashType; use crate::sighash::SchnorrSighashType;
/// Untweaked BIP-340 X-coord-only public key /// Untweaked BIP-340 X-coord-only public key
pub type UntweakedPublicKey = XOnlyPublicKey; pub type UntweakedPublicKey = XOnlyPublicKey;

View File

@ -1006,7 +1006,8 @@ impl<R: DerefMut<Target=Transaction>> SighashCache<R> {
/// ///
/// This allows in-line signing such as /// This allows in-line signing such as
/// ``` /// ```
/// use bitcoin::{absolute, EcdsaSighashType, SighashCache, Transaction, Script}; /// use bitcoin::{absolute, Transaction, Script};
/// use bitcoin::sighash::{EcdsaSighashType, SighashCache};
/// ///
/// let mut tx_to_sign = Transaction { version: 2, lock_time: absolute::PackedLockTime::ZERO, input: Vec::new(), output: Vec::new() }; /// let mut tx_to_sign = Transaction { version: 2, lock_time: absolute::PackedLockTime::ZERO, input: Vec::new(), output: Vec::new() };
/// let input_count = tx_to_sign.input.len(); /// let input_count = tx_to_sign.input.len();
@ -1069,7 +1070,7 @@ mod tests {
use secp256k1::{self, SecretKey, XOnlyPublicKey}; use secp256k1::{self, SecretKey, XOnlyPublicKey};
use crate::{Script, Transaction, TxIn, TxOut, EcdsaSighashType, Address}; use crate::{Script, Transaction, TxIn, TxOut, Address};
use crate::blockdata::locktime::absolute; use crate::blockdata::locktime::absolute;
use crate::consensus::deserialize; use crate::consensus::deserialize;
use crate::hashes::hex::{FromHex, ToHex}; use crate::hashes::hex::{FromHex, ToHex};