@@ -45,6 +45,7 @@ use crate::expression::{FromTree, TreeIterItem};
4545use crate :: miniscript:: decode:: Terminal ;
4646use crate :: {
4747 expression, plan, Error , ForEachKey , FromStrKey , MiniscriptKey , ToPublicKey , Translator ,
48+ ValidationParams ,
4849} ;
4950#[ cfg( test) ]
5051mod ms_tests;
@@ -732,27 +733,24 @@ impl<Ctx: ScriptContext> Miniscript<Ctx::Key, Ctx> {
732733 /// embedded in the chain. While it is inadvisable to use insane Miniscripts,
733734 /// once it's on the chain you don't have much choice anymore.
734735 pub fn decode_consensus ( script : & script:: Script ) -> Result < Miniscript < Ctx :: Key , Ctx > , Error > {
735- Miniscript :: decode_with_ext ( script, & ExtParams :: allow_all ( ) )
736+ Miniscript :: decode_with_validation_params ( script, & Ctx :: CONSENSUS )
736737 }
737738
738739 /// Attempt to decode a Miniscript from Script, specifying which validation parameters to apply.
739- pub fn decode_with_ext (
740+ pub fn decode_with_validation_params (
740741 script : & script:: Script ,
741- ext : & ExtParams ,
742+ params : & ValidationParams ,
742743 ) -> Result < Miniscript < Ctx :: Key , Ctx > , Error > {
743744 let tokens = lex ( script) ?;
744745 let mut iter = TokenIter :: new ( tokens) ;
745746
746747 let top = decode:: decode ( & mut iter) ?;
747748 Ctx :: check_global_validity ( & top) ?;
748- let type_check = types:: Type :: type_check ( & top. node ) ?;
749- if type_check. corr . base != types:: Base :: B {
750- return Err ( Error :: NonTopLevel ( format ! ( "{:?}" , top) ) ) ;
751- } ;
749+ types:: Type :: type_check ( & top. node ) ?;
752750 if let Some ( leading) = iter. next ( ) {
753751 Err ( Error :: Trailing ( leading. to_string ( ) ) )
754752 } else {
755- top. ext_check ( ext ) ?;
753+ top. validate ( params ) . map_err ( Error :: Validation ) ?;
756754 Ok ( top)
757755 }
758756 }
@@ -790,7 +788,7 @@ impl<Ctx: ScriptContext> Miniscript<Ctx::Key, Ctx> {
790788 ///
791789 /// ```
792790 pub fn decode ( script : & script:: Script ) -> Result < Miniscript < Ctx :: Key , Ctx > , Error > {
793- let ms = Self :: decode_with_ext ( script, & ExtParams :: sane ( ) ) ?;
791+ let ms = Self :: decode_with_validation_params ( script, & Ctx :: SANE ) ?;
794792 Ok ( ms)
795793 }
796794}
@@ -1917,9 +1915,10 @@ mod tests {
19171915 let ms = SegwitMs :: from_str_ext ( ms_str, & ExtParams :: allow_all ( ) ) . unwrap ( ) ;
19181916
19191917 let script = ms. encode ( ) ;
1920- // The same test, but parsing from script
1918+ // The same test, but parsing from script. Notice that unlike the previous "insane"
1919+ // extparams, the Ctx::CONSENSUS constant allows raw pubkeyhashes.
19211920 SegwitMs :: decode ( & script) . unwrap_err ( ) ;
1922- SegwitMs :: decode_with_ext ( & script, & ExtParams :: insane ( ) ) . unwrap_err ( ) ;
1921+ SegwitMs :: decode_with_validation_params ( & script, & Segwitv0 :: CONSENSUS ) . unwrap ( ) ;
19231922 SegwitMs :: decode_consensus ( & script) . unwrap ( ) ;
19241923
19251924 // Try replacing the raw_pkh with a pkh
0 commit comments