@@ -28,6 +28,7 @@ use sync::Arc;
28
28
use crate :: miniscript:: context:: SigType ;
29
29
use crate :: miniscript:: types:: { self , Property } ;
30
30
use crate :: miniscript:: ScriptContext ;
31
+ use crate :: miniscript:: musig_key:: KeyExpr ;
31
32
use crate :: prelude:: * ;
32
33
use crate :: util:: MsKeyBuilder ;
33
34
use crate :: {
@@ -80,7 +81,7 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Terminal<Pk, Ctx> {
80
81
Pk :: RawPkHash : ' a ,
81
82
{
82
83
match * self {
83
- Terminal :: PkK ( ref p) => pred ( p ) ,
84
+ Terminal :: PkK ( ref p) => p . for_each_key ( pred ) ,
84
85
Terminal :: PkH ( ref p) => pred ( p) ,
85
86
Terminal :: RawPkH ( ..)
86
87
| Terminal :: After ( ..)
@@ -112,8 +113,9 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Terminal<Pk, Ctx> {
112
113
&& c. real_for_each_key ( pred)
113
114
}
114
115
Terminal :: Thresh ( _, ref subs) => subs. iter ( ) . all ( |sub| sub. real_for_each_key ( pred) ) ,
115
- Terminal :: Multi ( _, ref keys) | Terminal :: MultiA ( _, ref keys) => {
116
- keys. iter ( ) . all ( |key| pred ( key) )
116
+ Terminal :: Multi ( _, ref keys) => keys. iter ( ) . all ( |key| pred ( key) ) ,
117
+ Terminal :: MultiA ( _, ref keys) => {
118
+ keys. iter ( ) . all ( |key| key. for_each_key ( pred) )
117
119
}
118
120
}
119
121
}
@@ -125,7 +127,7 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Terminal<Pk, Ctx> {
125
127
T : Translator < Pk , Q , E > ,
126
128
{
127
129
let frag: Terminal < Q , CtxQ > = match * self {
128
- Terminal :: PkK ( ref p) => Terminal :: PkK ( t . pk ( p ) ?) ,
130
+ Terminal :: PkK ( ref p) => Terminal :: PkK ( p . translate_pk ( t ) ?) ,
129
131
Terminal :: PkH ( ref p) => Terminal :: PkH ( t. pk ( p) ?) ,
130
132
Terminal :: RawPkH ( ref p) => Terminal :: RawPkH ( t. pkh ( p) ?) ,
131
133
Terminal :: After ( n) => Terminal :: After ( n) ,
@@ -186,7 +188,7 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Terminal<Pk, Ctx> {
186
188
Terminal :: Multi ( k, keys?)
187
189
}
188
190
Terminal :: MultiA ( k, ref keys) => {
189
- let keys: Result < Vec < Q > , _ > = keys. iter ( ) . map ( |k| t . pk ( k ) ) . collect ( ) ;
191
+ let keys: Result < Vec < KeyExpr < Q > > , _ > = keys. iter ( ) . map ( |k| k . translate_pk ( t ) ) . collect ( ) ;
190
192
Terminal :: MultiA ( k, keys?)
191
193
}
192
194
} ;
@@ -455,7 +457,7 @@ impl_from_tree!(
455
457
}
456
458
let mut unwrapped = match ( frag_name, top. args. len( ) ) {
457
459
( "pk_k" , 1 ) => {
458
- expression:: terminal ( & top. args [ 0 ] , |x| Pk :: from_str ( x ) . map ( Terminal :: PkK ) )
460
+ expression:: unary ( top, Terminal :: PkK )
459
461
}
460
462
( "pk_h" , 1 ) => expression:: terminal( & top. args[ 0 ] , |x| Pk :: from_str( x) . map( Terminal :: PkH ) ) ,
461
463
( "after" , 1 ) => expression:: terminal( & top. args[ 0 ] , |x| {
@@ -522,15 +524,18 @@ impl_from_tree!(
522
524
return Err ( errstr( "higher threshold than there were keys in multi" ) ) ;
523
525
}
524
526
525
- let pks: Result <Vec <Pk >, _> = top. args[ 1 ..]
526
- . iter( )
527
- . map( |sub| expression:: terminal( sub, Pk :: from_str) )
528
- . collect( ) ;
529
-
530
527
if frag_name == "multi" {
528
+ let pks: Result <Vec <Pk >, _> = top. args[ 1 ..]
529
+ . iter( )
530
+ . map( |sub| expression:: terminal( sub, Pk :: from_str) )
531
+ . collect( ) ;
531
532
pks. map( |pks| Terminal :: Multi ( k, pks) )
532
533
} else {
533
534
// must be multi_a
535
+ let pks: Result <Vec <KeyExpr <Pk >>, _> = top. args[ 1 ..]
536
+ . iter( )
537
+ . map( |sub| expression:: terminal( sub, KeyExpr :: <Pk >:: from_str) )
538
+ . collect( ) ;
534
539
pks. map( |pks| Terminal :: MultiA ( k, pks) )
535
540
}
536
541
}
@@ -734,7 +739,7 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Terminal<Pk, Ctx> {
734
739
builder = builder. push_ms_key :: < _ , Ctx > ( & keys[ 0 ] ) ;
735
740
builder = builder. push_opcode ( opcodes:: all:: OP_CHECKSIG ) ;
736
741
for pk in keys. iter ( ) . skip ( 1 ) {
737
- builder = builder. push_ms_key :: < _ , Ctx > ( pk) ;
742
+ builder = builder. push_ms_key :: < _ , Ctx > ( & pk) ;
738
743
builder = builder. push_opcode ( opcodes:: all:: OP_CHECKSIGADD ) ;
739
744
}
740
745
builder
@@ -793,7 +798,7 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Terminal<Pk, Ctx> {
793
798
script_num_size ( k)
794
799
+ 1
795
800
+ script_num_size ( pks. len ( ) )
796
- + pks. iter ( ) . map ( |pk| Ctx :: pk_len ( pk ) ) . sum :: < usize > ( )
801
+ + pks. iter ( ) . map ( |pk| Ctx :: pk_len ( & KeyExpr :: SingleKey ( * pk ) ) ) . sum :: < usize > ( )
797
802
}
798
803
Terminal :: MultiA ( k, ref pks) => {
799
804
script_num_size ( k)
0 commit comments