Skip to content

Commit

Permalink
Rename thresh_m to multi
Browse files Browse the repository at this point in the history
  • Loading branch information
kiminuo committed Apr 7, 2020
1 parent aae84a4 commit 3dac01d
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 51 deletions.
2 changes: 1 addition & 1 deletion examples/sign_multisig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ fn main() {
);

let descriptor_str = format!(
"wsh(thresh_m(2,{},{},{}))",
"wsh(multi(2,{},{},{}))",
public_keys[0], public_keys[1], public_keys[2],
);

Expand Down
24 changes: 12 additions & 12 deletions src/descriptor/satisfied_constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ where
None => return Some(Err(Error::UnexpectedStackEnd)),
}
}
Terminal::ThreshM(ref k, ref subs) if node_state.n_evaluated == 0 => {
Terminal::Multi(ref k, ref subs) if node_state.n_evaluated == 0 => {
let len = self.stack.len();
if len < k + 1 {
return Some(Err(Error::InsufficientSignaturesMultiSig));
Expand All @@ -604,7 +604,7 @@ where
_ => {
match self
.stack
.evaluate_thresh_m(&mut self.verify_sig, &subs[subs.len() - 1])
.evaluate_multi(&mut self.verify_sig, &subs[subs.len() - 1])
{
Some(Ok(x)) => {
self.push_evaluation_state(
Expand All @@ -625,7 +625,7 @@ where
}
}
}
Terminal::ThreshM(k, ref subs) => {
Terminal::Multi(k, ref subs) => {
if node_state.n_satisfied == k {
//multi-sig bug: Pop extra 0
if let Some(StackElement::Dissatisfied) = self.stack.pop() {
Expand All @@ -636,7 +636,7 @@ where
} else if node_state.n_evaluated == subs.len() {
return Some(Err(Error::MultiSigEvaluationError));
} else {
match self.stack.evaluate_thresh_m(
match self.stack.evaluate_multi(
&mut self.verify_sig,
&subs[subs.len() - node_state.n_evaluated - 1],
) {
Expand Down Expand Up @@ -983,9 +983,9 @@ impl<'stack> Stack<'stack> {
/// stack as input signatures and validates it in order of pubkeys.
/// For example, if the first signature is satisfied by second public key,
/// other signatures are not checked against the first pubkey.
/// `thresh_m(2,pk1,pk2)` would be satisfied by `[0 sig2 sig1]` and Err on
/// `multi(2,pk1,pk2)` would be satisfied by `[0 sig2 sig1]` and Err on
/// `[0 sig2 sig1]`
fn evaluate_thresh_m<'desc, F>(
fn evaluate_multi<'desc, F>(
&mut self,
verify_sig: F,
pk: &'desc bitcoin::PublicKey,
Expand Down Expand Up @@ -1423,7 +1423,7 @@ mod tests {
StackElement::Push(&der_sigs[0]),
]);
let elem = ms_str!(
"thresh_m(3,{},{},{},{},{})",
"multi(3,{},{},{},{},{})",
pks[4],
pks[3],
pks[2],
Expand All @@ -1432,9 +1432,9 @@ mod tests {
);
let constraints = from_stack(&vfyfn, stack, &elem);

let thresh_m_satisfied: Result<Vec<SatisfiedConstraint>, Error> = constraints.collect();
let multi_satisfied: Result<Vec<SatisfiedConstraint>, Error> = constraints.collect();
assert_eq!(
thresh_m_satisfied.unwrap(),
multi_satisfied.unwrap(),
vec![
SatisfiedConstraint::PublicKey {
key: &pks[0],
Expand All @@ -1459,7 +1459,7 @@ mod tests {
StackElement::Push(&der_sigs[1]),
]);
let elem = ms_str!(
"thresh_m(3,{},{},{},{},{})",
"multi(3,{},{},{},{},{})",
pks[4],
pks[3],
pks[2],
Expand All @@ -1468,7 +1468,7 @@ mod tests {
);
let constraints = from_stack(&vfyfn, stack, &elem);

let thresh_m_error: Result<Vec<SatisfiedConstraint>, Error> = constraints.collect();
assert!(thresh_m_error.is_err());
let multi_error: Result<Vec<SatisfiedConstraint>, Error> = constraints.collect();
assert!(multi_error.is_err());
}
}
28 changes: 14 additions & 14 deletions src/miniscript/astelem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ impl<Pk: MiniscriptKey> Terminal<Pk> {
.collect();
Terminal::Thresh(k, subs?)
}
Terminal::ThreshM(k, ref keys) => {
Terminal::Multi(k, ref keys) => {
let keys: Result<Vec<Q>, _> = keys.iter().map(&mut *translatefpk).collect();
Terminal::ThreshM(k, keys?)
Terminal::Multi(k, keys?)
}
})
}
Expand Down Expand Up @@ -231,8 +231,8 @@ impl<Pk: MiniscriptKey> fmt::Debug for Terminal<Pk> {
}
f.write_str(")")
}
Terminal::ThreshM(k, ref keys) => {
write!(f, "thresh_m({}", k)?;
Terminal::Multi(k, ref keys) => {
write!(f, "multi({}", k)?;
for k in keys {
write!(f, ",{:?}", k)?;
}
Expand Down Expand Up @@ -287,8 +287,8 @@ impl<Pk: MiniscriptKey> fmt::Display for Terminal<Pk> {
}
f.write_str(")")
}
Terminal::ThreshM(k, ref keys) => {
write!(f, "thresh_m({}", k)?;
Terminal::Multi(k, ref keys) => {
write!(f, "multi({}", k)?;
for k in keys {
write!(f, ",{}", k)?;
}
Expand Down Expand Up @@ -430,7 +430,7 @@ where

Ok(Terminal::Thresh(k, subs?))
}
("thresh_m", n) => {
("multi", n) => {
let k = expression::terminal(&top.args[0], expression::parse_num)? as usize;
if n == 0 || k > n - 1 {
return Err(errstr("higher threshold than there were keys in multi"));
Expand All @@ -441,7 +441,7 @@ where
.map(|sub| expression::terminal(sub, Pk::from_str))
.collect();

pks.map(|pks| Terminal::ThreshM(k, pks))
pks.map(|pks| Terminal::Multi(k, pks))
}
_ => Err(Error::Unexpected(format!(
"{}({} args) while parsing Miniscript",
Expand Down Expand Up @@ -610,7 +610,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Terminal<Pk> {
.push_int(k as i64)
.push_opcode(opcodes::all::OP_EQUAL)
}
Terminal::ThreshM(k, ref keys) => {
Terminal::Multi(k, ref keys) => {
builder = builder.push_int(k as i64);
for pk in keys {
builder = builder.push_key(&pk.to_public_key());
Expand Down Expand Up @@ -667,7 +667,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Terminal<Pk> {
+ subs.len() // ADD
- 1 // no ADD on first element
}
Terminal::ThreshM(k, ref pks) => {
Terminal::Multi(k, ref pks) => {
script_num_size(k)
+ 1
+ script_num_size(pks.len())
Expand Down Expand Up @@ -721,7 +721,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Terminal<Pk> {
}
Some(sum)
}
Terminal::ThreshM(k, _) => Some(1 + k),
Terminal::Multi(k, _) => Some(1 + k),
_ => None,
}
}
Expand Down Expand Up @@ -771,7 +771,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Terminal<Pk> {
}
Some(sum)
}
Terminal::ThreshM(k, _) => Some(1 + k),
Terminal::Multi(k, _) => Some(1 + k),
_ => None,
}
}
Expand Down Expand Up @@ -845,7 +845,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Terminal<Pk> {
.map(|(n, &(x, y))| if n < k { x } else { y })
.sum::<usize>()
}
Terminal::ThreshM(k, _) => 1 + k,
Terminal::Multi(k, _) => 1 + k,
}
}

Expand Down Expand Up @@ -924,7 +924,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Terminal<Pk> {
.map(|(n, &(x, y))| if n < k { x } else { y })
.sum::<usize>()
}
Terminal::ThreshM(k, _) => 1 + 73 * k,
Terminal::Multi(k, _) => 1 + 73 * k,
}
}
}
4 changes: 2 additions & 2 deletions src/miniscript/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ pub enum Terminal<Pk: MiniscriptKey> {
/// [E] ([W] ADD)* k EQUAL
Thresh(usize, Vec<Arc<Miniscript<Pk>>>),
/// k (<key>)* n CHECKMULTISIG
ThreshM(usize, Vec<Pk>),
Multi(usize, Vec<Pk>),
}

macro_rules! match_token {
Expand Down Expand Up @@ -337,7 +337,7 @@ pub fn parse(tokens: &mut TokenIter) -> Result<Miniscript<bitcoin::PublicKey>, E
Tk::Num(k) => k,
);
keys.reverse();
term.reduce0(Terminal::ThreshM(k as usize, keys))?;
term.reduce0(Terminal::Multi(k as usize, keys))?;
},
);
}
Expand Down

0 comments on commit 3dac01d

Please sign in to comment.