From f41a70db0f403ac047b0e76f6585c05854bfaa60 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Thu, 27 Jul 2023 13:07:29 +1000 Subject: [PATCH] Set struct_lit_width to 80 Set `rustfmt` config option `struct_lit_width` to true and run the formatter. --- bitcoind-tests/tests/setup/test_util.rs | 14 +-- bitcoind-tests/tests/test_cpp.rs | 17 ++-- bitcoind-tests/tests/test_desc.rs | 33 +++---- examples/psbt_sign_finalize.rs | 24 ++--- rustfmt.toml | 2 +- src/descriptor/checksum.rs | 15 +-- src/descriptor/key.rs | 32 ++----- src/descriptor/mod.rs | 10 +- src/descriptor/segwitv0.rs | 16 +--- src/descriptor/sh.rs | 32 ++----- src/descriptor/sortedmulti.rs | 6 +- src/descriptor/tr.rs | 85 ++++------------- src/expression.rs | 23 +---- src/interpreter/mod.rs | 41 ++------- src/iter/tree.rs | 10 +- src/lib.rs | 10 +- src/miniscript/decode.rs | 29 +----- src/miniscript/iter.rs | 11 +-- src/miniscript/mod.rs | 7 +- src/miniscript/satisfy.rs | 116 ++++++++---------------- src/miniscript/types/correctness.rs | 49 ++-------- src/miniscript/types/extra_props.rs | 16 +--- src/miniscript/types/malleability.rs | 48 ++-------- src/miniscript/types/mod.rs | 116 +++++------------------- src/policy/compiler.rs | 54 ++--------- src/psbt/mod.rs | 38 ++------ 26 files changed, 191 insertions(+), 663 deletions(-) diff --git a/bitcoind-tests/tests/setup/test_util.rs b/bitcoind-tests/tests/setup/test_util.rs index 39a1a5c3f..c49b07741 100644 --- a/bitcoind-tests/tests/setup/test_util.rs +++ b/bitcoind-tests/tests/setup/test_util.rs @@ -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, @@ -124,10 +117,7 @@ impl TestData { hash160_pre, x_only_keypairs, }; - Self { - pubdata, - secretdata, - } + Self { pubdata, secretdata } } } diff --git a/bitcoind-tests/tests/test_cpp.rs b/bitcoind-tests/tests/test_cpp.rs index 8c7f2d826..09873443b 100644 --- a/bitcoind-tests/tests/test_cpp.rs +++ b/bitcoind-tests/tests/test_cpp.rs @@ -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()); @@ -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] diff --git a/bitcoind-tests/tests/test_desc.rs b/bitcoind-tests/tests/test_desc.rs index abb57400f..bbb2b1bf2 100644 --- a/bitcoind-tests/tests/test_desc.rs +++ b/bitcoind-tests/tests/test_desc.rs @@ -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) @@ -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 } @@ -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 }); } } _ => { @@ -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 }); } } } diff --git a/examples/psbt_sign_finalize.rs b/examples/psbt_sign_finalize.rs index 0f3728f81..08abd5abe 100644 --- a/examples/psbt_sign_finalize.rs +++ b/examples/psbt_sign_finalize.rs @@ -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 @@ -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); diff --git a/rustfmt.toml b/rustfmt.toml index 2ff868fa6..88289b24b 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -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 diff --git a/src/descriptor/checksum.rs b/src/descriptor/checksum.rs index 67b302ff1..08d16f948 100644 --- a/src/descriptor/checksum.rs +++ b/src/descriptor/checksum.rs @@ -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 /// @@ -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 { diff --git a/src/descriptor/key.rs b/src/descriptor/key.rs index d9a70522d..93c5b9231 100644 --- a/src/descriptor/key.rs +++ b/src/descriptor/key.rs @@ -196,10 +196,7 @@ impl SinglePriv { fn to_public(&self, secp: &Secp256k1) -> 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) } } } @@ -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() @@ -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() @@ -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::(key_part)?; @@ -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, } @@ -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), .. }) ) } diff --git a/src/descriptor/mod.rs b/src/descriptor/mod.rs index a3eba632f..87db1d240 100644 --- a/src/descriptor/mod.rs +++ b/src/descriptor/mod.rs @@ -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 diff --git a/src/descriptor/segwitv0.rs b/src/descriptor/segwitv0.rs index 883b0a70c..e79f1de82 100644 --- a/src/descriptor/segwitv0.rs +++ b/src/descriptor/segwitv0.rs @@ -38,18 +38,14 @@ impl Wsh { pub fn new(ms: Miniscript) -> Result { // 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) -> Result { // 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 @@ -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", diff --git a/src/descriptor/sh.rs b/src/descriptor/sh.rs index 523d005d7..e4f35cc30 100644 --- a/src/descriptor/sh.rs +++ b/src/descriptor/sh.rs @@ -128,9 +128,7 @@ impl Sh { pub fn new(ms: Miniscript) -> Result { // 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` @@ -138,24 +136,16 @@ impl Sh { pub fn new_sortedmulti(k: usize, pks: Vec) -> Result { // 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) -> Result { - 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) -> Self { - Self { - inner: ShInner::Wsh(wsh), - } - } + pub fn new_with_wsh(wsh: Wsh) -> Self { Self { inner: ShInner::Wsh(wsh) } } /// Checks whether the descriptor is safe. pub fn sanity_check(&self) -> Result<(), Error> { @@ -173,24 +163,16 @@ impl Sh { pub fn new_wsh_sortedmulti(k: usize, pks: Vec) -> Result { // 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 { - 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) -> Self { - Self { - inner: ShInner::Wpkh(wpkh), - } - } + pub fn new_with_wpkh(wpkh: Wpkh) -> 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` diff --git a/src/descriptor/sortedmulti.rs b/src/descriptor/sortedmulti.rs index f2a6f3a9b..79bccc270 100644 --- a/src/descriptor/sortedmulti.rs +++ b/src/descriptor/sortedmulti.rs @@ -51,11 +51,7 @@ impl SortedMultiVec { // even tapscript in future Ctx::check_local_validity(&ms)?; - Ok(Self { - k, - pks, - phantom: PhantomData, - }) + Ok(Self { k, pks, phantom: PhantomData }) } /// Parse an expression tree into a SortedMultiVec pub fn from_tree(tree: &expression::Tree) -> Result diff --git a/src/descriptor/tr.rs b/src/descriptor/tr.rs index bfbac39d4..a4fb985c5 100644 --- a/src/descriptor/tr.rs +++ b/src/descriptor/tr.rs @@ -117,32 +117,20 @@ impl TapTree { /// Creates a `TapTree` by combining `left` and `right` tree nodes. pub(crate) fn combine(left: TapTree, right: TapTree) -> Self { let height = 1 + cmp::max(left.height(), right.height()); - TapTree::Tree { - left: Arc::new(left), - right: Arc::new(right), - height, - } + TapTree::Tree { left: Arc::new(left), right: Arc::new(right), height } } /// Returns the height of this tree. fn height(&self) -> usize { match *self { - TapTree::Tree { - left: _, - right: _, - height, - } => height, + TapTree::Tree { left: _, right: _, height } => height, TapTree::Leaf(..) => 0, } } /// Iterates over all miniscripts in DFS walk order compatible with the /// PSBT requirements (BIP 371). - pub fn iter(&self) -> TapTreeIter { - TapTreeIter { - stack: vec![(0, self)], - } - } + pub fn iter(&self) -> TapTreeIter { TapTreeIter { stack: vec![(0, self)] } } // Helper function to translate keys fn translate_helper(&self, t: &mut T) -> Result, TranslateErr> @@ -151,11 +139,7 @@ impl TapTree { Q: MiniscriptKey, { let frag = match *self { - TapTree::Tree { - ref left, - ref right, - ref height, - } => TapTree::Tree { + TapTree::Tree { ref left, ref right, ref height } => TapTree::Tree { left: Arc::new(left.translate_helper(t)?), right: Arc::new(right.translate_helper(t)?), height: *height, @@ -169,11 +153,9 @@ impl TapTree { impl fmt::Display for TapTree { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - TapTree::Tree { - ref left, - ref right, - height: _, - } => write!(f, "{{{},{}}}", *left, *right), + TapTree::Tree { ref left, ref right, height: _ } => { + write!(f, "{{{},{}}}", *left, *right) + } TapTree::Leaf(ref script) => write!(f, "{}", *script), } } @@ -182,11 +164,9 @@ impl fmt::Display for TapTree { impl fmt::Debug for TapTree { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - TapTree::Tree { - ref left, - ref right, - height: _, - } => write!(f, "{{{:?},{:?}}}", *left, *right), + TapTree::Tree { ref left, ref right, height: _ } => { + write!(f, "{{{:?},{:?}}}", *left, *right) + } TapTree::Leaf(ref script) => write!(f, "{:?}", *script), } } @@ -199,11 +179,7 @@ impl Tr { let nodes = tree.as_ref().map(|t| t.height()).unwrap_or(0); if nodes <= TAPROOT_CONTROL_MAX_NODE_COUNT { - Ok(Self { - internal_key, - tree, - spend_info: Mutex::new(None), - }) + Ok(Self { internal_key, tree, spend_info: Mutex::new(None) }) } else { Err(Error::MaxRecursiveDepthExceeded) } @@ -436,11 +412,7 @@ where fn next(&mut self) -> Option { while let Some((depth, last)) = self.stack.pop() { match *last { - TapTree::Tree { - ref left, - ref right, - height: _, - } => { + TapTree::Tree { ref left, ref right, height: _ } => { self.stack.push((depth + 1, right)); self.stack.push((depth + 1, left)); } @@ -560,14 +532,8 @@ fn parse_tr_tree(s: &str) -> Result { if !key.args.is_empty() { return Err(Error::Unexpected("invalid taproot internal key".to_string())); } - let internal_key = expression::Tree { - name: key.name, - args: vec![], - }; - return Ok(expression::Tree { - name: "tr", - args: vec![internal_key], - }); + let internal_key = expression::Tree { name: key.name, args: vec![] }; + return Ok(expression::Tree { name: "tr", args: vec![internal_key] }); } // use str::split_once() method to refactor this when compiler version bumps up let (key, script) = split_once(rest, ',') @@ -577,22 +543,13 @@ fn parse_tr_tree(s: &str) -> Result { if !key.args.is_empty() { return Err(Error::Unexpected("invalid taproot internal key".to_string())); } - let internal_key = expression::Tree { - name: key.name, - args: vec![], - }; + let internal_key = expression::Tree { name: key.name, args: vec![] }; if script.is_empty() { - return Ok(expression::Tree { - name: "tr", - args: vec![internal_key], - }); + return Ok(expression::Tree { name: "tr", args: vec![internal_key] }); } let (tree, rest) = expression::Tree::from_slice_delim(script, 1, '{')?; if rest.is_empty() { - Ok(expression::Tree { - name: "tr", - args: vec![internal_key, tree], - }) + Ok(expression::Tree { name: "tr", args: vec![internal_key, tree] }) } else { Err(errstr(rest)) } @@ -619,11 +576,9 @@ impl Liftable for TapTree { fn lift(&self) -> Result, Error> { fn lift_helper(s: &TapTree) -> Result, Error> { match *s { - TapTree::Tree { - ref left, - ref right, - height: _, - } => Ok(Policy::Threshold(1, vec![lift_helper(left)?, lift_helper(right)?])), + TapTree::Tree { ref left, ref right, height: _ } => { + Ok(Policy::Threshold(1, vec![lift_helper(left)?, lift_helper(right)?])) + } TapTree::Leaf(ref leaf) => leaf.lift(), } } diff --git a/src/expression.rs b/src/expression.rs index dc97e0b1a..7875284de 100644 --- a/src/expression.rs +++ b/src/expression.rs @@ -137,27 +137,14 @@ impl<'a> Tree<'a> { match next_expr(sl, delim) { // String-ending terminal - Found::Nothing => Ok(( - Tree { - name: sl, - args: vec![], - }, - "", - )), + Found::Nothing => Ok((Tree { name: sl, args: vec![] }, "")), // Terminal - Found::Comma(n) | Found::RBracket(n) => Ok(( - Tree { - name: &sl[..n], - args: vec![], - }, - &sl[n..], - )), + Found::Comma(n) | Found::RBracket(n) => { + Ok((Tree { name: &sl[..n], args: vec![] }, &sl[n..])) + } // Function call Found::LBracket(n) => { - let mut ret = Tree { - name: &sl[..n], - args: vec![], - }; + let mut ret = Tree { name: &sl[..n], args: vec![] }; sl = &sl[n + 1..]; loop { diff --git a/src/interpreter/mod.rs b/src/interpreter/mod.rs index 704bdcb00..906989a04 100644 --- a/src/interpreter/mod.rs +++ b/src/interpreter/mod.rs @@ -140,13 +140,7 @@ impl<'txin> Interpreter<'txin> { lock_time: absolute::LockTime, // CLTV, absolute lock time. ) -> Result { let (inner, stack, script_code) = inner::from_txdata(spk, script_sig, witness)?; - Ok(Interpreter { - inner, - stack, - script_code, - age, - lock_time, - }) + Ok(Interpreter { inner, stack, script_code, age, lock_time }) } /// Same as [`Interpreter::iter`], but allows for a custom verification function. @@ -164,11 +158,7 @@ impl<'txin> Interpreter<'txin> { None }, state: if let inner::Inner::Script(ref script, _) = self.inner { - vec![NodeEvaluationState { - node: script, - n_evaluated: 0, - n_satisfied: 0, - }] + vec![NodeEvaluationState { node: script, n_evaluated: 0, n_satisfied: 0 }] } else { vec![] }, @@ -559,11 +549,8 @@ where n_evaluated: usize, n_satisfied: usize, ) { - self.state.push(NodeEvaluationState { - node, - n_evaluated, - n_satisfied, - }) + self.state + .push(NodeEvaluationState { node, n_evaluated, n_satisfied }) } /// Helper function to step the iterator @@ -1129,11 +1116,7 @@ mod tests { verify_sig: verify_fn, stack, public_key: None, - state: vec![NodeEvaluationState { - node: ms, - n_evaluated: 0, - n_satisfied: 0, - }], + state: vec![NodeEvaluationState { node: ms, n_evaluated: 0, n_satisfied: 0 }], age: Sequence::from_height(1002), lock_time: absolute::LockTime::from_height(1002).unwrap(), has_errored: false, @@ -1206,9 +1189,7 @@ mod tests { let older_satisfied: Result, Error> = constraints.collect(); assert_eq!( older_satisfied.unwrap(), - vec![SatisfiedConstraint::RelativeTimelock { - n: Sequence::from_height(1000) - }] + vec![SatisfiedConstraint::RelativeTimelock { n: Sequence::from_height(1000) }] ); //Check Sha256 @@ -1298,10 +1279,7 @@ mod tests { SatisfiedConstraint::PublicKey { key_sig: KeySigPair::Ecdsa(pks[0], ecdsa_sigs[0]) }, - SatisfiedConstraint::HashLock { - hash: HashLockType::Sha256(sha256_hash), - preimage, - } + SatisfiedConstraint::HashLock { hash: HashLockType::Sha256(sha256_hash), preimage } ] ); @@ -1323,10 +1301,7 @@ mod tests { SatisfiedConstraint::PublicKey { key_sig: KeySigPair::Ecdsa(pks[0], ecdsa_sigs[0]) }, - SatisfiedConstraint::HashLock { - hash: HashLockType::Sha256(sha256_hash), - preimage, - } + SatisfiedConstraint::HashLock { hash: HashLockType::Sha256(sha256_hash), preimage } ] ); diff --git a/src/iter/tree.rs b/src/iter/tree.rs index 29009c2e3..cc58a6cf7 100644 --- a/src/iter/tree.rs +++ b/src/iter/tree.rs @@ -72,10 +72,7 @@ pub trait TreeLike: Clone + Sized { /// then adding a stack to manually track which items and their children have been /// yielded, you may be better off using this iterator instead. fn verbose_pre_order_iter(self) -> VerbosePreOrderIter { - VerbosePreOrderIter { - stack: vec![PreOrderIterItem::initial(self, None)], - index: 0, - } + VerbosePreOrderIter { stack: vec![PreOrderIterItem::initial(self, None)], index: 0 } } /// Obtains an iterator of all the nodes rooted at the DAG, in post order. @@ -83,10 +80,7 @@ pub trait TreeLike: Clone + Sized { /// Each node is only yielded once, at the leftmost position that it /// appears in the DAG. fn post_order_iter(self) -> PostOrderIter { - PostOrderIter { - index: 0, - stack: vec![IterStackItem::unprocessed(self, None)], - } + PostOrderIter { index: 0, stack: vec![IterStackItem::unprocessed(self, None)] } } } diff --git a/src/lib.rs b/src/lib.rs index 324601be6..d93718bc9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -847,16 +847,10 @@ mod prelude { } impl Mutex { - pub fn new(inner: T) -> Mutex { - Mutex { - inner: RefCell::new(inner), - } - } + pub fn new(inner: T) -> Mutex { Mutex { inner: RefCell::new(inner) } } pub fn lock<'a>(&'a self) -> LockResult> { - Ok(MutexGuard { - lock: self.inner.borrow_mut(), - }) + Ok(MutexGuard { lock: self.inner.borrow_mut() }) } } } diff --git a/src/miniscript/decode.rs b/src/miniscript/decode.rs index 48e883738..76afee62d 100644 --- a/src/miniscript/decode.rs +++ b/src/miniscript/decode.rs @@ -217,12 +217,7 @@ impl TerminalStack { fn reduce0(&mut self, ms: Terminal) -> Result<(), Error> { let ty = Type::type_check(&ms, return_none)?; let ext = ExtData::type_check(&ms, return_none)?; - let ms = Miniscript { - node: ms, - ty, - ext, - phantom: PhantomData, - }; + let ms = Miniscript { node: ms, ty, ext, phantom: PhantomData }; Ctx::check_global_validity(&ms)?; self.0.push(ms); Ok(()) @@ -238,12 +233,7 @@ impl TerminalStack { let ty = Type::type_check(&wrapped_ms, return_none)?; let ext = ExtData::type_check(&wrapped_ms, return_none)?; - let ms = Miniscript { - node: wrapped_ms, - ty, - ext, - phantom: PhantomData, - }; + let ms = Miniscript { node: wrapped_ms, ty, ext, phantom: PhantomData }; Ctx::check_global_validity(&ms)?; self.0.push(ms); Ok(()) @@ -261,12 +251,7 @@ impl TerminalStack { let ty = Type::type_check(&wrapped_ms, return_none)?; let ext = ExtData::type_check(&wrapped_ms, return_none)?; - let ms = Miniscript { - node: wrapped_ms, - ty, - ext, - phantom: PhantomData, - }; + let ms = Miniscript { node: wrapped_ms, ty, ext, phantom: PhantomData }; Ctx::check_global_validity(&ms)?; self.0.push(ms); Ok(()) @@ -551,12 +536,8 @@ pub fn parse( let ty = Type::type_check(&wrapped_ms, return_none)?; let ext = ExtData::type_check(&wrapped_ms, return_none)?; - term.0.push(Miniscript { - node: wrapped_ms, - ty, - ext, - phantom: PhantomData, - }); + term.0 + .push(Miniscript { node: wrapped_ms, ty, ext, phantom: PhantomData }); } Some(NonTerm::ThreshW { n, k }) => { match_token!( diff --git a/src/miniscript/iter.rs b/src/miniscript/iter.rs index 6df228aad..1e8f016b7 100644 --- a/src/miniscript/iter.rs +++ b/src/miniscript/iter.rs @@ -115,10 +115,7 @@ pub struct Iter<'a, Pk: MiniscriptKey, Ctx: ScriptContext> { impl<'a, Pk: MiniscriptKey, Ctx: ScriptContext> Iter<'a, Pk, Ctx> { fn new(miniscript: &'a Miniscript) -> Self { - Iter { - next: Some(miniscript), - path: vec![], - } + Iter { next: Some(miniscript), path: vec![] } } } @@ -176,11 +173,7 @@ pub struct PkIter<'a, Pk: MiniscriptKey, Ctx: ScriptContext> { impl<'a, Pk: MiniscriptKey, Ctx: ScriptContext> PkIter<'a, Pk, Ctx> { fn new(miniscript: &'a Miniscript) -> Self { let mut iter = Iter::new(miniscript); - PkIter { - curr_node: iter.next(), - node_iter: iter, - key_index: 0, - } + PkIter { curr_node: iter.next(), node_iter: iter, key_index: 0 } } } diff --git a/src/miniscript/mod.rs b/src/miniscript/mod.rs index 198c52a9d..0aa8b61fc 100644 --- a/src/miniscript/mod.rs +++ b/src/miniscript/mod.rs @@ -87,12 +87,7 @@ impl Miniscript { ty: types::Type, ext: types::extra_props::ExtData, ) -> Miniscript { - Miniscript { - node, - ty, - ext, - phantom: PhantomData, - } + Miniscript { node, ty, ext, phantom: PhantomData } } /// Extracts the `AstElem` representing the root of the miniscript diff --git a/src/miniscript/satisfy.rs b/src/miniscript/satisfy.rs index 015bcd4b3..fcdb9f9d1 100644 --- a/src/miniscript/satisfy.rs +++ b/src/miniscript/satisfy.rs @@ -769,10 +769,7 @@ impl Satisfaction { for sat in &ret_stack { assert!(!sat.has_sig); } - Satisfaction { - stack: Witness::Unavailable, - has_sig: false, - } + Satisfaction { stack: Witness::Unavailable, has_sig: false } } else { // Otherwise flatten everything out Satisfaction { @@ -870,28 +867,16 @@ impl Satisfaction { match (sat1.has_sig, sat2.has_sig) { // If neither option has a signature, this is a malleability // vector, so choose neither one. - (false, false) => Satisfaction { - stack: Witness::Unavailable, - has_sig: false, - }, + (false, false) => Satisfaction { stack: Witness::Unavailable, has_sig: false }, // If only one has a signature, take the one that doesn't; a // third party could malleate by removing the signature, but // can't malleate if he'd have to add it - (false, true) => Satisfaction { - stack: sat1.stack, - has_sig: false, - }, - (true, false) => Satisfaction { - stack: sat2.stack, - has_sig: false, - }, + (false, true) => Satisfaction { stack: sat1.stack, has_sig: false }, + (true, false) => Satisfaction { stack: sat2.stack, has_sig: false }, // If both have a signature associated with them, choose the // cheaper one (where "cheaper" is defined such that available // things are cheaper than unavailable ones) - (true, true) => Satisfaction { - stack: cmp::min(sat1.stack, sat2.stack), - has_sig: true, - }, + (true, true) => Satisfaction { stack: cmp::min(sat1.stack, sat2.stack), has_sig: true }, } } @@ -986,30 +971,20 @@ impl Satisfaction { has_sig: false, }, - Terminal::Ripemd160(ref h) => Satisfaction { - stack: Witness::ripemd160_preimage(stfr, h), - has_sig: false, - }, - Terminal::Hash160(ref h) => Satisfaction { - stack: Witness::hash160_preimage(stfr, h), - has_sig: false, - }, - Terminal::Sha256(ref h) => Satisfaction { - stack: Witness::sha256_preimage(stfr, h), - has_sig: false, - }, - Terminal::Hash256(ref h) => Satisfaction { - stack: Witness::hash256_preimage(stfr, h), - has_sig: false, - }, - Terminal::True => Satisfaction { - stack: Witness::empty(), - has_sig: false, - }, - Terminal::False => Satisfaction { - stack: Witness::Impossible, - has_sig: false, - }, + Terminal::Ripemd160(ref h) => { + Satisfaction { stack: Witness::ripemd160_preimage(stfr, h), has_sig: false } + } + Terminal::Hash160(ref h) => { + Satisfaction { stack: Witness::hash160_preimage(stfr, h), has_sig: false } + } + Terminal::Sha256(ref h) => { + Satisfaction { stack: Witness::sha256_preimage(stfr, h), has_sig: false } + } + Terminal::Hash256(ref h) => { + Satisfaction { stack: Witness::hash256_preimage(stfr, h), has_sig: false } + } + Terminal::True => Satisfaction { stack: Witness::empty(), has_sig: false }, + Terminal::False => Satisfaction { stack: Witness::Impossible, has_sig: false }, Terminal::Alt(ref sub) | Terminal::Swap(ref sub) | Terminal::Check(ref sub) @@ -1166,10 +1141,7 @@ impl Satisfaction { } if sig_count < k { - Satisfaction { - stack: Witness::Impossible, - has_sig: false, - } + Satisfaction { stack: Witness::Impossible, has_sig: false } } else { // Throw away the most expensive ones for _ in 0..sig_count - k { @@ -1215,10 +1187,7 @@ impl Satisfaction { } if sig_count < k { - Satisfaction { - stack: Witness::Impossible, - has_sig: false, - } + Satisfaction { stack: Witness::Impossible, has_sig: false } } else { Satisfaction { stack: sigs.into_iter().fold(Witness::empty(), |acc, sig| { @@ -1255,10 +1224,7 @@ impl Satisfaction { ) -> Satisfaction, { match *term { - Terminal::PkK(..) => Satisfaction { - stack: Witness::push_0(), - has_sig: false, - }, + Terminal::PkK(..) => Satisfaction { stack: Witness::push_0(), has_sig: false }, Terminal::PkH(ref pk) => { let pk_bytes = match Ctx::sig_type() { SigType::Ecdsa => pk.to_public_key().to_bytes(), @@ -1276,35 +1242,27 @@ impl Satisfaction { ), has_sig: false, }, - Terminal::False => Satisfaction { - stack: Witness::empty(), - has_sig: false, - }, + Terminal::False => Satisfaction { stack: Witness::empty(), has_sig: false }, Terminal::True | Terminal::Older(_) | Terminal::After(_) | Terminal::Verify(_) - | Terminal::OrC(..) => Satisfaction { - stack: Witness::Impossible, - has_sig: false, - }, + | Terminal::OrC(..) => Satisfaction { stack: Witness::Impossible, has_sig: false }, Terminal::Sha256(_) | Terminal::Hash256(_) | Terminal::Ripemd160(_) - | Terminal::Hash160(_) => Satisfaction { - stack: Witness::hash_dissatisfaction(), - has_sig: false, - }, + | Terminal::Hash160(_) => { + Satisfaction { stack: Witness::hash_dissatisfaction(), has_sig: false } + } Terminal::Alt(ref sub) | Terminal::Swap(ref sub) | Terminal::Check(ref sub) | Terminal::ZeroNotEqual(ref sub) => { Self::dissatisfy_helper(&sub.node, stfr, root_has_sig, leaf_hash, min_fn, thresh_fn) } - Terminal::DupIf(_) | Terminal::NonZero(_) => Satisfaction { - stack: Witness::push_0(), - has_sig: false, - }, + Terminal::DupIf(_) | Terminal::NonZero(_) => { + Satisfaction { stack: Witness::push_0(), has_sig: false } + } Terminal::AndV(ref v, ref other) => { let vsat = Self::satisfy_helper(&v.node, stfr, root_has_sig, leaf_hash, min_fn, thresh_fn); @@ -1391,14 +1349,12 @@ impl Satisfaction { }), has_sig: false, }, - Terminal::Multi(k, _) => Satisfaction { - stack: Witness::Stack(vec![vec![]; k + 1]), - has_sig: false, - }, - Terminal::MultiA(_, ref pks) => Satisfaction { - stack: Witness::Stack(vec![vec![]; pks.len()]), - has_sig: false, - }, + Terminal::Multi(k, _) => { + Satisfaction { stack: Witness::Stack(vec![vec![]; k + 1]), has_sig: false } + } + Terminal::MultiA(_, ref pks) => { + Satisfaction { stack: Witness::Stack(vec![vec![]; pks.len()]), has_sig: false } + } } } diff --git a/src/miniscript/types/correctness.rs b/src/miniscript/types/correctness.rs index a4c3b2fa9..74b6b62ce 100644 --- a/src/miniscript/types/correctness.rs +++ b/src/miniscript/types/correctness.rs @@ -114,30 +114,15 @@ impl Property for Correctness { } fn from_true() -> Self { - Correctness { - base: Base::B, - input: Input::Zero, - dissatisfiable: false, - unit: true, - } + Correctness { base: Base::B, input: Input::Zero, dissatisfiable: false, unit: true } } fn from_false() -> Self { - Correctness { - base: Base::B, - input: Input::Zero, - dissatisfiable: true, - unit: true, - } + Correctness { base: Base::B, input: Input::Zero, dissatisfiable: true, unit: true } } fn from_pk_k() -> Self { - Correctness { - base: Base::K, - input: Input::OneNonZero, - dissatisfiable: true, - unit: true, - } + Correctness { base: Base::K, input: Input::OneNonZero, dissatisfiable: true, unit: true } } fn from_pk_h() -> Self { @@ -150,39 +135,19 @@ impl Property for Correctness { } fn from_multi(_: usize, _: usize) -> Self { - Correctness { - base: Base::B, - input: Input::AnyNonZero, - dissatisfiable: true, - unit: true, - } + Correctness { base: Base::B, input: Input::AnyNonZero, dissatisfiable: true, unit: true } } fn from_multi_a(_: usize, _: usize) -> Self { - Correctness { - base: Base::B, - input: Input::Any, - dissatisfiable: true, - unit: true, - } + Correctness { base: Base::B, input: Input::Any, dissatisfiable: true, unit: true } } fn from_hash() -> Self { - Correctness { - base: Base::B, - input: Input::OneNonZero, - dissatisfiable: true, - unit: true, - } + Correctness { base: Base::B, input: Input::OneNonZero, dissatisfiable: true, unit: true } } fn from_time(_: u32) -> Self { - Correctness { - base: Base::B, - input: Input::Zero, - dissatisfiable: false, - unit: false, - } + Correctness { base: Base::B, input: Input::Zero, dissatisfiable: false, unit: false } } fn cast_alt(self) -> Result { diff --git a/src/miniscript/types/extra_props.rs b/src/miniscript/types/extra_props.rs index 63a0f6483..56096745d 100644 --- a/src/miniscript/types/extra_props.rs +++ b/src/miniscript/types/extra_props.rs @@ -43,11 +43,7 @@ pub struct OpLimits { impl OpLimits { /// Creates a new instance of [`OpLimits`] pub fn new(op_static: usize, op_sat: Option, op_nsat: Option) -> Self { - OpLimits { - count: op_static, - sat: op_sat, - nsat: op_nsat, - } + OpLimits { count: op_static, sat: op_sat, nsat: op_nsat } } /// Worst case opcode count when this element is satisfied @@ -874,10 +870,7 @@ impl Property for ExtData { Pk: MiniscriptKey, { let wrap_err = |result: Result| { - result.map_err(|kind| Error { - fragment: fragment.clone(), - error: kind, - }) + result.map_err(|kind| Error { fragment: fragment.clone(), error: kind }) }; let ret = match *fragment { @@ -988,10 +981,7 @@ impl Property for ExtData { let res = Self::threshold(k, subs.len(), |n| Ok(subs[n].ext)); - res.map_err(|kind| Error { - fragment: fragment.clone(), - error: kind, - }) + res.map_err(|kind| Error { fragment: fragment.clone(), error: kind }) } }; if let Ok(ref ret) = ret { diff --git a/src/miniscript/types/malleability.rs b/src/miniscript/types/malleability.rs index aef62ce6e..a0bc53122 100644 --- a/src/miniscript/types/malleability.rs +++ b/src/miniscript/types/malleability.rs @@ -68,67 +68,35 @@ impl Malleability { impl Property for Malleability { fn from_true() -> Self { - Malleability { - dissat: Dissat::None, - safe: false, - non_malleable: true, - } + Malleability { dissat: Dissat::None, safe: false, non_malleable: true } } fn from_false() -> Self { - Malleability { - dissat: Dissat::Unique, - safe: true, - non_malleable: true, - } + Malleability { dissat: Dissat::Unique, safe: true, non_malleable: true } } fn from_pk_k() -> Self { - Malleability { - dissat: Dissat::Unique, - safe: true, - non_malleable: true, - } + Malleability { dissat: Dissat::Unique, safe: true, non_malleable: true } } fn from_pk_h() -> Self { - Malleability { - dissat: Dissat::Unique, - safe: true, - non_malleable: true, - } + Malleability { dissat: Dissat::Unique, safe: true, non_malleable: true } } fn from_multi(_: usize, _: usize) -> Self { - Malleability { - dissat: Dissat::Unique, - safe: true, - non_malleable: true, - } + Malleability { dissat: Dissat::Unique, safe: true, non_malleable: true } } fn from_multi_a(_: usize, _: usize) -> Self { - Malleability { - dissat: Dissat::Unique, - safe: true, - non_malleable: true, - } + Malleability { dissat: Dissat::Unique, safe: true, non_malleable: true } } fn from_hash() -> Self { - Malleability { - dissat: Dissat::Unknown, - safe: false, - non_malleable: true, - } + Malleability { dissat: Dissat::Unknown, safe: false, non_malleable: true } } fn from_time(_: u32) -> Self { - Malleability { - dissat: Dissat::None, - safe: false, - non_malleable: true, - } + Malleability { dissat: Dissat::None, safe: false, non_malleable: true } } fn cast_alt(self) -> Result { Ok(self) } diff --git a/src/miniscript/types/mod.rs b/src/miniscript/types/mod.rs index 53c244c7e..aa542f9e6 100644 --- a/src/miniscript/types/mod.rs +++ b/src/miniscript/types/mod.rs @@ -367,10 +367,7 @@ pub trait Property: Sized { .unwrap_or_else(|| Self::type_check(sub, return_none)) }; let wrap_err = |result: Result| { - result.map_err(|kind| Error { - fragment: fragment.clone(), - error: kind, - }) + result.map_err(|kind| Error { fragment: fragment.clone(), error: kind }) }; let ret = match *fragment { @@ -511,130 +508,70 @@ impl Property for Type { debug_assert!(self.mall.non_malleable || self.corr.input != Input::Zero); } - fn from_true() -> Self { - Type { - corr: Property::from_true(), - mall: Property::from_true(), - } - } + fn from_true() -> Self { Type { corr: Property::from_true(), mall: Property::from_true() } } - fn from_false() -> Self { - Type { - corr: Property::from_false(), - mall: Property::from_false(), - } - } + fn from_false() -> Self { Type { corr: Property::from_false(), mall: Property::from_false() } } fn from_pk_k() -> Self { - Type { - corr: Property::from_pk_k::(), - mall: Property::from_pk_k::(), - } + Type { corr: Property::from_pk_k::(), mall: Property::from_pk_k::() } } fn from_pk_h() -> Self { - Type { - corr: Property::from_pk_h::(), - mall: Property::from_pk_h::(), - } + Type { corr: Property::from_pk_h::(), mall: Property::from_pk_h::() } } fn from_multi(k: usize, n: usize) -> Self { - Type { - corr: Property::from_multi(k, n), - mall: Property::from_multi(k, n), - } + Type { corr: Property::from_multi(k, n), mall: Property::from_multi(k, n) } } fn from_multi_a(k: usize, n: usize) -> Self { - Type { - corr: Property::from_multi_a(k, n), - mall: Property::from_multi_a(k, n), - } + Type { corr: Property::from_multi_a(k, n), mall: Property::from_multi_a(k, n) } } - fn from_hash() -> Self { - Type { - corr: Property::from_hash(), - mall: Property::from_hash(), - } - } + fn from_hash() -> Self { Type { corr: Property::from_hash(), mall: Property::from_hash() } } fn from_sha256() -> Self { - Type { - corr: Property::from_sha256(), - mall: Property::from_sha256(), - } + Type { corr: Property::from_sha256(), mall: Property::from_sha256() } } fn from_hash256() -> Self { - Type { - corr: Property::from_hash256(), - mall: Property::from_hash256(), - } + Type { corr: Property::from_hash256(), mall: Property::from_hash256() } } fn from_ripemd160() -> Self { - Type { - corr: Property::from_ripemd160(), - mall: Property::from_ripemd160(), - } + Type { corr: Property::from_ripemd160(), mall: Property::from_ripemd160() } } fn from_hash160() -> Self { - Type { - corr: Property::from_hash160(), - mall: Property::from_hash160(), - } + Type { corr: Property::from_hash160(), mall: Property::from_hash160() } } fn from_time(t: u32) -> Self { - Type { - corr: Property::from_time(t), - mall: Property::from_time(t), - } + Type { corr: Property::from_time(t), mall: Property::from_time(t) } } fn from_after(t: absolute::LockTime) -> Self { - Type { - corr: Property::from_after(t), - mall: Property::from_after(t), - } + Type { corr: Property::from_after(t), mall: Property::from_after(t) } } fn from_older(t: Sequence) -> Self { - Type { - corr: Property::from_older(t), - mall: Property::from_older(t), - } + Type { corr: Property::from_older(t), mall: Property::from_older(t) } } fn cast_alt(self) -> Result { - Ok(Type { - corr: Property::cast_alt(self.corr)?, - mall: Property::cast_alt(self.mall)?, - }) + Ok(Type { corr: Property::cast_alt(self.corr)?, mall: Property::cast_alt(self.mall)? }) } fn cast_swap(self) -> Result { - Ok(Type { - corr: Property::cast_swap(self.corr)?, - mall: Property::cast_swap(self.mall)?, - }) + Ok(Type { corr: Property::cast_swap(self.corr)?, mall: Property::cast_swap(self.mall)? }) } fn cast_check(self) -> Result { - Ok(Type { - corr: Property::cast_check(self.corr)?, - mall: Property::cast_check(self.mall)?, - }) + Ok(Type { corr: Property::cast_check(self.corr)?, mall: Property::cast_check(self.mall)? }) } fn cast_dupif(self) -> Result { - Ok(Type { - corr: Property::cast_dupif(self.corr)?, - mall: Property::cast_dupif(self.mall)?, - }) + Ok(Type { corr: Property::cast_dupif(self.corr)?, mall: Property::cast_dupif(self.mall)? }) } fn cast_verify(self) -> Result { @@ -659,10 +596,7 @@ impl Property for Type { } fn cast_true(self) -> Result { - Ok(Type { - corr: Property::cast_true(self.corr)?, - mall: Property::cast_true(self.mall)?, - }) + Ok(Type { corr: Property::cast_true(self.corr)?, mall: Property::cast_true(self.mall)? }) } fn cast_or_i_false(self) -> Result { @@ -757,10 +691,7 @@ impl Property for Type { Ctx: ScriptContext, { let wrap_err = |result: Result| { - result.map_err(|kind| Error { - fragment: fragment.clone(), - error: kind, - }) + result.map_err(|kind| Error { fragment: fragment.clone(), error: kind }) }; let ret = match *fragment { @@ -871,10 +802,7 @@ impl Property for Type { let res = Self::threshold(k, subs.len(), |n| Ok(subs[n].ty)); - res.map_err(|kind| Error { - fragment: fragment.clone(), - error: kind, - }) + res.map_err(|kind| Error { fragment: fragment.clone(), error: kind }) } }; if let Ok(ref ret) = ret { diff --git a/src/policy/compiler.rs b/src/policy/compiler.rs index 06f100f37..d7905c000 100644 --- a/src/policy/compiler.rs +++ b/src/policy/compiler.rs @@ -126,11 +126,7 @@ impl CompilationKey { /// Helper to create compilation key from components fn from_type(ty: Type, expensive_verify: bool, dissat_prob: Option) -> CompilationKey { - CompilationKey { - ty, - expensive_verify, - dissat_prob: dissat_prob.map(OrdF64), - } + CompilationKey { ty, expensive_verify, dissat_prob: dissat_prob.map(OrdF64) } } } @@ -151,19 +147,11 @@ struct CompilerExtData { impl Property for CompilerExtData { fn from_true() -> Self { - CompilerExtData { - branch_prob: None, - sat_cost: 0.0, - dissat_cost: None, - } + CompilerExtData { branch_prob: None, sat_cost: 0.0, dissat_cost: None } } fn from_false() -> Self { - CompilerExtData { - branch_prob: None, - sat_cost: f64::MAX, - dissat_cost: Some(0.0), - } + CompilerExtData { branch_prob: None, sat_cost: f64::MAX, dissat_cost: Some(0.0) } } fn from_pk_k() -> Self { @@ -210,19 +198,11 @@ impl Property for CompilerExtData { } fn from_hash() -> Self { - CompilerExtData { - branch_prob: None, - sat_cost: 33.0, - dissat_cost: Some(33.0), - } + CompilerExtData { branch_prob: None, sat_cost: 33.0, dissat_cost: Some(33.0) } } fn from_time(_t: u32) -> Self { - CompilerExtData { - branch_prob: None, - sat_cost: 0.0, - dissat_cost: None, - } + CompilerExtData { branch_prob: None, sat_cost: 0.0, dissat_cost: None } } fn cast_alt(self) -> Result { @@ -258,19 +238,11 @@ impl Property for CompilerExtData { } fn cast_verify(self) -> Result { - Ok(CompilerExtData { - branch_prob: None, - sat_cost: self.sat_cost, - dissat_cost: None, - }) + Ok(CompilerExtData { branch_prob: None, sat_cost: self.sat_cost, dissat_cost: None }) } fn cast_nonzero(self) -> Result { - Ok(CompilerExtData { - branch_prob: None, - sat_cost: self.sat_cost, - dissat_cost: Some(1.0), - }) + Ok(CompilerExtData { branch_prob: None, sat_cost: self.sat_cost, dissat_cost: Some(1.0) }) } fn cast_zeronotequal(self) -> Result { @@ -282,11 +254,7 @@ impl Property for CompilerExtData { } fn cast_true(self) -> Result { - Ok(CompilerExtData { - branch_prob: None, - sat_cost: self.sat_cost, - dissat_cost: None, - }) + Ok(CompilerExtData { branch_prob: None, sat_cost: self.sat_cost, dissat_cost: None }) } fn cast_or_i_false(self) -> Result { @@ -1346,10 +1314,8 @@ mod tests { assert_eq!(abs.n_keys(), 5); assert_eq!(abs.minimum_n_keys(), Some(3)); - let bitcoinsig = bitcoin::ecdsa::Signature { - sig, - hash_ty: bitcoin::sighash::EcdsaSighashType::All, - }; + let bitcoinsig = + bitcoin::ecdsa::Signature { sig, hash_ty: bitcoin::sighash::EcdsaSighashType::All }; let sigvec = bitcoinsig.to_vec(); let no_sat = HashMap::::new(); diff --git a/src/psbt/mod.rs b/src/psbt/mod.rs index 08ec8d3fd..a9eba63de 100644 --- a/src/psbt/mod.rs +++ b/src/psbt/mod.rs @@ -174,25 +174,18 @@ impl error::Error for InputError { impl fmt::Display for InputError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { - InputError::InvalidSignature { - ref pubkey, - ref sig, - } => write!(f, "PSBT: bad signature {} for key {:?}", pubkey, sig), + InputError::InvalidSignature { ref pubkey, ref sig } => { + write!(f, "PSBT: bad signature {} for key {:?}", pubkey, sig) + } InputError::KeyErr(ref e) => write!(f, "Key Err: {}", e), InputError::Interpreter(ref e) => write!(f, "Interpreter: {}", e), InputError::SecpErr(ref e) => write!(f, "Secp Err: {}", e), - InputError::InvalidRedeemScript { - ref redeem, - ref p2sh_expected, - } => write!( + InputError::InvalidRedeemScript { ref redeem, ref p2sh_expected } => write!( f, "Redeem script {} does not match the p2sh script {}", redeem, p2sh_expected ), - InputError::InvalidWitnessScript { - ref witness_script, - ref p2wsh_expected, - } => write!( + InputError::InvalidWitnessScript { ref witness_script, ref p2wsh_expected } => write!( f, "Witness script {} does not match the p2wsh script {}", witness_script, p2wsh_expected @@ -211,11 +204,7 @@ impl fmt::Display for InputError { InputError::NonEmptyWitnessScript => { write!(f, "PSBT has non-empty witness script at for legacy input") } - InputError::WrongSighashFlag { - required, - got, - pubkey, - } => write!( + InputError::WrongSighashFlag { required, got, pubkey } => write!( f, "PSBT: signature with key {:?} had \ sighashflag {:?} rather than required {:?}", @@ -668,10 +657,7 @@ impl PsbtExt for Psbt { index: usize, ) -> Result<(), Error> { if index >= self.inputs.len() { - return Err(Error::InputIdxOutofBounds { - psbt_inp: self.inputs.len(), - index, - }); + return Err(Error::InputIdxOutofBounds { psbt_inp: self.inputs.len(), index }); } finalizer::finalize_input(self, index, secp, /*allow_mall*/ false) } @@ -693,10 +679,7 @@ impl PsbtExt for Psbt { index: usize, ) -> Result<(), Error> { if index >= self.inputs.len() { - return Err(Error::InputIdxOutofBounds { - psbt_inp: self.inputs.len(), - index, - }); + return Err(Error::InputIdxOutofBounds { psbt_inp: self.inputs.len(), index }); } finalizer::finalize_input(self, index, secp, /*allow_mall*/ false) } @@ -1625,10 +1608,7 @@ mod tests { version: 1, lock_time: absolute::LockTime::ZERO, input: vec![TxIn { - previous_output: OutPoint { - txid: non_witness_utxo.txid(), - vout: 0, - }, + previous_output: OutPoint { txid: non_witness_utxo.txid(), vout: 0 }, ..Default::default() }], output: vec![],