Skip to content

Commit 0b5e3f6

Browse files
committed
chore: apply rustfmt.toml
1 parent 8f06a44 commit 0b5e3f6

File tree

16 files changed

+208
-151
lines changed

16 files changed

+208
-151
lines changed

wallet/examples/compiler.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ use bdk_wallet::{KeychainKind, Wallet};
2525

2626
/// Miniscript policy is a high level abstraction of spending conditions. Defined in the
2727
/// rust-miniscript library here https://docs.rs/miniscript/7.0.0/miniscript/policy/index.html
28-
/// rust-miniscript provides a `compile()` function that can be used to compile any miniscript policy
29-
/// into a descriptor. This descriptor then in turn can be used in bdk a fully functioning wallet
30-
/// can be derived from the policy.
28+
/// rust-miniscript provides a `compile()` function that can be used to compile any miniscript
29+
/// policy into a descriptor. This descriptor then in turn can be used in bdk a fully functioning
30+
/// wallet can be derived from the policy.
3131
///
3232
/// This example demonstrates the interaction between a bdk wallet and miniscript policy.
3333
#[allow(clippy::print_stdout)]

wallet/examples/policy.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ use bdk_wallet::signer::SignersContainer;
2020
///
2121
/// Policy is higher abstraction representation of the wallet descriptor spending condition.
2222
/// This is useful to express complex miniscript spending conditions into more human readable form.
23-
/// The resulting `Policy` structure can be used to derive spending conditions the wallet is capable
24-
/// to spend from.
23+
/// The resulting `Policy` structure can be used to derive spending conditions the wallet is
24+
/// capable to spend from.
2525
///
26-
/// This example demos a Policy output for a 2of2 multisig between between 2 parties, where the wallet holds
27-
/// one of the Extend Private key.
26+
/// This example demos a Policy output for a 2of2 multisig between between 2 parties, where the
27+
/// wallet holds one of the Extend Private key.
2828
#[allow(clippy::print_stdout)]
2929
fn main() -> Result<(), Box<dyn Error>> {
3030
let secp = bitcoin::secp256k1::Secp256k1::new();

wallet/src/descriptor/checksum.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ use alloc::string::String;
1919

2020
use miniscript::descriptor::checksum::desc_checksum;
2121

22-
/// Compute the checksum of a descriptor, excludes any existing checksum in the descriptor string from the calculation
22+
/// Compute the checksum of a descriptor, excludes any existing checksum in the descriptor string
23+
/// from the calculation
2324
pub fn calc_checksum(desc: &str) -> Result<String, DescriptorError> {
2425
if let Some(split) = desc.split_once('#') {
2526
let og_checksum = split.1;

wallet/src/descriptor/dsl.rs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,8 @@ macro_rules! apply_modifier {
404404
/// Macro to write full descriptors with code
405405
///
406406
/// This macro expands to a `Result` of
407-
/// [`DescriptorTemplateOut`](super::template::DescriptorTemplateOut) and [`DescriptorError`](crate::descriptor::DescriptorError)
407+
/// [`DescriptorTemplateOut`](super::template::DescriptorTemplateOut) and
408+
/// [`DescriptorError`](crate::descriptor::DescriptorError)
408409
///
409410
/// The syntax is very similar to the normal descriptor syntax, with the exception that modifiers
410411
/// cannot be grouped together. For instance, a descriptor fragment like `sdv:older(144)` has to be
@@ -429,9 +430,10 @@ macro_rules! apply_modifier {
429430
///
430431
/// -------
431432
///
432-
/// 2-of-3 that becomes a 1-of-3 after a timelock has expired. Both `descriptor_a` and `descriptor_b` are equivalent: the first
433-
/// syntax is more suitable for a fixed number of items known at compile time, while the other accepts a
434-
/// [`Vec`] of items, which makes it more suitable for writing dynamic descriptors.
433+
/// 2-of-3 that becomes a 1-of-3 after a timelock has expired. Both `descriptor_a` and
434+
/// `descriptor_b` are equivalent: the first syntax is more suitable for a fixed number of items
435+
/// known at compile time, while the other accepts a [`Vec`] of items, which makes it more suitable
436+
/// for writing dynamic descriptors.
435437
///
436438
/// They both produce the descriptor: `wsh(thresh(2,pk(...),s:pk(...),sndv:older(...)))`
437439
///
@@ -672,8 +674,9 @@ macro_rules! fragment_internal {
672674

673675
/// Macro to write descriptor fragments with code
674676
///
675-
/// This macro will be expanded to an object of type `Result<(Miniscript<DescriptorPublicKey, _>, KeyMap, ValidNetworks), DescriptorError>`. It allows writing
676-
/// fragments of larger descriptors that can be pieced together using `fragment!(thresh_vec(m, ...))`.
677+
/// This macro will be expanded to an object of type `Result<(Miniscript<DescriptorPublicKey, _>,
678+
/// KeyMap, ValidNetworks), DescriptorError>`. It allows writing fragments of larger descriptors
679+
/// that can be pieced together using `fragment!(thresh_vec(m, ...))`.
677680
///
678681
/// The syntax to write macro fragment is the same as documented for the [`descriptor`] macro.
679682
#[macro_export]
@@ -846,11 +849,13 @@ mod test {
846849
}
847850
}
848851

849-
// - at least one of each "type" of operator; i.e. one modifier, one leaf_opcode, one leaf_opcode_value, etc.
852+
// - at least one of each "type" of operator; i.e. one modifier, one leaf_opcode, one
853+
// leaf_opcode_value, etc.
850854
// - mixing up key types that implement IntoDescriptorKey in multi() or thresh()
851855

852856
// expected script for pk and bare manually created
853-
// expected addresses created with `bitcoin-cli getdescriptorinfo` (for hash) and `bitcoin-cli deriveaddresses`
857+
// expected addresses created with `bitcoin-cli getdescriptorinfo` (for hash) and `bitcoin-cli
858+
// deriveaddresses`
854859

855860
#[test]
856861
fn test_fixed_legacy_descriptors() {
@@ -1105,7 +1110,8 @@ mod test {
11051110
);
11061111
}
11071112

1108-
// - verify the valid_networks returned is correctly computed based on the keys present in the descriptor
1113+
// - verify the valid_networks returned is correctly computed based on the keys present in the
1114+
// descriptor
11091115
#[test]
11101116
fn test_valid_networks() {
11111117
let xprv = bip32::Xpriv::from_str("tprv8ZgxMBicQKsPcx5nBGsR63Pe8KnRUqmbJNENAfGftF3yuXoMMoVJJcYeUw5eVkm9WBPjWYt6HMWYJNesB5HaNVBaFc1M6dRjWSYnmewUMYy").unwrap();
@@ -1162,7 +1168,8 @@ mod test {
11621168
assert_eq!(key_map.get(&key3).unwrap().to_string(), "tprv8ZgxMBicQKsPdZXrcHNLf5JAJWFAoJ2TrstMRdSKtEggz6PddbuSkvHKM9oKJyFgZV1B7rw8oChspxyYbtmEXYyg1AjfWbL3ho3XHDpHRZf/10/20/30/40/*");
11631169
}
11641170

1165-
// - verify the ScriptContext is correctly validated (i.e. passing a type that only impl IntoDescriptorKey<Segwitv0> to a pkh() descriptor should throw a compilation error
1171+
// - verify the ScriptContext is correctly validated (i.e. passing a type that only impl
1172+
// IntoDescriptorKey<Segwitv0> to a pkh() descriptor should throw a compilation error
11661173
#[test]
11671174
fn test_script_context_validation() {
11681175
// this compiles
@@ -1174,8 +1181,9 @@ mod test {
11741181
assert_eq!(desc.to_string(), "pkh(tpubD6NzVbkrYhZ4WR7a4vY1VT3khMJMeAxVsfq9TBJyJWrNk247zCJtV7AWf6UJP7rAVsn8NNKdJi3gFyKPTmWZS9iukb91xbn2HbFSMQm2igY/0/*)#yrnz9pp2");
11751182

11761183
// as expected this does not compile due to invalid context
1177-
//let desc_key:DescriptorKey<Segwitv0> = (xprv, path.clone()).into_descriptor_key().unwrap();
1178-
//let (desc, _key_map, _valid_networks) = descriptor!(pkh(desc_key)).unwrap();
1184+
//let desc_key:DescriptorKey<Segwitv0> = (xprv,
1185+
// path.clone()).into_descriptor_key().unwrap(); let (desc, _key_map,
1186+
// _valid_networks) = descriptor!(pkh(desc_key)).unwrap();
11791187
}
11801188

11811189
#[test]

wallet/src/descriptor/mod.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ pub type HdKeyPaths = BTreeMap<secp256k1::PublicKey, KeySource>;
6969
/// [`psbt::Output`]: bitcoin::psbt::Output
7070
pub type TapKeyOrigins = BTreeMap<XOnlyPublicKey, (Vec<taproot::TapLeafHash>, KeySource)>;
7171

72-
/// Trait for types which can be converted into an [`ExtendedDescriptor`] and a [`KeyMap`] usable by a wallet in a specific [`Network`]
72+
/// Trait for types which can be converted into an [`ExtendedDescriptor`] and a [`KeyMap`] usable by
73+
/// a wallet in a specific [`Network`]
7374
pub trait IntoWalletDescriptor {
7475
/// Convert to wallet descriptor
7576
fn into_wallet_descriptor(
@@ -460,10 +461,11 @@ impl DescriptorMeta for ExtendedDescriptor {
460461
// using `for_any_key` should make this stop as soon as we return `true`
461462
self.for_any_key(|key| {
462463
if let DescriptorPublicKey::XPub(xpub) = key {
463-
// Check if the key matches one entry in our `key_origins`. If it does, `matches()` will
464-
// return the "prefix" that matched, so we remove that prefix from the full path
465-
// found in `key_origins` and save it in `derive_path`. We expect this to be a derivation
466-
// path of length 1 if the key is `wildcard` and an empty path otherwise.
464+
// Check if the key matches one entry in our `key_origins`. If it does, `matches()`
465+
// will return the "prefix" that matched, so we remove that prefix
466+
// from the full path found in `key_origins` and save it in
467+
// `derive_path`. We expect this to be a derivation path of length 1
468+
// if the key is `wildcard` and an empty path otherwise.
467469
let root_fingerprint = xpub.root_fingerprint(secp);
468470
let derive_path = key_origins
469471
.get_key_value(&root_fingerprint)
@@ -478,10 +480,11 @@ impl DescriptorMeta for ExtendedDescriptor {
478480
.cloned()
479481
.collect::<DerivationPath>();
480482

481-
// `derive_path` only contains the replacement index for the wildcard, if present, or
482-
// an empty path for fixed descriptors. To verify the key we also need the normal steps
483-
// that come before the wildcard, so we take them directly from `xpub` and then append
484-
// the final index
483+
// `derive_path` only contains the replacement index for the wildcard, if
484+
// present, or an empty path for fixed descriptors.
485+
// To verify the key we also need the normal steps
486+
// that come before the wildcard, so we take them directly from `xpub` and
487+
// then append the final index
485488
if verify_key(
486489
xpub,
487490
&xpub.derivation_path.extend(derive_path.clone()),

wallet/src/descriptor/policy.rs

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,8 @@ fn mix<T: Clone>(vec: Vec<Vec<T>>) -> Vec<Vec<T>> {
237237

238238
/// Type for a map of sets of [`Condition`] items keyed by each set's index
239239
pub type ConditionMap = BTreeMap<usize, HashSet<Condition>>;
240-
/// Type for a map of folded sets of [`Condition`] items keyed by a vector of the combined set's indexes
240+
/// Type for a map of folded sets of [`Condition`] items keyed by a vector of the combined set's
241+
/// indexes
241242
pub type FoldedConditionMap = BTreeMap<Vec<usize>, HashSet<Condition>>;
242243

243244
fn serialize_folded_cond_map<S>(
@@ -363,14 +364,18 @@ impl Satisfaction {
363364
if items.len() >= *m {
364365
let mut map = BTreeMap::new();
365366
let indexes = combinations(items, *m);
366-
// `indexes` at this point is a Vec<Vec<usize>>, with the "n choose k" of items (m of n)
367+
// `indexes` at this point is a Vec<Vec<usize>>, with the "n choose k" of items (m
368+
// of n)
367369
indexes
368370
.into_iter()
369371
// .inspect(|x| println!("--- orig --- {:?}", x))
370-
// we map each of the combinations of elements into a tuple of ([chosen items], [conditions]). unfortunately, those items have potentially more than one
371-
// condition (think about ORs), so we also use `mix` to expand those, i.e. [[0], [1, 2]] becomes [[0, 1], [0, 2]]. This is necessary to make sure that we
372+
// we map each of the combinations of elements into a tuple of ([chosen items],
373+
// [conditions]). unfortunately, those items have potentially more than one
374+
// condition (think about ORs), so we also use `mix` to expand those, i.e. [[0],
375+
// [1, 2]] becomes [[0, 1], [0, 2]]. This is necessary to make sure that we
372376
// consider every possible options and check whether or not they are compatible.
373-
// since this step can turn one item of the iterator into multiple ones, we use `flat_map()` to expand them out
377+
// since this step can turn one item of the iterator into multiple ones, we use
378+
// `flat_map()` to expand them out
374379
.flat_map(|i_vec| {
375380
mix(i_vec
376381
.iter()
@@ -386,7 +391,8 @@ impl Satisfaction {
386391
.collect::<Vec<(Vec<usize>, Vec<Condition>)>>()
387392
})
388393
// .inspect(|x| println!("flat {:?}", x))
389-
// try to fold all the conditions for this specific combination of indexes/options. if they are not compatible, try_fold will be Err
394+
// try to fold all the conditions for this specific combination of
395+
// indexes/options. if they are not compatible, try_fold will be Err
390396
.map(|(key, val)| {
391397
(
392398
key,
@@ -503,15 +509,18 @@ impl Condition {
503509
/// Errors that can happen while extracting and manipulating policies
504510
#[derive(Debug, PartialEq, Eq)]
505511
pub enum PolicyError {
506-
/// Not enough items are selected to satisfy a [`SatisfiableItem::Thresh`] or a [`SatisfiableItem::Multisig`]
512+
/// Not enough items are selected to satisfy a [`SatisfiableItem::Thresh`] or a
513+
/// [`SatisfiableItem::Multisig`]
507514
NotEnoughItemsSelected(String),
508-
/// Index out of range for an item to satisfy a [`SatisfiableItem::Thresh`] or a [`SatisfiableItem::Multisig`]
515+
/// Index out of range for an item to satisfy a [`SatisfiableItem::Thresh`] or a
516+
/// [`SatisfiableItem::Multisig`]
509517
IndexOutOfRange(usize),
510518
/// Can not add to an item that is [`Satisfaction::None`] or [`Satisfaction::Complete`]
511519
AddOnLeaf,
512520
/// Can not add to an item that is [`Satisfaction::PartialComplete`]
513521
AddOnPartialComplete,
514-
/// Can not merge CSV or timelock values unless both are less than or both are equal or greater than 500_000_000
522+
/// Can not merge CSV or timelock values unless both are less than or both are equal or greater
523+
/// than 500_000_000
515524
MixedTimelockUnits,
516525
/// Incompatible conditions (not currently used)
517526
IncompatibleConditions,
@@ -642,8 +651,8 @@ impl Policy {
642651
/// create a transaction
643652
///
644653
/// What this means is that for some spending policies the user should select which paths in
645-
/// the tree it intends to satisfy while signing, because the transaction must be created differently based
646-
/// on that.
654+
/// the tree it intends to satisfy while signing, because the transaction must be created
655+
/// differently based on that.
647656
pub fn requires_path(&self) -> bool {
648657
self.get_condition(&BTreeMap::new()).is_err()
649658
}
@@ -1063,7 +1072,8 @@ pub enum BuildSatisfaction<'a> {
10631072
/// Current blockchain height
10641073
current_height: u32,
10651074
/// The highest confirmation height between the inputs
1066-
/// CSV should consider different inputs, but we consider the worst condition for the tx as whole
1075+
/// CSV should consider different inputs, but we consider the worst condition for the tx as
1076+
/// whole
10671077
input_max_height: u32,
10681078
},
10691079
}
@@ -1633,6 +1643,7 @@ mod test {
16331643
);
16341644
}
16351645

1646+
#[rustfmt::skip]
16361647
#[test]
16371648
fn test_extract_satisfaction_timelock() {
16381649
//const PSBT_POLICY_CONSIDER_TIMELOCK_NOT_EXPIRED: &str = "cHNidP8BAFMBAAAAAdld52uJFGT7Yde0YZdSVh2vL020Zm2exadH5R4GSNScAAAAAAD/////ATrcAAAAAAAAF6kUXv2Fn+YemPP4PUpNR1ZbU16/eRCHAAAAAAABASvI3AAAAAAAACIAILhzvvcBzw/Zfnc9ispRK0PCahxn1F6RHXTZAmw5tqNPAQVSdmNSsmlofCEDeAtjYQk/Vfu4db2+68hyMKjc38+kWl5sP5QH8L42Zsusk3whAvhhP8vi6bSPMZokerDnvffCBs8m6MdEH8+PgUJdZ5mIrJNShyIGAvhhP8vi6bSPMZokerDnvffCBs8m6MdEH8+PgUJdZ5mIDBwu7j4AAACAAAAAACIGA3gLY2EJP1X7uHW9vuvIcjCo3N/PpFpebD+UB/C+NmbLDMkRfC4AAACAAAAAAAAA";

0 commit comments

Comments
 (0)