Skip to content

Commit be8af0f

Browse files
committed
miniscript: add infallible multi() and multi_a() constructors
These can't be constfs but they're still useful.
1 parent 8e79274 commit be8af0f

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/miniscript/mod.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ mod ms_tests;
5252
mod private {
5353
use core::marker::PhantomData;
5454

55-
use super::types::{ExtData, Type};
55+
use super::limits::{MAX_PUBKEYS_IN_CHECKSIGADD, MAX_PUBKEYS_PER_MULTISIG};
56+
use super::types::{self, ExtData, Type};
5657
use crate::iter::TreeLike as _;
5758
pub use crate::miniscript::context::ScriptContext;
58-
use crate::miniscript::types;
5959
use crate::prelude::sync::Arc;
6060
use crate::{AbsLockTime, Error, MiniscriptKey, RelLockTime, Terminal, MAX_RECURSION_DEPTH};
6161

@@ -270,6 +270,28 @@ mod private {
270270
}
271271
}
272272

273+
// non-const because Thresh::n is not becasue Vec::len is not (needs Rust 1.87)
274+
/// The `multi` combinator.
275+
pub fn multi(thresh: crate::Threshold<Pk, MAX_PUBKEYS_PER_MULTISIG>) -> Self {
276+
Self {
277+
ty: types::Type::multi(),
278+
ext: types::extra_props::ExtData::multi(thresh.k(), thresh.n()),
279+
node: Terminal::Multi(thresh),
280+
phantom: PhantomData,
281+
}
282+
}
283+
284+
// non-const because Thresh::n is not becasue Vec::len is not
285+
/// The `multi` combinator.
286+
pub fn multi_a(thresh: crate::Threshold<Pk, MAX_PUBKEYS_IN_CHECKSIGADD>) -> Self {
287+
Self {
288+
ty: types::Type::multi_a(),
289+
ext: types::extra_props::ExtData::multi_a(thresh.k(), thresh.n()),
290+
node: Terminal::MultiA(thresh),
291+
phantom: PhantomData,
292+
}
293+
}
294+
273295
/// Add type information(Type and Extdata) to Miniscript based on
274296
/// `AstElem` fragment. Dependent on display and clone because of Error
275297
/// Display code of type_check.

0 commit comments

Comments
 (0)