Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initiate configuration of rustfmt #374

Merged
merged 5 commits into from
May 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 7 additions & 4 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ on: [push, pull_request]
name: Continuous integration

jobs:
lint_fuzz_stable:
name: Lint + Fuzz
Fuzz:
name: Fuzz
runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -24,11 +24,10 @@ jobs:
- name: Running fuzzer
env:
DO_FUZZ: true
DO_LINT: true
run: ./contrib/test.sh

Nightly:
name: Bench + Docs
name: Bench + Docs + Fmt
runs-on: ubuntu-latest
steps:
- name: Checkout Crate
Expand All @@ -47,6 +46,10 @@ jobs:
env:
DO_DOCS: true
run: ./contrib/test.sh
- name: Running formatter
env:
DO_FMT: true
run: ./contrib/test.sh

UnitTests:
name: Tests
Expand Down
4 changes: 2 additions & 2 deletions contrib/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ then
alias cargo="cargo +$TOOLCHAIN"
fi

# Lint if told to
if [ "$DO_LINT" = true ]
# Format if told to
if [ "$DO_FMT" = true ]
then
(
rustup component add rustfmt
Expand Down
3 changes: 2 additions & 1 deletion examples/htlc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@

//! Example: Create an HTLC with miniscript using the policy compiler

use std::str::FromStr;

use bitcoin::Network;
use miniscript::descriptor::Wsh;
use miniscript::policy::{Concrete, Liftable};
use miniscript::DescriptorTrait;
use std::str::FromStr;

fn main() {
// HTLC policy with 10:1 odds for happy (co-operative) case compared to uncooperative case.
Expand Down
4 changes: 3 additions & 1 deletion examples/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@

//! Example: Parsing a descriptor from a string.

use miniscript::{descriptor::DescriptorType, Descriptor, DescriptorTrait};
use std::str::FromStr;

use miniscript::descriptor::DescriptorType;
use miniscript::{Descriptor, DescriptorTrait};

fn main() {
let desc = miniscript::Descriptor::<bitcoin::PublicKey>::from_str(
"wsh(c:pk_k(020202020202020202020202020202020202020202020202020202020202020202))",
Expand Down
5 changes: 3 additions & 2 deletions examples/sign_multisig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@

//! Example: Signing a 2-of-3 multisignature.

use std::collections::HashMap;
use std::str::FromStr;

use bitcoin::blockdata::witness::Witness;
use bitcoin::secp256k1;
use miniscript::DescriptorTrait;
use std::collections::HashMap;
use std::str::FromStr;

fn main() {
let mut tx = spending_transaction();
Expand Down
3 changes: 2 additions & 1 deletion examples/verify_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@

//! Example: Verifying a signed transaction.

use std::str::FromStr;

use bitcoin::consensus::Decodable;
use bitcoin::secp256k1::{self, Secp256k1};
use bitcoin::util::sighash;
use miniscript::interpreter::KeySigPair;
use std::str::FromStr;

fn main() {
//
Expand Down
77 changes: 77 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
max_width = 100
hard_tabs = false
tab_spaces = 4
newline_style = "Auto"
indent_style = "Block"
use_small_heuristics = "Default"
fn_call_width = 60
attr_fn_like_width = 70
struct_lit_width = 18
struct_variant_width = 35
array_width = 60
chain_width = 60
single_line_if_else_max_width = 50
wrap_comments = false
format_code_in_doc_comments = false
comment_width = 80
normalize_comments = false
normalize_doc_attributes = false
license_template_path = ""
format_strings = false
format_macro_matchers = false
format_macro_bodies = true
hex_literal_case = "Preserve"
empty_item_single_line = true
struct_lit_single_line = true
fn_single_line = false
where_single_line = false
imports_indent = "Block"
imports_layout = "Mixed"
imports_granularity = "Module" # Default "Preserve"
group_imports = "StdExternalCrate" # Default "Preserve"
reorder_imports = true
reorder_modules = true
reorder_impl_items = false
type_punctuation_density = "Wide"
space_before_colon = false
space_after_colon = true
spaces_around_ranges = false
binop_separator = "Front"
remove_nested_parens = true
combine_control_expr = true
overflow_delimited_expr = false
struct_field_align_threshold = 0
enum_discrim_align_threshold = 0
match_arm_blocks = true
match_arm_leading_pipes = "Never"
force_multiline_blocks = false
fn_args_layout = "Tall"
brace_style = "SameLineWhere"
control_brace_style = "AlwaysSameLine"
trailing_semicolon = true
trailing_comma = "Vertical"
match_block_trailing_comma = false
blank_lines_upper_bound = 1
blank_lines_lower_bound = 0
edition = "2015"
version = "One"
inline_attribute_width = 0
format_generated_files = true
merge_derives = true
use_try_shorthand = false
use_field_init_shorthand = false
force_explicit_abi = true
condense_wildcard_suffixes = false
color = "Auto"
required_version = "1.4.38"
unstable_features = false
disable_all_formatting = false
skip_children = false
hide_parse_errors = false
error_on_line_overflow = false
error_on_unformatted = false
report_todo = "Never"
report_fixme = "Never"
ignore = []
emit_mode = "Files"
make_backup = false
13 changes: 6 additions & 7 deletions src/descriptor/bare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@
//! Also includes pk, and pkh descriptors
//!

use std::{fmt, str::FromStr};
use std::fmt;
use std::str::FromStr;

use bitcoin::{self, blockdata::script, Script};
use bitcoin::blockdata::script;
use bitcoin::{self, Script};

use super::checksum::{desc_checksum, verify_checksum};
use super::DescriptorTrait;
use crate::expression::{self, FromTree};
use crate::miniscript::context::ScriptContext;
use crate::policy::{semantic, Liftable};
Expand All @@ -31,11 +35,6 @@ use crate::{
TranslatePk,
};

use super::{
checksum::{desc_checksum, verify_checksum},
DescriptorTrait,
};

/// Create a Bare Descriptor. That is descriptor that is
/// not wrapped in sh or wsh. This covers the Pk descriptor
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
Expand Down
3 changes: 2 additions & 1 deletion src/descriptor/checksum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,10 @@ pub(super) fn verify_checksum(s: &str) -> Result<&str, Error> {
}
#[cfg(test)]
mod test {
use super::*;
use std::str;

use super::*;

macro_rules! check_expected {
($desc: expr, $checksum: expr) => {
assert_eq!(desc_checksum($desc).unwrap(), $checksum);
Expand Down
20 changes: 9 additions & 11 deletions src/descriptor/key.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
use std::{error, fmt, str::FromStr};
use std::str::FromStr;
use std::{error, fmt};

use bitcoin::{
self,
hashes::{hash160, Hash},
hashes::{hex::FromHex, HashEngine},
secp256k1::{Secp256k1, Signing, Verification},
util::bip32,
XOnlyPublicKey, XpubIdentifier,
};
use bitcoin::hashes::hex::FromHex;
use bitcoin::hashes::{hash160, Hash, HashEngine};
use bitcoin::secp256k1::{Secp256k1, Signing, Verification};
use bitcoin::util::bip32;
use bitcoin::{self, XOnlyPublicKey, XpubIdentifier};

use crate::{MiniscriptKey, ToPublicKey};

Expand Down Expand Up @@ -796,11 +794,11 @@ impl ToPublicKey for DerivedDescriptorKey {

#[cfg(test)]
mod test {
use super::{DescriptorKeyParseError, DescriptorPublicKey, DescriptorSecretKey};
use std::str::FromStr;

use bitcoin::secp256k1;

use std::str::FromStr;
use super::{DescriptorKeyParseError, DescriptorPublicKey, DescriptorSecretKey};

#[test]
fn parse_descriptor_key_errors() {
Expand Down
35 changes: 16 additions & 19 deletions src/descriptor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,21 @@
//! these with BIP32 paths, pay-to-contract instructions, etc.
//!

use std::collections::HashMap;
use std::fmt;
use std::ops::Range;
use std::{collections::HashMap, sync::Arc};
use std::{
fmt,
str::{self, FromStr},
};
use std::str::{self, FromStr};
use std::sync::Arc;

use bitcoin::blockdata::witness::Witness;
use bitcoin::util::address::WitnessVersion;
use bitcoin::{self, secp256k1, Script};

use self::checksum::verify_checksum;
use crate::expression;
use crate::miniscript;
use crate::miniscript::{Legacy, Miniscript, Segwitv0};
use crate::{
BareCtx, Error, ForEach, ForEachKey, MiniscriptKey, Satisfier, ToPublicKey, TranslatePk,
TranslatePk2,
expression, miniscript, BareCtx, Error, ForEach, ForEachKey, MiniscriptKey, Satisfier,
ToPublicKey, TranslatePk, TranslatePk2,
};

// Directly export from lib.rs, exporting the trait here causes conflicts in this file
Expand Down Expand Up @@ -857,26 +854,26 @@ serde_string_impl_pk!(Descriptor, "a script descriptor");

#[cfg(test)]
mod tests {
use super::checksum::desc_checksum;
use super::tr::Tr;
use super::*;
use crate::descriptor::key::Wildcard;
use crate::descriptor::{DescriptorPublicKey, DescriptorSecretKey, DescriptorXKey, SinglePub};
use crate::hex_script;
use crate::{Descriptor, DummyKey, Error, Miniscript, Satisfier, TranslatePk2};
use std::cmp;
use std::collections::HashMap;
use std::str::FromStr;

use bitcoin::blockdata::opcodes::all::{OP_CLTV, OP_CSV};
use bitcoin::blockdata::script::Instruction;
use bitcoin::blockdata::{opcodes, script};
use bitcoin::hashes::hex::{FromHex, ToHex};
use bitcoin::hashes::{hash160, sha256};
use bitcoin::util::bip32;
use bitcoin::{self, secp256k1, EcdsaSighashType, PublicKey};
use std::cmp;
use std::collections::HashMap;
use std::str::FromStr;

use super::checksum::desc_checksum;
use super::tr::Tr;
use super::*;
use crate::descriptor::key::Wildcard;
use crate::descriptor::{DescriptorPublicKey, DescriptorSecretKey, DescriptorXKey, SinglePub};
#[cfg(feature = "compiler")]
use crate::policy;
use crate::{hex_script, Descriptor, DummyKey, Error, Miniscript, Satisfier, TranslatePk2};

type StdDescriptor = Descriptor<PublicKey>;
const TEST_PK: &'static str =
Expand Down
16 changes: 6 additions & 10 deletions src/descriptor/pretaproot.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use std::{
fmt,
str::{self, FromStr},
};
use std::fmt;
use std::str::{self, FromStr};

use bitcoin::{self, Script};

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

/// Script descriptor
Expand Down Expand Up @@ -241,12 +240,9 @@ serde_string_impl_pk!(PreTaprootDescriptor, "a pre-taproot script descriptor");
pub(crate) mod traits {
use bitcoin::Script;

use crate::{
descriptor::{Pkh, Sh, Wpkh, Wsh},
DescriptorTrait, MiniscriptKey, ToPublicKey,
};

use super::PreTaprootDescriptor;
use crate::descriptor::{Pkh, Sh, Wpkh, Wsh};
use crate::{DescriptorTrait, MiniscriptKey, ToPublicKey};

/// A general trait for Pre taproot bitcoin descriptor.
/// Similar to [`DescriptorTrait`], but `explicit_script` and `script_code` methods cannot fail
Expand Down
10 changes: 4 additions & 6 deletions src/descriptor/segwitv0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@
//! Implementation of Segwit Descriptors. Contains the implementation
//! of wsh, wpkh and sortedmulti inside wsh.

use std::{fmt, str::FromStr};
use std::fmt;
use std::str::FromStr;

use bitcoin::{self, Script};

use super::checksum::{desc_checksum, verify_checksum};
use super::{DescriptorTrait, SortedMultiVec};
use crate::expression::{self, FromTree};
use crate::miniscript::context::{ScriptContext, ScriptContextError};
use crate::policy::{semantic, Liftable};
Expand All @@ -28,11 +31,6 @@ use crate::{
Error, ForEach, ForEachKey, Miniscript, MiniscriptKey, Satisfier, Segwitv0, ToPublicKey,
TranslatePk,
};

use super::{
checksum::{desc_checksum, verify_checksum},
DescriptorTrait, SortedMultiVec,
};
/// A Segwitv0 wsh descriptor
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
pub struct Wsh<Pk: MiniscriptKey> {
Expand Down