Skip to content

Commit 38b84de

Browse files
committed
Merge rust-bitcoin#4669: bitcoin: Add public ext modules
17dd640 bitcoin: Add crate level public ext module (Tobin C. Harding) Pull request description: bitcoin: Add crate level public ext module Add a public `ext` module and re-export all the extension traits anonymously traits so users can use wildcard imports of form: `use bitcoin::ext::*;` If, for some reason, users want the name in scope they have to go to the module its defined in e.g., `use bitcoin::script::ScriptExt`. Update all files in the `examples` directory to use wildcard import, thereby verifying it all works as expected. Note this is not exactly what is described in issue rust-bitcoin#4660 but it resolves it none the less. Close: rust-bitcoin#4660 ACKs for top commit: apoelstra: ACK 17dd640; successfully ran local tests Tree-SHA512: 32a553ebbbc36498ca72ffcf12aca262d63e4d86be4054ab00df4b418ffb9bac3dddca3942744dedaec22286134043dbee1d190209673465820aed0886f8dd7b
2 parents 94bde57 + 17dd640 commit 38b84de

File tree

8 files changed

+34
-13
lines changed

8 files changed

+34
-13
lines changed

bitcoin/examples/ecdsa-psbt-simple.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,11 @@
2525
use std::collections::BTreeMap;
2626

