Skip to content

Commit c2e637e

Browse files
committed
Configure group_imports
Configure `group_imports = "StdExternalCrate"`. The benefit of this option is that it increases uniformity in the code base over the default "Preserve", while saving devs needing to think about where they place their import statements (for those that do not use tooling to add them).
1 parent a44d427 commit c2e637e

38 files changed

+134
-126
lines changed

examples/htlc.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717
extern crate bitcoin;
1818
extern crate miniscript;
1919

20+
use std::str::FromStr;
21+
2022
use bitcoin::Network;
2123
use miniscript::descriptor::Wsh;
2224
use miniscript::policy::{Concrete, Liftable};
2325
use miniscript::DescriptorTrait;
24-
use std::str::FromStr;
2526

2627
fn main() {
2728
//HTLC policy with 10:1 odds for happy(co-operative) case compared to uncooperative case

examples/parse.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717
extern crate bitcoin;
1818
extern crate miniscript;
1919

20-
use miniscript::{descriptor::DescriptorType, Descriptor, DescriptorTrait};
2120
use std::str::FromStr;
2221

22+
use miniscript::{descriptor::DescriptorType, Descriptor, DescriptorTrait};
23+
2324
fn main() {
2425
let my_descriptor = miniscript::Descriptor::<bitcoin::PublicKey>::from_str(
2526
"wsh(c:pk_k(020202020202020202020202020202020202020202020202020202020202020202))",

examples/sign_multisig.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717
extern crate bitcoin;
1818
extern crate miniscript;
1919

20+
use std::collections::HashMap;
21+
use std::str::FromStr;
22+
2023
use bitcoin::blockdata::witness::Witness;
2124
use bitcoin::secp256k1; // secp256k1 re-exported from rust-bitcoin
2225
use miniscript::DescriptorTrait;
23-
use std::collections::HashMap;
24-
use std::str::FromStr;
2526

2627
fn main() {
2728
// Avoid repeatedly typing a pretty-common descriptor type

examples/verify_tx.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717
extern crate bitcoin;
1818
extern crate miniscript;
1919

20+
use std::str::FromStr;
21+
2022
use bitcoin::consensus::Decodable;
2123
use bitcoin::util::sighash;
2224
use bitcoin::{secp256k1, TxOut}; // secp256k1 re-exported from rust-bitcoin
2325
use miniscript::interpreter::KeySigPair;
24-
use std::str::FromStr;
2526

2627
fn main() {
2728
// tx `f27eba163c38ad3f34971198687a3f1882b7ec818599ffe469a8440d82261c98`

examples/xpub_descriptors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
1717
extern crate miniscript;
1818

19+
use std::str::FromStr;
20+
1921
use miniscript::bitcoin::{self, secp256k1};
2022
use miniscript::{Descriptor, DescriptorPublicKey, DescriptorTrait, TranslatePk2};
21-
22-
use std::str::FromStr;
2323
fn main() {
2424
// For deriving from descriptors, we need to provide a secp context
2525
let secp_ctx = secp256k1::Secp256k1::verification_only();

rustfmt.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ where_single_line = false
2828
imports_indent = "Block"
2929
imports_layout = "Mixed"
3030
imports_granularity = "Preserve"
31-
group_imports = "Preserve"
31+
group_imports = "StdExternalCrate" # Default "Preserve"
3232
reorder_imports = true
3333
reorder_modules = true
3434
reorder_impl_items = false

src/descriptor/bare.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
use std::{fmt, str::FromStr};
2222

2323
use bitcoin::{self, blockdata::script, Script};
24-
2524
use expression::{self, FromTree};
2625
use miniscript::context::ScriptContext;
2726
use policy::{semantic, Liftable};

src/descriptor/checksum.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,10 @@ pub(super) fn verify_checksum(s: &str) -> Result<&str, Error> {
101101
}
102102
#[cfg(test)]
103103
mod test {
104-
use super::*;
105104
use std::str;
106105

106+
use super::*;
107+
107108
macro_rules! check_expected {
108109
($desc: expr, $checksum: expr) => {
109110
assert_eq!(desc_checksum($desc).unwrap(), $checksum);

src/descriptor/key.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use bitcoin::{
99
util::bip32,
1010
XOnlyPublicKey, XpubIdentifier,
1111
};
12-
1312
use {MiniscriptKey, ToPublicKey};
1413

1514
/// Single public key without any origin or range information
@@ -719,11 +718,11 @@ impl MiniscriptKey for DescriptorPublicKey {
719718

720719
#[cfg(test)]
721720
mod test {
722-
use super::{DescriptorKeyParseError, DescriptorPublicKey, DescriptorSecretKey};
721+
use std::str::FromStr;
723722

724723
use bitcoin::secp256k1;
725724

726-
use std::str::FromStr;
725+
use super::{DescriptorKeyParseError, DescriptorPublicKey, DescriptorSecretKey};
727726

728727
#[test]
729728
fn parse_descriptor_key_errors() {

src/descriptor/mod.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ use std::{
3131

3232
use bitcoin::blockdata::witness::Witness;
3333
use bitcoin::{self, secp256k1, Script};
34-
35-
use self::checksum::verify_checksum;
3634
use expression;
3735
use miniscript;
3836
use miniscript::{Legacy, Miniscript, Segwitv0};
@@ -41,6 +39,8 @@ use {
4139
TranslatePk2,
4240
};
4341

42+
use self::checksum::verify_checksum;
43+
4444
// Directly export from lib.rs, exporting the trait here causes conflicts in this file
4545
pub(crate) mod pretaproot;
4646

@@ -824,9 +824,10 @@ serde_string_impl_pk!(Descriptor, "a script descriptor");
824824

825825
#[cfg(test)]
826826
mod tests {
827-
use super::checksum::desc_checksum;
828-
use super::tr::Tr;
829-
use super::*;
827+
use std::cmp;
828+
use std::collections::HashMap;
829+
use std::str::FromStr;
830+
830831
use bitcoin::blockdata::opcodes::all::{OP_CLTV, OP_CSV};
831832
use bitcoin::blockdata::script::Instruction;
832833
use bitcoin::blockdata::{opcodes, script};
@@ -839,13 +840,13 @@ mod tests {
839840
DescriptorPublicKey, DescriptorSecretKey, DescriptorSinglePub, DescriptorXKey,
840841
};
841842
use hex_script;
842-
use std::cmp;
843-
use std::collections::HashMap;
844-
use std::str::FromStr;
845-
use {Descriptor, DummyKey, Error, Miniscript, Satisfier, TranslatePk2};
846-
847843
#[cfg(feature = "compiler")]
848844
use policy;
845+
use {Descriptor, DummyKey, Error, Miniscript, Satisfier, TranslatePk2};
846+
847+
use super::checksum::desc_checksum;
848+
use super::tr::Tr;
849+
use super::*;
849850

850851
type StdDescriptor = Descriptor<PublicKey>;
851852
const TEST_PK: &'static str =

src/descriptor/pretaproot.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use std::{
44
};
55

66
use bitcoin::{self, Script};
7+
use {expression, DescriptorTrait, Error, MiniscriptKey, Satisfier, ToPublicKey};
78

89
use super::{checksum::verify_checksum, Bare, Pkh, Sh, Wpkh, Wsh};
9-
use {expression, DescriptorTrait, Error, MiniscriptKey, Satisfier, ToPublicKey};
1010

1111
/// Script descriptor
1212
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
@@ -240,7 +240,6 @@ serde_string_impl_pk!(PreTaprootDescriptor, "a pre-taproot script descriptor");
240240
// Have the trait in a separate module to avoid conflicts
241241
pub(crate) mod traits {
242242
use bitcoin::Script;
243-
244243
use {
245244
descriptor::{Pkh, Sh, Wpkh, Wsh},
246245
DescriptorTrait, MiniscriptKey, ToPublicKey,

src/descriptor/segwitv0.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use std::{fmt, str::FromStr};
2020

2121
use bitcoin::{self, Script};
22-
2322
use expression::{self, FromTree};
2423
use miniscript::context::{ScriptContext, ScriptContextError};
2524
use policy::{semantic, Liftable};

src/descriptor/sh.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
use std::{fmt, str::FromStr};
2222

2323
use bitcoin::{self, blockdata::script, Script};
24-
2524
use expression::{self, FromTree};
2625
use miniscript::context::ScriptContext;
2726
use policy::{semantic, Liftable};

src/descriptor/sortedmulti.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use std::{fmt, marker::PhantomData, str::FromStr};
2020

2121
use bitcoin::blockdata::script;
22-
2322
use expression;
2423
use miniscript::{
2524
self, context::ScriptContext, decode::Terminal, limits::MAX_PUBKEYS_PER_MULTISIG,
@@ -240,10 +239,11 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> fmt::Display for SortedMultiVec<Pk,
240239

241240
#[cfg(test)]
242241
mod tests {
243-
use super::*;
244242
use bitcoin::secp256k1::PublicKey;
245243
use miniscript::context::Legacy;
246244

245+
use super::*;
246+
247247
#[test]
248248
fn too_many_pubkeys() {
249249
// Arbitrary pubic key.

src/descriptor/tr.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
// Tapscript
22

3-
use policy::semantic::Policy;
4-
use policy::Liftable;
5-
use util::{varint_len, witness_size};
6-
use {DescriptorTrait, ForEach, ForEachKey, Satisfier, ToPublicKey, TranslatePk};
3+
use std::cmp::{self, max};
4+
use std::hash;
5+
use std::sync::{Arc, Mutex};
6+
use std::{fmt, str::FromStr};
77

8-
use super::checksum::{desc_checksum, verify_checksum};
98
use bitcoin::blockdata::opcodes;
109
use bitcoin::util::taproot::{
1110
LeafVersion, TaprootBuilder, TaprootBuilderError, TaprootSpendInfo, TAPROOT_CONTROL_BASE_SIZE,
@@ -15,13 +14,15 @@ use bitcoin::{self, secp256k1, Script};
1514
use errstr;
1615
use expression::{self, FromTree};
1716
use miniscript::Miniscript;
18-
use std::cmp::{self, max};
19-
use std::hash;
20-
use std::sync::{Arc, Mutex};
21-
use std::{fmt, str::FromStr};
17+
use policy::semantic::Policy;
18+
use policy::Liftable;
19+
use util::{varint_len, witness_size};
2220
use Tap;
21+
use {DescriptorTrait, ForEach, ForEachKey, Satisfier, ToPublicKey, TranslatePk};
2322
use {Error, MiniscriptKey};
2423

24+
use super::checksum::{desc_checksum, verify_checksum};
25+
2526
/// A Taproot Tree representation.
2627
// Hidden leaves are not yet supported in descriptor spec. Conceptually, it should
2728
// be simple to integrate those here, but it is best to wait on core for the exact syntax.
@@ -748,9 +749,10 @@ where
748749

749750
#[cfg(test)]
750751
mod tests {
751-
use super::*;
752752
use ForEachKey;
753753

754+
use super::*;
755+
754756
#[test]
755757
fn test_for_each() {
756758
let desc = "tr(acc0, {

src/expression.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use std::str::FromStr;
1919

2020
use errstr;
2121
use Error;
22-
2322
use MAX_RECURSION_DEPTH;
2423

2524
#[derive(Debug)]

src/interpreter/error.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212
// If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
1313
//
1414

15+
use std::{error, fmt};
16+
1517
use bitcoin::hashes::{hash160, hex::ToHex};
1618
use bitcoin::util::taproot;
1719
use bitcoin::{self, secp256k1};
18-
use std::{error, fmt};
1920

2021
use super::BitcoinKey;
2122

src/interpreter/inner.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@ use bitcoin;
1616
use bitcoin::blockdata::witness::Witness;
1717
use bitcoin::hashes::{hash160, sha256, Hash};
1818
use bitcoin::util::taproot::{ControlBlock, TAPROOT_ANNEX_PREFIX};
19-
19+
use miniscript::context::{NoChecks, ScriptContext};
2020
use {BareCtx, Legacy, Segwitv0, Tap};
21+
use {Miniscript, MiniscriptKey};
2122

2223
use super::{stack, BitcoinKey, Error, Stack, TypedHash160};
23-
use miniscript::context::{NoChecks, ScriptContext};
24-
use {Miniscript, MiniscriptKey};
2524

2625
/// Attempts to parse a slice as a Bitcoin public key, checking compressedness
2726
/// if asked to, but otherwise dropping it
@@ -399,12 +398,14 @@ impl<Ctx: ScriptContext> ToNoChecks for Miniscript<bitcoin::XOnlyPublicKey, Ctx>
399398
#[cfg(test)]
400399
mod tests {
401400

402-
use super::*;
401+
use std::str::FromStr;
402+
403403
use bitcoin::blockdata::script;
404404
use bitcoin::hashes::hex::FromHex;
405405
use bitcoin::hashes::{hash160, sha256, Hash};
406406
use bitcoin::{self, Script};
407-
use std::str::FromStr;
407+
408+
use super::*;
408409

409410
struct KeyTestData {
410411
pk_spk: bitcoin::Script,

src/interpreter/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919
//! assuming that the spent coin was descriptor controlled.
2020
//!
2121
22-
use bitcoin::blockdata::witness::Witness;
23-
use bitcoin::util::{sighash, taproot};
2422
use std::borrow::Borrow;
2523
use std::fmt;
2624
use std::str::FromStr;
2725

26+
use bitcoin::blockdata::witness::Witness;
2827
use bitcoin::hashes::{hash160, ripemd160, sha256, sha256d};
28+
use bitcoin::util::{sighash, taproot};
2929
use bitcoin::{self, secp256k1, TxOut};
3030
use miniscript::context::NoChecks;
3131
use miniscript::ScriptContext;
@@ -1030,8 +1030,6 @@ fn verify_sersig<'txin>(
10301030
#[cfg(test)]
10311031
mod tests {
10321032

1033-
use super::inner::ToNoChecks;
1034-
use super::*;
10351033
use bitcoin;
10361034
use bitcoin::hashes::{hash160, ripemd160, sha256, sha256d, Hash};
10371035
use bitcoin::secp256k1::{self, Secp256k1};
@@ -1040,6 +1038,9 @@ mod tests {
10401038
use MiniscriptKey;
10411039
use ToPublicKey;
10421040

1041+
use super::inner::ToNoChecks;
1042+
use super::*;
1043+
10431044
fn setup_keys_sigs(
10441045
n: usize,
10451046
) -> (

src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,14 @@ use std::{error, fmt, hash, str};
121121

122122
use bitcoin::blockdata::{opcodes, script};
123123
use bitcoin::hashes::{hash160, sha256, Hash};
124-
124+
pub use descriptor::pretaproot::{traits::PreTaprootDescriptorTrait, PreTaprootDescriptor};
125125
pub use descriptor::{Descriptor, DescriptorPublicKey, DescriptorTrait};
126126
pub use interpreter::Interpreter;
127127
pub use miniscript::context::{BareCtx, Legacy, ScriptContext, Segwitv0, Tap};
128128
pub use miniscript::decode::Terminal;
129129
pub use miniscript::satisfy::{Preimage32, Satisfier};
130130
pub use miniscript::Miniscript;
131131

132-
pub use descriptor::pretaproot::{traits::PreTaprootDescriptorTrait, PreTaprootDescriptor};
133-
134132
///Public key trait which can be converted to Hash type
135133
pub trait MiniscriptKey: Clone + Eq + Ord + fmt::Debug + fmt::Display + hash::Hash {
136134
/// Returns true if the pubkey is uncompressed. Defaults to `false`.

src/miniscript/analyzable.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717
//! Tools for determining whether the guarantees offered by the library
1818
//! actually hold.
1919
20-
use error;
21-
use miniscript::iter::PkPkh;
2220
use std::collections::HashSet;
2321
use std::fmt;
22+
23+
use error;
24+
use miniscript::iter::PkPkh;
2425
use {Miniscript, MiniscriptKey, ScriptContext};
2526
/// Possible reasons Miniscript guarantees can fail
2627
/// We currently mark Miniscript as Non-Analyzable if

0 commit comments

Comments
 (0)