Skip to content

Commit 3c6ae26

Browse files
committed
Merge #572: Reduce line count
26bb52e Set struct_lit_width to 80 (Tobin C. Harding) ced7d77 Set fn_call_with to 80 (Tobin C. Harding) 6fe7b20 Set fn_single_line to true (Tobin C. Harding) Pull request description: This PR is formatting changes only, totally non-urgent. Reduce line count by setting a couple of rustfmt config options to be the same as they are in `rust-bitcoin`. Final patch removes whitespace in trait impl blocks, and was the impetus for this PR. ACKs for top commit: apoelstra: ACK 26bb52e Tree-SHA512: 185006a09cf8fe8f8258a19183dbd7fc1c860f125ca9a55f7903aef7bb48b8fbc3a5319f81bfa1fcb6c1fbeb47345f1c251f27ee416d3132e8322cae9c8e213f
2 parents 780dbc6 + 26bb52e commit 3c6ae26

39 files changed

+656
-2180
lines changed

bitcoind-tests/tests/setup/test_util.rs

+11-44
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

@@ -287,43 +277,20 @@ pub fn parse_test_desc(
287277

288278
// substitute hash fragments in the string as the per rules
289279
fn subs_hash_frag(ms: &str, pubdata: &PubData) -> String {
290-
let ms = ms.replace(
291-
"sha256(H)",
292-
&format!("sha256({})", &pubdata.sha256.to_string()),
293-
);
294-
let ms = ms.replace(
295-
"hash256(H)",
296-
&format!("hash256({})", &pubdata.hash256.to_string()),
297-
);
298-
let ms = ms.replace(
299-
"ripemd160(H)",
300-
&format!("ripemd160({})", &pubdata.ripemd160.to_string()),
301-
);
302-
let ms = ms.replace(
303-
"hash160(H)",
304-
&format!("hash160({})", &pubdata.hash160.to_string()),
305-
);
280+
let ms = ms.replace("sha256(H)", &format!("sha256({})", &pubdata.sha256.to_string()));
281+
let ms = ms.replace("hash256(H)", &format!("hash256({})", &pubdata.hash256.to_string()));
282+
let ms = ms.replace("ripemd160(H)", &format!("ripemd160({})", &pubdata.ripemd160.to_string()));
283+
let ms = ms.replace("hash160(H)", &format!("hash160({})", &pubdata.hash160.to_string()));
306284

307285
let mut rand_hash32 = [0u8; 32];
308286
rand::thread_rng().fill_bytes(&mut rand_hash32);
309287

310288
let mut rand_hash20 = [0u8; 20];
311289
rand::thread_rng().fill_bytes(&mut rand_hash20);
312-
let ms = ms.replace(
313-
"sha256(H!)",
314-
&format!("sha256({})", rand_hash32.to_lower_hex_string()),
315-
);
316-
let ms = ms.replace(
317-
"hash256(H!)",
318-
&format!("hash256({})", rand_hash32.to_lower_hex_string()),
319-
);
320-
let ms = ms.replace(
321-
"ripemd160(H!)",
322-
&format!("ripemd160({})", rand_hash20.to_lower_hex_string()),
323-
);
324-
let ms = ms.replace(
325-
"hash160(H!)",
326-
&format!("hash160({})", rand_hash20.to_lower_hex_string()),
327-
);
290+
let ms = ms.replace("sha256(H!)", &format!("sha256({})", rand_hash32.to_lower_hex_string()));
291+
let ms = ms.replace("hash256(H!)", &format!("hash256({})", rand_hash32.to_lower_hex_string()));
292+
let ms =
293+
ms.replace("ripemd160(H!)", &format!("ripemd160({})", rand_hash20.to_lower_hex_string()));
294+
let ms = ms.replace("hash160(H!)", &format!("hash160({})", rand_hash20.to_lower_hex_string()));
328295
ms
329296
}

bitcoind-tests/tests/test_cpp.rs

+20-41
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ where
4444
}
4545

4646
/// Quickly create a BTC amount.
47-
fn btc<F: Into<f64>>(btc: F) -> Amount {
48-
Amount::from_btc(btc.into()).unwrap()
49-
}
47+
fn btc<F: Into<f64>>(btc: F) -> Amount { Amount::from_btc(btc.into()).unwrap() }
5048

