Skip to content

Commit 99868ce

Browse files
committed
Sorted multi parse errors
Fixes #202
1 parent b09227d commit 99868ce

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/descriptor/mod.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ use bitcoin::secp256k1::{Secp256k1, Signing};
3838
use bitcoin::util::bip32;
3939
use bitcoin::{self, Script};
4040

41+
use errstr;
4142
use expression;
4243
use miniscript;
4344
use miniscript::context::{ScriptContext, ScriptContextError};
@@ -1445,7 +1446,15 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> SortedMultiVec<Pk, Ctx> {
14451446
where
14461447
<Pk as FromStr>::Err: ToString,
14471448
{
1449+
if tree.args.is_empty() {
1450+
return Err(errstr("no arguments given for sortedmulti"));
1451+
}
14481452
let k = expression::parse_num(tree.args[0].name)?;
1453+
if k > (tree.args.len() - 1) as u32 {
1454+
return Err(errstr(
1455+
"higher threshold than there were keys in sortedmulti",
1456+
));
1457+
}
14491458
let pks: Result<Vec<Pk>, _> = tree.args[1..]
14501459
.iter()
14511460
.map(|sub| expression::terminal(sub, Pk::from_str))
@@ -1685,6 +1694,19 @@ mod tests {
16851694
StdDescriptor::from_str("(\u{7f}()3").unwrap_err();
16861695
StdDescriptor::from_str("pk()").unwrap_err();
16871696
StdDescriptor::from_str("nl:0").unwrap_err(); //issue 63
1697+
let compressed_pk = DummyKey.to_string();
1698+
assert_eq!(
1699+
StdDescriptor::from_str("sh(sortedmulti)")
1700+
.unwrap_err()
1701+
.to_string(),
1702+
"unexpected «no arguments given for sortedmulti»"
1703+
); //issue 202
1704+
assert_eq!(
1705+
StdDescriptor::from_str(&format!("sh(sortedmulti(2,{}))", compressed_pk))
1706+
.unwrap_err()
1707+
.to_string(),
1708+
"unexpected «higher threshold than there were keys in sortedmulti»"
1709+
); //issue 202
16881710

16891711
StdDescriptor::from_str(TEST_PK).unwrap();
16901712

0 commit comments

Comments
 (0)