Skip to content

Commit

Permalink
Set struct_lit_width to 80
Browse files Browse the repository at this point in the history
Set `rustfmt` config option `struct_lit_width` to true and run the
formatter.
  • Loading branch information
tcharding committed Aug 8, 2023
1 parent f0d0563 commit f41a70d
Show file tree
Hide file tree
Showing 26 changed files with 191 additions and 663 deletions.
14 changes: 2 additions & 12 deletions bitcoind-tests/tests/setup/test_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,7 @@ impl TestData {
let ripemd160_pre = [0x78 as u8; 32];
let ripemd160 = ripemd160::Hash::hash(&ripemd160_pre);

let pubdata = PubData {
pks,
sha256,
hash256,
ripemd160,
hash160,
x_only_pks,
};
let pubdata = PubData { pks, sha256, hash256, ripemd160, hash160, x_only_pks };
let secretdata = SecretData {
sks,
sha256_pre,
Expand All @@ -124,10 +117,7 @@ impl TestData {
hash160_pre,
x_only_keypairs,
};
Self {
pubdata,
secretdata,
}
Self { pubdata, secretdata }
}
}

Expand Down
17 changes: 6 additions & 11 deletions bitcoind-tests/tests/test_cpp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,9 @@ pub fn test_from_cpp_ms(cl: &Client, testdata: &TestData) {
.get_new_address(None, Some(json::AddressType::Bech32))
.unwrap()
.assume_checked();
psbt.unsigned_tx.output.push(TxOut {
value: 99_999_000,
script_pubkey: addr.script_pubkey(),
});
psbt.unsigned_tx
.output
.push(TxOut { value: 99_999_000, script_pubkey: addr.script_pubkey() });
let mut input = psbt::Input::default();
input.witness_utxo = Some(witness_utxo);
input.witness_script = Some(desc.explicit_script().unwrap());
Expand Down Expand Up @@ -181,13 +180,9 @@ pub fn test_from_cpp_ms(cl: &Client, testdata: &TestData) {
for sk in sks_reqd {
let sig = secp.sign_ecdsa(&msg, &sk);
let pk = pks[sks.iter().position(|&x| x == sk).unwrap()];
psbts[i].inputs[0].partial_sigs.insert(
pk,
bitcoin::ecdsa::Signature {
sig,
hash_ty: sighash_ty,
},
);
psbts[i].inputs[0]
.partial_sigs
.insert(pk, bitcoin::ecdsa::Signature { sig, hash_ty: sighash_ty });
}
// Add the hash preimages to the psbt
psbts[i].inputs[0]
Expand Down
33 changes: 11 additions & 22 deletions bitcoind-tests/tests/test_desc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,9 @@ pub fn test_desc_satisfy(
.assume_checked();
// Had to decrease 'value', so that fees can be increased
// (Was getting insufficient fees error, for deep script trees)
psbt.unsigned_tx.output.push(TxOut {
value: 99_997_000,
script_pubkey: addr.script_pubkey(),
});
psbt.unsigned_tx
.output
.push(TxOut { value: 99_997_000, script_pubkey: addr.script_pubkey() });
let mut input = psbt::Input::default();
input
.update_with_descriptor_unchecked(&definite_desc)
Expand Down Expand Up @@ -178,10 +177,8 @@ pub fn test_desc_satisfy(
rand::thread_rng().fill_bytes(&mut aux_rand);
let schnorr_sig =
secp.sign_schnorr_with_aux_rand(&msg, &internal_keypair, &aux_rand);
psbt.inputs[0].tap_key_sig = Some(taproot::Signature {
sig: schnorr_sig,
hash_ty: hash_ty,
});
psbt.inputs[0].tap_key_sig =
Some(taproot::Signature { sig: schnorr_sig, hash_ty: hash_ty });
} else {
// No internal key
}
Expand All @@ -206,13 +203,9 @@ pub fn test_desc_satisfy(
let sig = secp.sign_schnorr_with_aux_rand(&msg, &keypair, &aux_rand);
let x_only_pk =
x_only_pks[xonly_keypairs.iter().position(|&x| x == keypair).unwrap()];
psbt.inputs[0].tap_script_sigs.insert(
(x_only_pk, leaf_hash),
taproot::Signature {
sig,
hash_ty: hash_ty,
},
);
psbt.inputs[0]
.tap_script_sigs
.insert((x_only_pk, leaf_hash), taproot::Signature { sig, hash_ty: hash_ty });
}
}
_ => {
Expand Down Expand Up @@ -261,13 +254,9 @@ pub fn test_desc_satisfy(
let sig = secp.sign_ecdsa(&msg, &sk);
let pk = pks[sks.iter().position(|&x| x == sk).unwrap()];
assert!(secp.verify_ecdsa(&msg, &sig, &pk.inner).is_ok());
psbt.inputs[0].partial_sigs.insert(
pk,
ecdsa::Signature {
sig,
hash_ty: hash_ty,
},
);
psbt.inputs[0]
.partial_sigs
.insert(pk, ecdsa::Signature { sig, hash_ty: hash_ty });
}
}
}
Expand Down
24 changes: 9 additions & 15 deletions examples/psbt_sign_finalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,13 @@ fn main() {
txin.sequence = Sequence::from_height(26); //Sequence::MAX; //
psbt.unsigned_tx.input.push(txin);

psbt.unsigned_tx.output.push(TxOut {
script_pubkey: receiver.script_pubkey(),
value: amount / 5 - 500,
});
psbt.unsigned_tx
.output
.push(TxOut { script_pubkey: receiver.script_pubkey(), value: amount / 5 - 500 });

psbt.unsigned_tx.output.push(TxOut {
script_pubkey: bridge_descriptor.script_pubkey(),
value: amount * 4 / 5,
});
psbt.unsigned_tx
.output
.push(TxOut { script_pubkey: bridge_descriptor.script_pubkey(), value: amount * 4 / 5 });

// Generating signatures & witness data

Expand Down Expand Up @@ -130,13 +128,9 @@ fn main() {
let pk2 = backup2_private.public_key(&secp256k1);
assert!(secp256k1.verify_ecdsa(&msg, &sig2, &pk2.inner).is_ok());

psbt.inputs[0].partial_sigs.insert(
pk1,
bitcoin::ecdsa::Signature {
sig: sig1,
hash_ty: hash_ty,
},
);
psbt.inputs[0]
.partial_sigs
.insert(pk1, bitcoin::ecdsa::Signature { sig: sig1, hash_ty: hash_ty });

println!("{:#?}", psbt);

Expand Down
2 changes: 1 addition & 1 deletion rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ indent_style = "Block"
use_small_heuristics = "Default"
fn_call_width = 80
attr_fn_like_width = 70
struct_lit_width = 18
struct_lit_width = 80
struct_variant_width = 35
array_width = 60
chain_width = 60
Expand Down
15 changes: 2 additions & 13 deletions src/descriptor/checksum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,7 @@ impl Default for Engine {

impl Engine {
/// Construct an engine with no input
pub fn new() -> Self {
Engine {
c: 1,
cls: 0,
clscount: 0,
}
}
pub fn new() -> Self { Engine { c: 1, cls: 0, clscount: 0 } }

/// Checksum some data
///
Expand Down Expand Up @@ -148,12 +142,7 @@ pub struct Formatter<'f, 'a> {

impl<'f, 'a> Formatter<'f, 'a> {
/// Contruct a new `Formatter`, wrapping a given `fmt::Formatter`
pub fn new(f: &'f mut fmt::Formatter<'a>) -> Self {
Formatter {
fmt: f,
eng: Engine::new(),
}
}
pub fn new(f: &'f mut fmt::Formatter<'a>) -> Self { Formatter { fmt: f, eng: Engine::new() } }

/// Writes the checksum into the underlying `fmt::Formatter`
pub fn write_checksum(&mut self) -> fmt::Result {
Expand Down
32 changes: 6 additions & 26 deletions src/descriptor/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,7 @@ impl SinglePriv {
fn to_public<C: Signing>(&self, secp: &Secp256k1<C>) -> SinglePub {
let pub_key = self.key.public_key(secp);

SinglePub {
origin: self.origin.clone(),
key: SinglePubKey::FullKey(pub_key),
}
SinglePub { origin: self.origin.clone(), key: SinglePubKey::FullKey(pub_key) }
}
}

Expand Down Expand Up @@ -351,12 +348,7 @@ impl DescriptorSecretKey {
match self {
DescriptorSecretKey::Single(..) | DescriptorSecretKey::XPrv(..) => vec![self],
DescriptorSecretKey::MultiXPrv(xpub) => {
let DescriptorMultiXKey {
origin,
xkey,
derivation_paths,
wildcard,
} = xpub;
let DescriptorMultiXKey { origin, xkey, derivation_paths, wildcard } = xpub;
derivation_paths
.into_paths()
.into_iter()
Expand Down Expand Up @@ -659,12 +651,7 @@ impl DescriptorPublicKey {
match self {
DescriptorPublicKey::Single(..) | DescriptorPublicKey::XPub(..) => vec![self],
DescriptorPublicKey::MultiXPub(xpub) => {
let DescriptorMultiXKey {
origin,
xkey,
derivation_paths,
wildcard,
} = xpub;
let DescriptorMultiXKey { origin, xkey, derivation_paths, wildcard } = xpub;
derivation_paths
.into_paths()
.into_iter()
Expand All @@ -691,10 +678,7 @@ impl FromStr for DescriptorSecretKey {
if key_part.len() <= 52 {
let sk = bitcoin::PrivateKey::from_str(key_part)
.map_err(|_| DescriptorKeyParseError("Error while parsing a WIF private key"))?;
Ok(DescriptorSecretKey::Single(SinglePriv {
key: sk,
origin: None,
}))
Ok(DescriptorSecretKey::Single(SinglePriv { key: sk, origin: None }))
} else {
let (xpriv, derivation_paths, wildcard) =
parse_xkey_deriv::<bip32::ExtendedPrivKey>(key_part)?;
Expand Down Expand Up @@ -971,8 +955,7 @@ impl MiniscriptKey for DescriptorPublicKey {
fn is_uncompressed(&self) -> bool {
match self {
DescriptorPublicKey::Single(SinglePub {
key: SinglePubKey::FullKey(ref key),
..
key: SinglePubKey::FullKey(ref key), ..
}) => key.is_uncompressed(),
_ => false,
}
Expand All @@ -981,10 +964,7 @@ impl MiniscriptKey for DescriptorPublicKey {
fn is_x_only_key(&self) -> bool {
matches!(
self,
DescriptorPublicKey::Single(SinglePub {
key: SinglePubKey::XOnly(ref _key),
..
})
DescriptorPublicKey::Single(SinglePub { key: SinglePubKey::XOnly(ref _key), .. })
)
}

Expand Down
10 changes: 2 additions & 8 deletions src/descriptor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1464,17 +1464,11 @@ mod tests {

satisfier.insert(
a,
bitcoin::ecdsa::Signature {
sig: sig_a,
hash_ty: EcdsaSighashType::All,
},
bitcoin::ecdsa::Signature { sig: sig_a, hash_ty: EcdsaSighashType::All },
);
satisfier.insert(
b,
bitcoin::ecdsa::Signature {
sig: sig_b,
hash_ty: EcdsaSighashType::All,
},
bitcoin::ecdsa::Signature { sig: sig_b, hash_ty: EcdsaSighashType::All },
);

satisfier
Expand Down
16 changes: 4 additions & 12 deletions src/descriptor/segwitv0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,14 @@ impl<Pk: MiniscriptKey> Wsh<Pk> {
pub fn new(ms: Miniscript<Pk, Segwitv0>) -> Result<Self, Error> {
// do the top-level checks
Segwitv0::top_level_checks(&ms)?;
Ok(Self {
inner: WshInner::Ms(ms),
})
Ok(Self { inner: WshInner::Ms(ms) })
}

/// Create a new sortedmulti wsh descriptor
pub fn new_sortedmulti(k: usize, pks: Vec<Pk>) -> Result<Self, Error> {
// The context checks will be carried out inside new function for
// sortedMultiVec
Ok(Self {
inner: WshInner::SortedMulti(SortedMultiVec::new(k, pks)?),
})
Ok(Self { inner: WshInner::SortedMulti(SortedMultiVec::new(k, pks)?) })
}

/// Get the descriptor without the checksum
Expand Down Expand Up @@ -205,15 +201,11 @@ impl_from_tree!(
if top.name == "wsh" && top.args.len() == 1 {
let top = &top.args[0];
if top.name == "sortedmulti" {
return Ok(Wsh {
inner: WshInner::SortedMulti(SortedMultiVec::from_tree(top)?),
});
return Ok(Wsh { inner: WshInner::SortedMulti(SortedMultiVec::from_tree(top)?) });
}
let sub = Miniscript::from_tree(top)?;
Segwitv0::top_level_checks(&sub)?;
Ok(Wsh {
inner: WshInner::Ms(sub),
})
Ok(Wsh { inner: WshInner::Ms(sub) })
} else {
Err(Error::Unexpected(format!(
"{}({} args) while parsing wsh descriptor",
Expand Down
32 changes: 7 additions & 25 deletions src/descriptor/sh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,34 +128,24 @@ impl<Pk: MiniscriptKey> Sh<Pk> {
pub fn new(ms: Miniscript<Pk, Legacy>) -> Result<Self, Error> {
// do the top-level checks
Legacy::top_level_checks(&ms)?;
Ok(Self {
inner: ShInner::Ms(ms),
})
Ok(Self { inner: ShInner::Ms(ms) })
}

/// Create a new p2sh sortedmulti descriptor with threshold `k`
/// and Vec of `pks`.
pub fn new_sortedmulti(k: usize, pks: Vec<Pk>) -> Result<Self, Error> {
// The context checks will be carried out inside new function for
// sortedMultiVec
Ok(Self {
inner: ShInner::SortedMulti(SortedMultiVec::new(k, pks)?),
})
Ok(Self { inner: ShInner::SortedMulti(SortedMultiVec::new(k, pks)?) })
}

/// Create a new p2sh wrapped wsh descriptor with the raw miniscript
pub fn new_wsh(ms: Miniscript<Pk, Segwitv0>) -> Result<Self, Error> {
Ok(Self {
inner: ShInner::Wsh(Wsh::new(ms)?),
})
Ok(Self { inner: ShInner::Wsh(Wsh::new(ms)?) })
}

/// Create a new p2sh wrapper for the given wsh descriptor
pub fn new_with_wsh(wsh: Wsh<Pk>) -> Self {
Self {
inner: ShInner::Wsh(wsh),
}
}
pub fn new_with_wsh(wsh: Wsh<Pk>) -> Self { Self { inner: ShInner::Wsh(wsh) } }

/// Checks whether the descriptor is safe.
pub fn sanity_check(&self) -> Result<(), Error> {
Expand All @@ -173,24 +163,16 @@ impl<Pk: MiniscriptKey> Sh<Pk> {
pub fn new_wsh_sortedmulti(k: usize, pks: Vec<Pk>) -> Result<Self, Error> {
// The context checks will be carried out inside new function for
// sortedMultiVec
Ok(Self {
inner: ShInner::Wsh(Wsh::new_sortedmulti(k, pks)?),
})
Ok(Self { inner: ShInner::Wsh(Wsh::new_sortedmulti(k, pks)?) })
}

/// Create a new p2sh wrapped wpkh from `Pk`
pub fn new_wpkh(pk: Pk) -> Result<Self, Error> {
Ok(Self {
inner: ShInner::Wpkh(Wpkh::new(pk)?),
})
Ok(Self { inner: ShInner::Wpkh(Wpkh::new(pk)?) })
}

/// Create a new p2sh wrapper for the given wpkh descriptor
pub fn new_with_wpkh(wpkh: Wpkh<Pk>) -> Self {
Self {
inner: ShInner::Wpkh(wpkh),
}
}
pub fn new_with_wpkh(wpkh: Wpkh<Pk>) -> Self { Self { inner: ShInner::Wpkh(wpkh) } }

/// Computes an upper bound on the difference between a non-satisfied
/// `TxIn`'s `segwit_weight` and a satisfied `TxIn`'s `segwit_weight`
Expand Down
Loading

0 comments on commit f41a70d

Please sign in to comment.