2727
use bitcoin::bip32::{ChildNumber, DerivationPath, Fingerprint, IntoDerivationPath, Xpriv, Xpub};
28+
use bitcoin::ext::*;
2829
use bitcoin::key::WPubkeyHash;
2930
use bitcoin::locktime::absolute;
3031
use bitcoin::psbt::Input;
31-
use bitcoin::script::ScriptBufExt as _;
3232
use bitcoin::secp256k1::{Secp256k1, Signing};
33-
use bitcoin::witness::WitnessExt as _;
3433
use bitcoin::{
3534
consensus, transaction, Address, Amount, EcdsaSighashType, Network, OutPoint, Psbt, ScriptBuf,
3635
Sequence, Transaction, TxIn, TxOut, Txid, Witness,

bitcoin/examples/ecdsa-psbt.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,9 @@ use std::fmt;
3333

3434
use bitcoin::bip32::{ChildNumber, DerivationPath, Fingerprint, IntoDerivationPath, Xpriv, Xpub};
3535
use bitcoin::consensus::encode;
36-
use bitcoin::consensus_validation::TransactionExt as _;
36+
use bitcoin::ext::*;
3737
use bitcoin::locktime::absolute;
3838
use bitcoin::psbt::{self, Input, Psbt, PsbtSighashType};
39-
use bitcoin::script::ScriptBufExt as _;
4039
use bitcoin::secp256k1::{Secp256k1, Signing, Verification};
4140
use bitcoin::{
4241
transaction, Address, Amount, CompressedPublicKey, Network, OutPoint, ScriptBuf, Sequence,

bitcoin/examples/sighash.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use bitcoin::script::{ScriptBufExt as _, ScriptExt as _};
1+
use bitcoin::ext::*;
22
use bitcoin::{
33
consensus, ecdsa, sighash, Amount, CompressedPublicKey, Script, ScriptBuf, Transaction,
44
};

bitcoin/examples/sign-tx-segwit-v0.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
//! Demonstrate creating a transaction that spends to and from p2wpkh outputs.
44
55
use bitcoin::key::WPubkeyHash;
6+
use bitcoin::ext::*;
67
use bitcoin::locktime::absolute;
7-
use bitcoin::script::ScriptBufExt as _;
88
use bitcoin::secp256k1::{rand, Message, Secp256k1, SecretKey, Signing};
99
use bitcoin::sighash::{EcdsaSighashType, SighashCache};
10-
use bitcoin::witness::WitnessExt as _;
1110
use bitcoin::{
1211
transaction, Address, Amount, Network, OutPoint, ScriptBuf, Sequence, Transaction, TxIn, TxOut,
1312
Txid, Witness,

bitcoin/examples/sign-tx-taproot.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
//! Demonstrate creating a transaction that spends to and from p2tr outputs.
44
55
use bitcoin::key::{Keypair, TapTweak, TweakedKeypair, UntweakedPublicKey};
6+
use bitcoin::ext::*;
67
use bitcoin::locktime::absolute;
7-
use bitcoin::script::ScriptBufExt as _;
88
use bitcoin::secp256k1::{rand, Message, Secp256k1, SecretKey, Signing, Verification};
99
use bitcoin::sighash::{Prevouts, SighashCache, TapSighashType};
10-
use bitcoin::witness::WitnessExt as _;
1110
use bitcoin::{
1211
transaction, Address, Amount, Network, OutPoint, ScriptBuf, Sequence, Transaction, TxIn, TxOut,
1312
Txid, Witness,

bitcoin/examples/taproot-psbt-simple.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,11 @@
2323
use std::collections::BTreeMap;
2424

2525
use bitcoin::bip32::{ChildNumber, DerivationPath, Fingerprint, IntoDerivationPath, Xpriv, Xpub};
26+
use bitcoin::ext::*;
2627
use bitcoin::key::UntweakedPublicKey;
2728
use bitcoin::locktime::absolute;
2829
use bitcoin::psbt::Input;
29-
use bitcoin::script::ScriptBufExt as _;
3030
use bitcoin::secp256k1::{Secp256k1, Signing};
31-
use bitcoin::witness::WitnessExt as _;
3231
use bitcoin::{
3332
consensus, transaction, Address, Amount, Network, OutPoint, Psbt, ScriptBuf, Sequence,
3433
TapLeafHash, TapSighashType, Transaction, TxIn, TxOut, Txid, Witness, XOnlyPublicKey,

bitcoin/examples/taproot-psbt.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,10 @@ use std::collections::BTreeMap;
7979

8080
use bitcoin::bip32::{ChildNumber, DerivationPath, Fingerprint, Xpriv, Xpub};
8181
use bitcoin::consensus::encode;
82-
use bitcoin::consensus_validation::TransactionExt as _;
82+
use bitcoin::ext::*;
8383
use bitcoin::key::{TapTweak, XOnlyPublicKey};
8484
use bitcoin::opcodes::all::{OP_CHECKSIG, OP_CLTV, OP_DROP};
8585
use bitcoin::psbt::{self, Input, Output, Psbt, PsbtSighashType};
86-
use bitcoin::script::{ScriptBufExt as _, ScriptExt as _};
8786
use bitcoin::secp256k1::Secp256k1;
8887
use bitcoin::sighash::{self, SighashCache, TapSighash, TapSighashType};
8988
use bitcoin::taproot::{self, LeafVersion, TapLeafHash, TaprootBuilder, TaprootSpendInfo};

bitcoin/src/lib.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,33 @@ extern crate serde;
9393

9494
mod internal_macros;
9595

96+
pub mod ext {
97+
//! Re-export all the extension traits so downstream can use wildcard imports.
98+
//!
99+
//! As part of stabilizing `primitives` and `units` we created a bunch of extension traits in
100+
//! `rust-bitcoin` to hold all then API that we are not yet ready to stabilize. This module
101+
//! re-exports all of them to improve ergonomics for users comfortable with wildcard imports.
102+
//!
103+
//! # Examples
104+
//!
105+
//! ```
106+
//! // Wildcard import all of the extension crates.
107+
//! use bitcoin::ext::*;
108+
//!
109+
//! // If, for some reason, you want the name to be in scope access it via the module. E.g.
110+
//! use bitcoin::script::ScriptExt;
111+
//! ```
112+
#[rustfmt::skip] // Use terse custom grouping.
113+
pub use crate::{
114+
block::{BlockUncheckedExt as _, BlockCheckedExt as _, HeaderExt as _},
115+
pow::CompactTargetExt as _,
116+
script::{ScriptExt as _, ScriptBufExt as _},
117+
transaction::{TxidExt as _, WtxidExt as _, OutPointExt as _, TxInExt as _, TxOutExt as _, TransactionExt as _},
118+
witness::WitnessExt as _,
119+
};
120+
#[cfg(feature = "bitcoinconsensus")]
121+
pub use crate::consensus_validation::{ScriptExt as _, TransactionExt as _};
122+
}
96123
#[macro_use]
97124
pub mod address;
98125
pub mod bip152;

0 commit comments

Comments
 (0)