Skip to content

Commit 1120081

Browse files
committed
chore(wallet): rm dup code
Methods `make_multi` and `make_multi_a` were essentially the same thing except for a different const generic param on `Threshold`. So we rm `make_multi_a` and put a const generic param on `make_multi`.
1 parent 2a45640 commit 1120081

File tree

1 file changed

+9
-62
lines changed

1 file changed

+9
-62
lines changed

crates/wallet/src/descriptor/policy.rs

+9-62
Original file line numberDiff line numberDiff line change
@@ -587,61 +587,8 @@ impl Policy {
587587
Ok(Some(policy))
588588
}
589589

590-
fn make_multi<Ctx: ScriptContext + 'static>(
591-
threshold: &Threshold<DescriptorPublicKey, MAX_PUBKEYS_PER_MULTISIG>,
592-
signers: &SignersContainer,
593-
build_sat: BuildSatisfaction,
594-
sorted: bool,
595-
secp: &SecpCtx,
596-
) -> Result<Option<Policy>, PolicyError> {
597-
let parsed_keys = threshold.iter().map(|k| PkOrF::from_key(k, secp)).collect();
598-
599-
let mut contribution = Satisfaction::Partial {
600-
n: threshold.n(),
601-
m: threshold.k(),
602-
items: vec![],
603-
conditions: Default::default(),
604-
sorted: Some(sorted),
605-
};
606-
let mut satisfaction = contribution.clone();
607-
608-
for (index, key) in threshold.iter().enumerate() {
609-
if signers.find(signer_id(key, secp)).is_some() {
610-
contribution.add(
611-
&Satisfaction::Complete {
612-
condition: Default::default(),
613-
},
614-
index,
615-
)?;
616-
}
617-
618-
if let Some(psbt) = build_sat.psbt() {
619-
if Ctx::find_signature(psbt, key, secp) {
620-
satisfaction.add(
621-
&Satisfaction::Complete {
622-
condition: Default::default(),
623-
},
624-
index,
625-
)?;
626-
}
627-
}
628-
}
629-
satisfaction.finalize();
630-
contribution.finalize();
631-
632-
let mut policy: Policy = SatisfiableItem::Multisig {
633-
keys: parsed_keys,
634-
threshold: threshold.k(),
635-
}
636-
.into();
637-
policy.contribution = contribution;
638-
policy.satisfaction = satisfaction;
639-
640-
Ok(Some(policy))
641-
}
642-
643-
fn make_multi_a<Ctx: ScriptContext + 'static>(
644-
threshold: &Threshold<DescriptorPublicKey, MAX_PUBKEYS_IN_CHECKSIGADD>,
590+
fn make_multi<Ctx: ScriptContext + 'static, const MAX: usize>(
591+
threshold: &Threshold<DescriptorPublicKey, MAX>,
645592
signers: &SignersContainer,
646593
build_sat: BuildSatisfaction,
647594
sorted: bool,
@@ -1038,12 +985,12 @@ impl<Ctx: ScriptContext + 'static> ExtractPolicy for Miniscript<DescriptorPublic
1038985
Terminal::Hash160(hash) => {
1039986
Some(SatisfiableItem::Hash160Preimage { hash: *hash }.into())
1040987
}
1041-
Terminal::Multi(threshold) => {
1042-
Policy::make_multi::<Ctx>(threshold, signers, build_sat, false, secp)?
1043-
}
1044-
Terminal::MultiA(threshold) => {
1045-
Policy::make_multi_a::<Ctx>(threshold, signers, build_sat, false, secp)?
1046-
}
988+
Terminal::Multi(threshold) => Policy::make_multi::<Ctx, MAX_PUBKEYS_PER_MULTISIG>(
989+
threshold, signers, build_sat, false, secp,
990+
)?,
991+
Terminal::MultiA(threshold) => Policy::make_multi::<Ctx, MAX_PUBKEYS_IN_CHECKSIGADD>(
992+
threshold, signers, build_sat, false, secp,
993+
)?,
1047994
// Identities
1048995
Terminal::Alt(inner)
1049996
| Terminal::Swap(inner)
@@ -1145,7 +1092,7 @@ impl ExtractPolicy for Descriptor<DescriptorPublicKey> {
11451092
) -> Result<Option<Policy>, Error> {
11461093
let threshold = Threshold::new(keys.k(), keys.pks().to_vec())
11471094
.expect("valid threshold and pks collection");
1148-
Ok(Policy::make_multi::<Ctx>(
1095+
Ok(Policy::make_multi::<Ctx, MAX_PUBKEYS_PER_MULTISIG>(
11491096
&threshold, signers, build_sat, true, secp,
11501097
)?)
11511098
}

0 commit comments

Comments
 (0)