@@ -32,15 +32,21 @@ pub struct SortedMultiVec<Pk: MiniscriptKey, Ctx: ScriptContext> {
32
32
}
33
33
34
34
impl < Pk : MiniscriptKey , Ctx : ScriptContext > SortedMultiVec < Pk , Ctx > {
35
- fn constructor_check ( & self ) -> Result < ( ) , Error > {
35
+ fn constructor_check ( mut self ) -> Result < Self , Error > {
36
36
// Check the limits before creating a new SortedMultiVec
37
37
// For example, under p2sh context the scriptlen can only be
38
38
// upto 520 bytes.
39
- let term: Terminal < Pk , Ctx > = Terminal :: Multi ( self . inner . clone ( ) ) ;
39
+ let term: Terminal < Pk , Ctx > = Terminal :: Multi ( self . inner ) ;
40
40
let ms = Miniscript :: from_ast ( term) ?;
41
41
// This would check all the consensus rules for p2sh/p2wsh and
42
42
// even tapscript in future
43
- Ctx :: check_local_validity ( & ms) . map_err ( From :: from)
43
+ Ctx :: check_local_validity ( & ms) ?;
44
+ if let Terminal :: Multi ( inner) = ms. node {
45
+ self . inner = inner;
46
+ Ok ( self )
47
+ } else {
48
+ unreachable ! ( )
49
+ }
44
50
}
45
51
46
52
/// Create a new instance of `SortedMultiVec` given a list of keys and the threshold
@@ -49,8 +55,7 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> SortedMultiVec<Pk, Ctx> {
49
55
pub fn new ( k : usize , pks : Vec < Pk > ) -> Result < Self , Error > {
50
56
let ret =
51
57
Self { inner : Threshold :: new ( k, pks) . map_err ( Error :: Threshold ) ?, phantom : PhantomData } ;
52
- ret. constructor_check ( ) ?;
53
- Ok ( ret)
58
+ ret. constructor_check ( )
54
59
}
55
60
56
61
/// Parse an expression tree into a SortedMultiVec
@@ -66,8 +71,7 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> SortedMultiVec<Pk, Ctx> {
66
71
. translate_by_index ( |i| expression:: terminal ( & tree. args [ i + 1 ] , Pk :: from_str) ) ?,
67
72
phantom : PhantomData ,
68
73
} ;
69
- ret. constructor_check ( ) ?;
70
- Ok ( ret)
74
+ ret. constructor_check ( )
71
75
}
72
76
73
77
/// This will panic if fpk returns an uncompressed key when
@@ -85,8 +89,7 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> SortedMultiVec<Pk, Ctx> {
85
89
inner : self . inner . translate_ref ( |pk| t. pk ( pk) ) ?,
86
90
phantom : PhantomData ,
87
91
} ;
88
- ret. constructor_check ( ) . map_err ( TranslateErr :: OuterError ) ?;
89
- Ok ( ret)
92
+ ret. constructor_check ( ) . map_err ( TranslateErr :: OuterError )
90
93
}
91
94
92
95
/// The threshold value for the multisig.
0 commit comments