@@ -31,7 +31,7 @@ use std::fmt;
3131use std:: str:: { self , FromStr } ;
3232
3333use expression;
34- use miniscript:: Miniscript ;
34+ use miniscript:: { Legacy , Miniscript , Segwitv0 } ;
3535use Error ;
3636use MiniscriptKey ;
3737use Satisfier ;
@@ -50,7 +50,7 @@ pub use self::satisfied_constraints::Stack;
5050#[ derive( Clone , PartialEq , Eq , PartialOrd , Ord ) ]
5151pub enum Descriptor < Pk : MiniscriptKey > {
5252 /// A raw scriptpubkey (including pay-to-pubkey)
53- Bare ( Miniscript < Pk > ) ,
53+ Bare ( Miniscript < Pk , Legacy > ) ,
5454 /// Pay-to-Pubkey
5555 Pk ( Pk ) ,
5656 /// Pay-to-PubKey-Hash
@@ -60,11 +60,11 @@ pub enum Descriptor<Pk: MiniscriptKey> {
6060 /// Pay-to-Witness-PubKey-Hash inside P2SH
6161 ShWpkh ( Pk ) ,
6262 /// Pay-to-ScriptHash
63- Sh ( Miniscript < Pk > ) ,
63+ Sh ( Miniscript < Pk , Legacy > ) ,
6464 /// Pay-to-Witness-ScriptHash
65- Wsh ( Miniscript < Pk > ) ,
65+ Wsh ( Miniscript < Pk , Segwitv0 > ) ,
6666 /// P2SH-P2WSH
67- ShWsh ( Miniscript < Pk > ) ,
67+ ShWsh ( Miniscript < Pk , Segwitv0 > ) ,
6868}
6969
7070impl < Pk : MiniscriptKey > Descriptor < Pk > {
@@ -200,7 +200,8 @@ impl<Pk: MiniscriptKey + ToPublicKey> Descriptor<Pk> {
200200 let addr = bitcoin:: Address :: p2wpkh ( & pk. to_public_key ( ) , bitcoin:: Network :: Bitcoin ) ;
201201 addr. script_pubkey ( )
202202 }
203- Descriptor :: Sh ( ref d) | Descriptor :: Wsh ( ref d) | Descriptor :: ShWsh ( ref d) => d. encode ( ) ,
203+ Descriptor :: Sh ( ref d) => d. encode ( ) ,
204+ Descriptor :: Wsh ( ref d) | Descriptor :: ShWsh ( ref d) => d. encode ( ) ,
204205 }
205206 }
206207
@@ -395,25 +396,29 @@ where
395396 expression:: terminal ( & top. args [ 0 ] , |pk| Pk :: from_str ( pk) . map ( Descriptor :: Pkh ) )
396397 }
397398 ( "wpkh" , 1 ) => {
398- expression:: terminal ( & top. args [ 0 ] , |pk| Pk :: from_str ( pk) . map ( Descriptor :: Wpkh ) )
399+ let wpkh = expression:: terminal ( & top. args [ 0 ] , |pk| Pk :: from_str ( pk) ) ?;
400+ if wpkh. is_uncompressed ( ) {
401+ Err ( Error :: BadDescriptor )
402+ } else {
403+ Ok ( Descriptor :: Wpkh ( wpkh) )
404+ }
399405 }
400406 ( "sh" , 1 ) => {
401407 let newtop = & top. args [ 0 ] ;
402408 match ( newtop. name , newtop. args . len ( ) ) {
403- ( "wsh" , 1 ) => {
404- let sub = Miniscript :: from_tree ( & newtop. args [ 0 ] ) ?;
405- Ok ( Descriptor :: ShWsh ( sub) )
406- }
407- ( "wpkh" , 1 ) => expression:: terminal ( & newtop. args [ 0 ] , |pk| {
408- Pk :: from_str ( pk) . map ( Descriptor :: ShWpkh )
409- } ) ,
410- _ => {
411- let sub = Miniscript :: from_tree ( & top. args [ 0 ] ) ?;
412- Ok ( Descriptor :: Sh ( sub) )
409+ ( "wsh" , 1 ) => Miniscript :: from_tree ( & newtop. args [ 0 ] ) . map ( Descriptor :: ShWsh ) ,
410+ ( "wpkh" , 1 ) => {
411+ let wpkh = expression:: terminal ( & newtop. args [ 0 ] , |pk| Pk :: from_str ( pk) ) ?;
412+ if wpkh. is_uncompressed ( ) {
413+ Err ( Error :: BadDescriptor )
414+ } else {
415+ Ok ( Descriptor :: ShWpkh ( wpkh) )
416+ }
413417 }
418+ _ => Miniscript :: from_tree ( & top. args [ 0 ] ) . map ( Descriptor :: Sh ) ,
414419 }
415420 }
416- ( "wsh" , 1 ) => expression :: unary ( top, Descriptor :: Wsh ) ,
421+ ( "wsh" , 1 ) => Miniscript :: from_tree ( & top. args [ 0 ] ) . map ( Descriptor :: Wsh ) ,
417422 _ => {
418423 let sub = expression:: FromTree :: from_tree ( & top) ?;
419424 Ok ( Descriptor :: Bare ( sub) )
@@ -841,6 +846,8 @@ mod tests {
841846 ) ;
842847 assert_eq ! ( sh. unsigned_script_sig( ) , bitcoin:: Script :: new( ) ) ;
843848
849+ let ms = ms_str ! ( "c:pk_k({})" , pk) ;
850+
844851 let wsh = Descriptor :: Wsh ( ms. clone ( ) ) ;
845852 wsh. satisfy ( & mut txin, & satisfier) . expect ( "satisfaction" ) ;
846853 assert_eq ! (
0 commit comments