5149
// Find the Outpoint by value.
5250
// Ideally, we should find by scriptPubkey, but this
@@ -72,10 +70,7 @@ pub fn test_from_cpp_ms(cl: &Client, testdata: &TestData) {
7270
let pks = &testdata.pubdata.pks;
7371
// Generate some blocks
7472
let blocks = cl
75-
.generate_to_address(
76-
500,
77-
&cl.get_new_address(None, None).unwrap().assume_checked(),
78-
)
73+
.generate_to_address(500, &cl.get_new_address(None, None).unwrap().assume_checked())
7974
.unwrap();
8075
assert_eq!(blocks.len(), 500);
8176

@@ -98,10 +93,7 @@ pub fn test_from_cpp_ms(cl: &Client, testdata: &TestData) {
9893
}
9994
// Wait for the funds to mature.
10095
let blocks = cl
101-
.generate_to_address(
102-
50,
103-
&cl.get_new_address(None, None).unwrap().assume_checked(),
104-
)
96+
.generate_to_address(50, &cl.get_new_address(None, None).unwrap().assume_checked())
10597
.unwrap();
10698
assert_eq!(blocks.len(), 50);
10799
// Create a PSBT for each transaction.
@@ -140,10 +132,9 @@ pub fn test_from_cpp_ms(cl: &Client, testdata: &TestData) {
140132
.get_new_address(None, Some(json::AddressType::Bech32))
141133
.unwrap()
142134
.assume_checked();
143-
psbt.unsigned_tx.output.push(TxOut {
144-
value: 99_999_000,
145-
script_pubkey: addr.script_pubkey(),
146-
});
135+
psbt.unsigned_tx
136+
.output
137+
.push(TxOut { value: 99_999_000, script_pubkey: addr.script_pubkey() });
147138
let mut input = psbt::Input::default();
148139
input.witness_utxo = Some(witness_utxo);
149140
input.witness_script = Some(desc.explicit_script().unwrap());
@@ -187,32 +178,25 @@ pub fn test_from_cpp_ms(cl: &Client, testdata: &TestData) {
187178
for sk in sks_reqd {
188179
let sig = secp.sign_ecdsa(&msg, &sk);
189180
let pk = pks[sks.iter().position(|&x| x == sk).unwrap()];
190-
psbts[i].inputs[0].partial_sigs.insert(
191-
pk,
192-
bitcoin::ecdsa::Signature {
193-
sig,
194-
hash_ty: sighash_ty,
195-
},
196-
);
181+
psbts[i].inputs[0]
182+
.partial_sigs
183+
.insert(pk, bitcoin::ecdsa::Signature { sig, hash_ty: sighash_ty });
197184
}
198185
// Add the hash preimages to the psbt
199-
psbts[i].inputs[0].sha256_preimages.insert(
200-
testdata.pubdata.sha256,
201-
testdata.secretdata.sha256_pre.to_vec(),
202-
);
186+
psbts[i].inputs[0]
187+
.sha256_preimages
188+
.insert(testdata.pubdata.sha256, testdata.secretdata.sha256_pre.to_vec());
203189
psbts[i].inputs[0].hash256_preimages.insert(
204190
sha256d::Hash::from_byte_array(testdata.pubdata.hash256.to_byte_array()),
205191
testdata.secretdata.hash256_pre.to_vec(),
206192
);
207193
println!("{}", ms);
208-
psbts[i].inputs[0].hash160_preimages.insert(
209-
testdata.pubdata.hash160,
210-
testdata.secretdata.hash160_pre.to_vec(),
211-
);
212-
psbts[i].inputs[0].ripemd160_preimages.insert(
213-
testdata.pubdata.ripemd160,
214-
testdata.secretdata.ripemd160_pre.to_vec(),
215-
);
194+
psbts[i].inputs[0]
195+
.hash160_preimages
196+
.insert(testdata.pubdata.hash160, testdata.secretdata.hash160_pre.to_vec());
197+
psbts[i].inputs[0]
198+
.ripemd160_preimages
199+
.insert(testdata.pubdata.ripemd160, testdata.secretdata.ripemd160_pre.to_vec());
216200
// Finalize the transaction using psbt
217201
// Let miniscript do it's magic!
218202
if let Err(e) = psbts[i].finalize_mall_mut(&secp) {
@@ -232,10 +216,7 @@ pub fn test_from_cpp_ms(cl: &Client, testdata: &TestData) {
232216
}
233217
// Finally mine the blocks and await confirmations
234218
let _blocks = cl
235-
.generate_to_address(
236-
10,
237-
&cl.get_new_address(None, None).unwrap().assume_checked(),
238-
)
219+
.generate_to_address(10, &cl.get_new_address(None, None).unwrap().assume_checked())
239220
.unwrap();
240221
// Get the required transactions from the node mined in the blocks.
241222
for txid in spend_txids {
@@ -247,9 +228,7 @@ pub fn test_from_cpp_ms(cl: &Client, testdata: &TestData) {
247228
}
248229

249230
#[test]
250-
fn test_setup() {
251-
setup::setup();
252-
}
231+
fn test_setup() { setup::setup(); }
253232

254233
#[test]
255234
fn tests_from_cpp() {

bitcoind-tests/tests/test_desc.rs

+21-37
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ mod setup;
2525
use rand::RngCore;
2626
use setup::test_util::{self, TestData};
2727
/// Quickly create a BTC amount.
28-
fn btc<F: Into<f64>>(btc: F) -> Amount {
29-
Amount::from_btc(btc.into()).unwrap()
30-
}
28+
fn btc<F: Into<f64>>(btc: F) -> Amount { Amount::from_btc(btc.into()).unwrap() }
3129

3230
// Find the Outpoint by spk
3331
fn get_vout(cl: &Client, txid: Txid, value: u64, spk: ScriptBuf) -> (OutPoint, TxOut) {
@@ -137,10 +135,9 @@ pub fn test_desc_satisfy(
137135
.assume_checked();
138136
// Had to decrease 'value', so that fees can be increased
139137
// (Was getting insufficient fees error, for deep script trees)
140-
psbt.unsigned_tx.output.push(TxOut {
141-
value: 99_997_000,
142-
script_pubkey: addr.script_pubkey(),
143-
});
138+
psbt.unsigned_tx
139+
.output
140+
.push(TxOut { value: 99_997_000, script_pubkey: addr.script_pubkey() });
144141
let mut input = psbt::Input::default();
145142
input
146143
.update_with_descriptor_unchecked(&definite_desc)
@@ -180,10 +177,8 @@ pub fn test_desc_satisfy(
180177
rand::thread_rng().fill_bytes(&mut aux_rand);
181178
let schnorr_sig =
182179
secp.sign_schnorr_with_aux_rand(&msg, &internal_keypair, &aux_rand);
183-
psbt.inputs[0].tap_key_sig = Some(taproot::Signature {
184-
sig: schnorr_sig,
185-
hash_ty: hash_ty,
186-
});
180+
psbt.inputs[0].tap_key_sig =
181+
Some(taproot::Signature { sig: schnorr_sig, hash_ty: hash_ty });
187182
} else {
188183
// No internal key
189184
}
@@ -208,13 +203,9 @@ pub fn test_desc_satisfy(
208203
let sig = secp.sign_schnorr_with_aux_rand(&msg, &keypair, &aux_rand);
209204
let x_only_pk =
210205
x_only_pks[xonly_keypairs.iter().position(|&x| x == keypair).unwrap()];
211-
psbt.inputs[0].tap_script_sigs.insert(
212-
(x_only_pk, leaf_hash),
213-
taproot::Signature {
214-
sig,
215-
hash_ty: hash_ty,
216-
},
217-
);
206+
psbt.inputs[0]
207+
.tap_script_sigs
208+
.insert((x_only_pk, leaf_hash), taproot::Signature { sig, hash_ty: hash_ty });
218209
}
219210
}
220211
_ => {
@@ -263,33 +254,26 @@ pub fn test_desc_satisfy(
263254
let sig = secp.sign_ecdsa(&msg, &sk);
264255
let pk = pks[sks.iter().position(|&x| x == sk).unwrap()];
265256
assert!(secp.verify_ecdsa(&msg, &sig, &pk.inner).is_ok());
266-
psbt.inputs[0].partial_sigs.insert(
267-
pk,
268-
ecdsa::Signature {
269-
sig,
270-
hash_ty: hash_ty,
271-
},
272-
);
257+
psbt.inputs[0]
258+
.partial_sigs
259+
.insert(pk, ecdsa::Signature { sig, hash_ty: hash_ty });
273260
}
274261
}
275262
}
276263
// Add the hash preimages to the psbt
277-
psbt.inputs[0].sha256_preimages.insert(
278-
testdata.pubdata.sha256,
279-
testdata.secretdata.sha256_pre.to_vec(),
280-
);
264+
psbt.inputs[0]
265+
.sha256_preimages
266+
.insert(testdata.pubdata.sha256, testdata.secretdata.sha256_pre.to_vec());
281267
psbt.inputs[0].hash256_preimages.insert(
282268
sha256d::Hash::from_byte_array(testdata.pubdata.hash256.to_byte_array()),
283269
testdata.secretdata.hash256_pre.to_vec(),
284270
);
285-
psbt.inputs[0].hash160_preimages.insert(
286-
testdata.pubdata.hash160,
287-
testdata.secretdata.hash160_pre.to_vec(),
288-
);
289-
psbt.inputs[0].ripemd160_preimages.insert(
290-
testdata.pubdata.ripemd160,
291-
testdata.secretdata.ripemd160_pre.to_vec(),
292-
);
271+
psbt.inputs[0]
272+
.hash160_preimages
273+
.insert(testdata.pubdata.hash160, testdata.secretdata.hash160_pre.to_vec());
274+
psbt.inputs[0]
275+
.ripemd160_preimages
276+
.insert(testdata.pubdata.ripemd160, testdata.secretdata.ripemd160_pre.to_vec());
293277
println!("Testing descriptor: {}", definite_desc);
294278
// Finalize the transaction using psbt
295279
// Let miniscript do it's magic!

examples/psbt_sign_finalize.rs

+15-39
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,8 @@ fn main() {
2121
let bridge_descriptor = Descriptor::from_str(&s).unwrap();
2222
//let bridge_descriptor = Descriptor::<bitcoin::PublicKey>::from_str(&s).expect("parse descriptor string");
2323
assert!(bridge_descriptor.sanity_check().is_ok());
24-
println!(
25-
"Bridge pubkey script: {}",
26-
bridge_descriptor.script_pubkey()
27-
);
28-
println!(
29-
"Bridge address: {}",
30-
bridge_descriptor.address(Network::Regtest).unwrap()
31-
);
24+
println!("Bridge pubkey script: {}", bridge_descriptor.script_pubkey());
25+
println!("Bridge address: {}", bridge_descriptor.address(Network::Regtest).unwrap());
3226
println!(
3327
"Weight for witness satisfaction cost {}",
3428
bridge_descriptor.max_weight_to_satisfy().unwrap()
@@ -37,37 +31,25 @@ fn main() {
3731
let master_private_key_str = "cQhdvB3McbBJdx78VSSumqoHQiSXs75qwLptqwxSQBNBMDxafvaw";
3832
let _master_private_key =
3933
PrivateKey::from_str(master_private_key_str).expect("Can't create private key");
40-
println!(
41-
"Master public key: {}",
42-
_master_private_key.public_key(&secp256k1)
43-
);
34+
println!("Master public key: {}", _master_private_key.public_key(&secp256k1));
4435

4536
let backup1_private_key_str = "cWA34TkfWyHa3d4Vb2jNQvsWJGAHdCTNH73Rht7kAz6vQJcassky";
4637
let backup1_private =
4738
PrivateKey::from_str(backup1_private_key_str).expect("Can't create private key");
4839

49-
println!(
50-
"Backup1 public key: {}",
51-
backup1_private.public_key(&secp256k1)
52-
);
40+
println!("Backup1 public key: {}", backup1_private.public_key(&secp256k1));
5341

5442
let backup2_private_key_str = "cPJFWUKk8sdL7pcDKrmNiWUyqgovimmhaaZ8WwsByDaJ45qLREkh";
5543
let backup2_private =
5644
PrivateKey::from_str(backup2_private_key_str).expect("Can't create private key");
5745

58-
println!(
59-
"Backup2 public key: {}",
60-
backup2_private.public_key(&secp256k1)
61-
);
46+
println!("Backup2 public key: {}", backup2_private.public_key(&secp256k1));
6247

6348
let backup3_private_key_str = "cT5cH9UVm81W5QAf5KABXb23RKNSMbMzMx85y6R2mF42L94YwKX6";
6449
let _backup3_private =
6550
PrivateKey::from_str(backup3_private_key_str).expect("Can't create private key");
6651

67-
println!(
68-
"Backup3 public key: {}",
69-
_backup3_private.public_key(&secp256k1)
70-
);
52+
println!("Backup3 public key: {}", _backup3_private.public_key(&secp256k1));
7153

7254
let spend_tx = Transaction {
7355
version: 2,
@@ -104,15 +86,13 @@ fn main() {
10486
txin.sequence = Sequence::from_height(26); //Sequence::MAX; //
10587
psbt.unsigned_tx.input.push(txin);
10688

107-
psbt.unsigned_tx.output.push(TxOut {
108-
script_pubkey: receiver.script_pubkey(),
109-
value: amount / 5 - 500,
110-
});
89+
psbt.unsigned_tx
90+
.output
91+
.push(TxOut { script_pubkey: receiver.script_pubkey(), value: amount / 5 - 500 });
11192

112-
psbt.unsigned_tx.output.push(TxOut {
113-
script_pubkey: bridge_descriptor.script_pubkey(),
114-
value: amount * 4 / 5,
115-
});
93+
psbt.unsigned_tx
94+
.output
95+
.push(TxOut { script_pubkey: bridge_descriptor.script_pubkey(), value: amount * 4 / 5 });
11696

11797
// Generating signatures & witness data
11898

@@ -148,13 +128,9 @@ fn main() {
148128
let pk2 = backup2_private.public_key(&secp256k1);
149129
assert!(secp256k1.verify_ecdsa(&msg, &sig2, &pk2.inner).is_ok());
150130

151-
psbt.inputs[0].partial_sigs.insert(
152-
pk1,
153-
bitcoin::ecdsa::Signature {
154-
sig: sig1,
155-
hash_ty: hash_ty,
156-
},
157-
);
131+
psbt.inputs[0]
132+
.partial_sigs
133+
.insert(pk1, bitcoin::ecdsa::Signature { sig: sig1, hash_ty: hash_ty });
158134

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

0 commit comments

Comments
 (0)