Skip to content

Commit f41a70d

Browse files
committed
Set struct_lit_width to 80
Set `rustfmt` config option `struct_lit_width` to true and run the formatter.
1 parent f0d0563 commit f41a70d

File tree

26 files changed

+191
-663
lines changed

26 files changed

+191
-663
lines changed

bitcoind-tests/tests/setup/test_util.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,7 @@ impl TestData {
108108
let ripemd160_pre = [0x78 as u8; 32];
109109
let ripemd160 = ripemd160::Hash::hash(&ripemd160_pre);
110110

111-
let pubdata = PubData {
112-
pks,
113-
sha256,
114-
hash256,
115-
ripemd160,
116-
hash160,
117-
x_only_pks,
118-
};
111+
let pubdata = PubData { pks, sha256, hash256, ripemd160, hash160, x_only_pks };
119112
let secretdata = SecretData {
120113
sks,
121114
sha256_pre,
@@ -124,10 +117,7 @@ impl TestData {
124117
hash160_pre,
125118
x_only_keypairs,
126119
};
127-
Self {
128-
pubdata,
129-
secretdata,
130-
}
120+
Self { pubdata, secretdata }
131121
}
132122
}
133123

bitcoind-tests/tests/test_cpp.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,9 @@ pub fn test_from_cpp_ms(cl: &Client, testdata: &TestData) {
136136
.get_new_address(None, Some(json::AddressType::Bech32))
137137
.unwrap()
138138
.assume_checked();
139-
psbt.unsigned_tx.output.push(TxOut {
140-
value: 99_999_000,
141-
script_pubkey: addr.script_pubkey(),
142-
});
139+
psbt.unsigned_tx
140+
.output
141+
.push(TxOut { value: 99_999_000, script_pubkey: addr.script_pubkey() });
143142
let mut input = psbt::Input::default();
144143
input.witness_utxo = Some(witness_utxo);
145144
input.witness_script = Some(desc.explicit_script().unwrap());
@@ -181,13 +180,9 @@ pub fn test_from_cpp_ms(cl: &Client, testdata: &TestData) {
181180
for sk in sks_reqd {
182181
let sig = secp.sign_ecdsa(&msg, &sk);
183182
let pk = pks[sks.iter().position(|&x| x == sk).unwrap()];
184-
psbts[i].inputs[0].partial_sigs.insert(
185-
pk,
186-
bitcoin::ecdsa::Signature {
187-
sig,
188-
hash_ty: sighash_ty,
189-
},
190-
);
183+
psbts[i].inputs[0]
184+
.partial_sigs
185+
.insert(pk, bitcoin::ecdsa::Signature { sig, hash_ty: sighash_ty });
191186
}
192187
// Add the hash preimages to the psbt
193188
psbts[i].inputs[0]

bitcoind-tests/tests/test_desc.rs

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,9 @@ pub fn test_desc_satisfy(
135135
.assume_checked();
136136
// Had to decrease 'value', so that fees can be increased
137137
// (Was getting insufficient fees error, for deep script trees)
138-
psbt.unsigned_tx.output.push(TxOut {
139-
value: 99_997_000,
140-
script_pubkey: addr.script_pubkey(),
141-
});
138+
psbt.unsigned_tx
139+
.output
140+
.push(TxOut { value: 99_997_000, script_pubkey: addr.script_pubkey() });
142141
let mut input = psbt::Input::default();
143142
input
144143
.update_with_descriptor_unchecked(&definite_desc)
@@ -178,10 +177,8 @@ pub fn test_desc_satisfy(
178177
rand::thread_rng().fill_bytes(&mut aux_rand);
179178
let schnorr_sig =
180179
secp.sign_schnorr_with_aux_rand(&msg, &internal_keypair, &aux_rand);
181-
psbt.inputs[0].tap_key_sig = Some(taproot::Signature {
182-
sig: schnorr_sig,
183-
hash_ty: hash_ty,
184-
});
180+
psbt.inputs[0].tap_key_sig =
181+
Some(taproot::Signature { sig: schnorr_sig, hash_ty: hash_ty });
185182
} else {
186183
// No internal key
187184
}
@@ -206,13 +203,9 @@ pub fn test_desc_satisfy(
206203
let sig = secp.sign_schnorr_with_aux_rand(&msg, &keypair, &aux_rand);
207204
let x_only_pk =
208205
x_only_pks[xonly_keypairs.iter().position(|&x| x == keypair).unwrap()];
209-
psbt.inputs[0].tap_script_sigs.insert(
210-
(x_only_pk, leaf_hash),
211-
taproot::Signature {
212-
sig,
213-
hash_ty: hash_ty,
214-
},
215-
);
206+
psbt.inputs[0]
207+
.tap_script_sigs
208+
.insert((x_only_pk, leaf_hash), taproot::Signature { sig, hash_ty: hash_ty });
216209
}
217210
}
218211
_ => {
@@ -261,13 +254,9 @@ pub fn test_desc_satisfy(
261254
let sig = secp.sign_ecdsa(&msg, &sk);
262255
let pk = pks[sks.iter().position(|&x| x == sk).unwrap()];
263256
assert!(secp.verify_ecdsa(&msg, &sig, &pk.inner).is_ok());
264-
psbt.inputs[0].partial_sigs.insert(
265-
pk,
266-
ecdsa::Signature {
267-
sig,
268-
hash_ty: hash_ty,
269-
},
270-
);
257+
psbt.inputs[0]
258+
.partial_sigs
259+
.insert(pk, ecdsa::Signature { sig, hash_ty: hash_ty });
271260
}
272261
}
273262
}

examples/psbt_sign_finalize.rs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,13 @@ fn main() {
8686
txin.sequence = Sequence::from_height(26); //Sequence::MAX; //
8787
psbt.unsigned_tx.input.push(txin);
8888

89-
psbt.unsigned_tx.output.push(TxOut {
90-
script_pubkey: receiver.script_pubkey(),
91-
value: amount / 5 - 500,
92-
});
89+
psbt.unsigned_tx
90+
.output
91+
.push(TxOut { script_pubkey: receiver.script_pubkey(), value: amount / 5 - 500 });
9392

94-
psbt.unsigned_tx.output.push(TxOut {
95-
script_pubkey: bridge_descriptor.script_pubkey(),
96-
value: amount * 4 / 5,
97-
});
93+
psbt.unsigned_tx
94+
.output
95+
.push(TxOut { script_pubkey: bridge_descriptor.script_pubkey(), value: amount * 4 / 5 });
9896

9997
// Generating signatures & witness data
10098

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

133-
psbt.inputs[0].partial_sigs.insert(
134-
pk1,
135-
bitcoin::ecdsa::Signature {
136-
sig: sig1,
137-
hash_ty: hash_ty,
138-
},
139-
);
131+
psbt.inputs[0]
132+
.partial_sigs
133+
.insert(pk1, bitcoin::ecdsa::Signature { sig: sig1, hash_ty: hash_ty });
140134

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

rustfmt.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ indent_style = "Block"
66
use_small_heuristics = "Default"
77
fn_call_width = 80
88
attr_fn_like_width = 70
9-
struct_lit_width = 18
9+
struct_lit_width = 80
1010
struct_variant_width = 35
1111
array_width = 60
1212
chain_width = 60

src/descriptor/checksum.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,7 @@ impl Default for Engine {
8585

8686
impl Engine {
8787
/// Construct an engine with no input
88-
pub fn new() -> Self {
89-
Engine {
90-
c: 1,
91-
cls: 0,
92-
clscount: 0,
93-
}
94-
}
88+
pub fn new() -> Self { Engine { c: 1, cls: 0, clscount: 0 } }
9589

9690
/// Checksum some data
9791
///
@@ -148,12 +142,7 @@ pub struct Formatter<'f, 'a> {
148142

149143
impl<'f, 'a> Formatter<'f, 'a> {
150144
/// Contruct a new `Formatter`, wrapping a given `fmt::Formatter`
151-
pub fn new(f: &'f mut fmt::Formatter<'a>) -> Self {
152-
Formatter {
153-
fmt: f,
154-
eng: Engine::new(),
155-
}
156-
}
145+
pub fn new(f: &'f mut fmt::Formatter<'a>) -> Self { Formatter { fmt: f, eng: Engine::new() } }
157146

158147
/// Writes the checksum into the underlying `fmt::Formatter`
159148
pub fn write_checksum(&mut self) -> fmt::Result {

src/descriptor/key.rs

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,7 @@ impl SinglePriv {
196196
fn to_public<C: Signing>(&self, secp: &Secp256k1<C>) -> SinglePub {
197197
let pub_key = self.key.public_key(secp);
198198

199-
SinglePub {
200-
origin: self.origin.clone(),
201-
key: SinglePubKey::FullKey(pub_key),
202-
}
199+
SinglePub { origin: self.origin.clone(), key: SinglePubKey::FullKey(pub_key) }
203200
}
204201
}
205202

@@ -351,12 +348,7 @@ impl DescriptorSecretKey {
351348
match self {
352349
DescriptorSecretKey::Single(..) | DescriptorSecretKey::XPrv(..) => vec![self],
353350
DescriptorSecretKey::MultiXPrv(xpub) => {
354-
let DescriptorMultiXKey {
355-
origin,
356-
xkey,
357-
derivation_paths,
358-
wildcard,
359-
} = xpub;
351+
let DescriptorMultiXKey { origin, xkey, derivation_paths, wildcard } = xpub;
360352
derivation_paths
361353
.into_paths()
362354
.into_iter()
@@ -659,12 +651,7 @@ impl DescriptorPublicKey {
659651
match self {
660652
DescriptorPublicKey::Single(..) | DescriptorPublicKey::XPub(..) => vec![self],
661653
DescriptorPublicKey::MultiXPub(xpub) => {
662-
let DescriptorMultiXKey {
663-
origin,
664-
xkey,
665-
derivation_paths,
666-
wildcard,
667-
} = xpub;
654+
let DescriptorMultiXKey { origin, xkey, derivation_paths, wildcard } = xpub;
668655
derivation_paths
669656
.into_paths()
670657
.into_iter()
@@ -691,10 +678,7 @@ impl FromStr for DescriptorSecretKey {
691678
if key_part.len() <= 52 {
692679
let sk = bitcoin::PrivateKey::from_str(key_part)
693680
.map_err(|_| DescriptorKeyParseError("Error while parsing a WIF private key"))?;
694-
Ok(DescriptorSecretKey::Single(SinglePriv {
695-
key: sk,
696-
origin: None,
697-
}))
681+
Ok(DescriptorSecretKey::Single(SinglePriv { key: sk, origin: None }))
698682
} else {
699683
let (xpriv, derivation_paths, wildcard) =
700684
parse_xkey_deriv::<bip32::ExtendedPrivKey>(key_part)?;
@@ -971,8 +955,7 @@ impl MiniscriptKey for DescriptorPublicKey {
971955
fn is_uncompressed(&self) -> bool {
972956
match self {
973957
DescriptorPublicKey::Single(SinglePub {
974-
key: SinglePubKey::FullKey(ref key),
975-
..
958+
key: SinglePubKey::FullKey(ref key), ..
976959
}) => key.is_uncompressed(),
977960
_ => false,
978961
}
@@ -981,10 +964,7 @@ impl MiniscriptKey for DescriptorPublicKey {
981964
fn is_x_only_key(&self) -> bool {
982965
matches!(
983966
self,
984-
DescriptorPublicKey::Single(SinglePub {
985-
key: SinglePubKey::XOnly(ref _key),
986-
..
987-
})
967+
DescriptorPublicKey::Single(SinglePub { key: SinglePubKey::XOnly(ref _key), .. })
988968
)
989969
}
990970

src/descriptor/mod.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,17 +1464,11 @@ mod tests {
14641464

14651465
satisfier.insert(
14661466
a,
1467-
bitcoin::ecdsa::Signature {
1468-
sig: sig_a,
1469-
hash_ty: EcdsaSighashType::All,
1470-
},
1467+
bitcoin::ecdsa::Signature { sig: sig_a, hash_ty: EcdsaSighashType::All },
14711468
);
14721469
satisfier.insert(
14731470
b,
1474-
bitcoin::ecdsa::Signature {
1475-
sig: sig_b,
1476-
hash_ty: EcdsaSighashType::All,
1477-
},
1471+
bitcoin::ecdsa::Signature { sig: sig_b, hash_ty: EcdsaSighashType::All },
14781472
);
14791473

14801474
satisfier

src/descriptor/segwitv0.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,14 @@ impl<Pk: MiniscriptKey> Wsh<Pk> {
3838
pub fn new(ms: Miniscript<Pk, Segwitv0>) -> Result<Self, Error> {
3939
// do the top-level checks
4040
Segwitv0::top_level_checks(&ms)?;
41-
Ok(Self {
42-
inner: WshInner::Ms(ms),
43-
})
41+
Ok(Self { inner: WshInner::Ms(ms) })
4442
}
4543

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

5551
/// Get the descriptor without the checksum
@@ -205,15 +201,11 @@ impl_from_tree!(
205201
if top.name == "wsh" && top.args.len() == 1 {
206202
let top = &top.args[0];
207203
if top.name == "sortedmulti" {
208-
return Ok(Wsh {
209-
inner: WshInner::SortedMulti(SortedMultiVec::from_tree(top)?),
210-
});
204+
return Ok(Wsh { inner: WshInner::SortedMulti(SortedMultiVec::from_tree(top)?) });
211205
}
212206
let sub = Miniscript::from_tree(top)?;
213207
Segwitv0::top_level_checks(&sub)?;
214-
Ok(Wsh {
215-
inner: WshInner::Ms(sub),
216-
})
208+
Ok(Wsh { inner: WshInner::Ms(sub) })
217209
} else {
218210
Err(Error::Unexpected(format!(
219211
"{}({} args) while parsing wsh descriptor",

src/descriptor/sh.rs

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -128,34 +128,24 @@ impl<Pk: MiniscriptKey> Sh<Pk> {
128128
pub fn new(ms: Miniscript<Pk, Legacy>) -> Result<Self, Error> {
129129
// do the top-level checks
130130
Legacy::top_level_checks(&ms)?;
131-
Ok(Self {
132-
inner: ShInner::Ms(ms),
133-
})
131+
Ok(Self { inner: ShInner::Ms(ms) })
134132
}
135133

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

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

153147
/// Create a new p2sh wrapper for the given wsh descriptor
154-
pub fn new_with_wsh(wsh: Wsh<Pk>) -> Self {
155-
Self {
156-
inner: ShInner::Wsh(wsh),
157-
}
158-
}
148+
pub fn new_with_wsh(wsh: Wsh<Pk>) -> Self { Self { inner: ShInner::Wsh(wsh) } }
159149

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

181169
/// Create a new p2sh wrapped wpkh from `Pk`
182170
pub fn new_wpkh(pk: Pk) -> Result<Self, Error> {
183-
Ok(Self {
184-
inner: ShInner::Wpkh(Wpkh::new(pk)?),
185-
})
171+
Ok(Self { inner: ShInner::Wpkh(Wpkh::new(pk)?) })
186172
}
187173

188174
/// Create a new p2sh wrapper for the given wpkh descriptor
189-
pub fn new_with_wpkh(wpkh: Wpkh<Pk>) -> Self {
190-
Self {
191-
inner: ShInner::Wpkh(wpkh),
192-
}
193-
}
175+
pub fn new_with_wpkh(wpkh: Wpkh<Pk>) -> Self { Self { inner: ShInner::Wpkh(wpkh) } }
194176

195177
/// Computes an upper bound on the difference between a non-satisfied
196178
/// `TxIn`'s `segwit_weight` and a satisfied `TxIn`'s `segwit_weight`

0 commit comments

Comments
 (0)