@@ -529,8 +529,8 @@ impl<Ctx: ScriptContext> Miniscript<Ctx::Key, Ctx> {
529529 /// Some of the analysis guarantees of miniscript are lost when dealing with
530530 /// insane scripts. In general, in a multi-party setting users should only
531531 /// accept sane scripts.
532- pub fn parse_insane ( script : & script:: Script ) -> Result < Miniscript < Ctx :: Key , Ctx > , Error > {
533- Miniscript :: parse_with_ext ( script, & ExtParams :: insane ( ) )
532+ pub fn decode_insane ( script : & script:: Script ) -> Result < Miniscript < Ctx :: Key , Ctx > , Error > {
533+ Miniscript :: decode_with_ext ( script, & ExtParams :: insane ( ) )
534534 }
535535
536536 /// Attempt to parse an miniscript with extra features that not yet specified in the spec.
@@ -540,14 +540,14 @@ impl<Ctx: ScriptContext> Miniscript<Ctx::Key, Ctx> {
540540 /// - Parsing miniscripts with raw pubkey hashes
541541 ///
542542 /// Allowed extra features can be specified by the ext [`ExtParams`] argument.
543- pub fn parse_with_ext (
543+ pub fn decode_with_ext (
544544 script : & script:: Script ,
545545 ext : & ExtParams ,
546546 ) -> Result < Miniscript < Ctx :: Key , Ctx > , Error > {
547547 let tokens = lex ( script) ?;
548548 let mut iter = TokenIter :: new ( tokens) ;
549549
550- let top = decode:: parse ( & mut iter) ?;
550+ let top = decode:: decode ( & mut iter) ?;
551551 Ctx :: check_global_validity ( & top) ?;
552552 let type_check = types:: Type :: type_check ( & top. node ) ?;
553553 if type_check. corr . base != types:: Base :: B {
@@ -564,7 +564,7 @@ impl<Ctx: ScriptContext> Miniscript<Ctx::Key, Ctx> {
564564 /// Attempt to parse a Script into Miniscript representation.
565565 ///
566566 /// This function will fail parsing for scripts that do not clear the
567- /// [`Miniscript::sanity_check`] checks. Use [`Miniscript::parse_insane `] to
567+ /// [`Miniscript::sanity_check`] checks. Use [`Miniscript::decode_insane `] to
568568 /// parse such scripts.
569569 ///
570570 /// ## Decode/Parse a miniscript from script hex
@@ -578,24 +578,24 @@ impl<Ctx: ScriptContext> Miniscript<Ctx::Key, Ctx> {
578578 /// type TapScript = Miniscript<XOnlyPublicKey, Tap>;
579579 ///
580580 /// // parse x-only miniscript in Taproot context
581- /// let tapscript_ms = TapScript::parse (&bitcoin::ScriptBuf::from_hex(
581+ /// let tapscript_ms = TapScript::decode (&bitcoin::ScriptBuf::from_hex(
582582 /// "202788ee41e76f4f3af603da5bc8fa22997bc0344bb0f95666ba6aaff0242baa99ac",
583583 /// ).expect("Even length hex"))
584584 /// .expect("Xonly keys are valid only in taproot context");
585585 /// // tapscript fails decoding when we use them with compressed keys
586- /// let err = TapScript::parse (&bitcoin::ScriptBuf::from_hex(
586+ /// let err = TapScript::decode (&bitcoin::ScriptBuf::from_hex(
587587 /// "21022788ee41e76f4f3af603da5bc8fa22997bc0344bb0f95666ba6aaff0242baa99ac",
588588 /// ).expect("Even length hex"))
589589 /// .expect_err("Compressed keys cannot be used in Taproot context");
590590 /// // Segwitv0 succeeds decoding with full keys.
591- /// Segwitv0Script::parse (&bitcoin::ScriptBuf::from_hex(
591+ /// Segwitv0Script::decode (&bitcoin::ScriptBuf::from_hex(
592592 /// "21022788ee41e76f4f3af603da5bc8fa22997bc0344bb0f95666ba6aaff0242baa99ac",
593593 /// ).expect("Even length hex"))
594594 /// .expect("Compressed keys are allowed in Segwit context");
595595 ///
596596 /// ```
597- pub fn parse ( script : & script:: Script ) -> Result < Miniscript < Ctx :: Key , Ctx > , Error > {
598- let ms = Self :: parse_with_ext ( script, & ExtParams :: sane ( ) ) ?;
597+ pub fn decode ( script : & script:: Script ) -> Result < Miniscript < Ctx :: Key , Ctx > , Error > {
598+ let ms = Self :: decode_with_ext ( script, & ExtParams :: sane ( ) ) ?;
599599 Ok ( ms)
600600 }
601601}
@@ -1165,7 +1165,7 @@ mod tests {
11651165 assert_eq ! ( format!( "{:x}" , bitcoin_script) , expected) ;
11661166 }
11671167 // Parse scripts with all extensions
1168- let roundtrip = Segwitv0Script :: parse_with_ext ( & bitcoin_script, & ExtParams :: allow_all ( ) )
1168+ let roundtrip = Segwitv0Script :: decode_with_ext ( & bitcoin_script, & ExtParams :: allow_all ( ) )
11691169 . expect ( "parse string serialization" ) ;
11701170 assert_eq ! ( roundtrip, script) ;
11711171 }
@@ -1175,7 +1175,7 @@ mod tests {
11751175 let ser = tree. encode ( ) ;
11761176 assert_eq ! ( ser. len( ) , tree. script_size( ) ) ;
11771177 assert_eq ! ( ser. to_string( ) , s) ;
1178- let deser = Segwitv0Script :: parse_insane ( & ser) . expect ( "deserialize result of serialize" ) ;
1178+ let deser = Segwitv0Script :: decode_insane ( & ser) . expect ( "deserialize result of serialize" ) ;
11791179 assert_eq ! ( * tree, deser) ;
11801180 }
11811181
@@ -1316,19 +1316,19 @@ mod tests {
13161316 fn verify_parse ( ) {
13171317 let ms = "and_v(v:hash160(20195b5a3d650c17f0f29f91c33f8f6335193d07),or_d(sha256(96de8fc8c256fa1e1556d41af431cace7dca68707c78dd88c3acab8b17164c47),older(16)))" ;
13181318 let ms: Segwitv0Script = Miniscript :: from_str_insane ( ms) . unwrap ( ) ;
1319- assert_eq ! ( ms, Segwitv0Script :: parse_insane ( & ms. encode( ) ) . unwrap( ) ) ;
1319+ assert_eq ! ( ms, Segwitv0Script :: decode_insane ( & ms. encode( ) ) . unwrap( ) ) ;
13201320
13211321 let ms = "and_v(v:sha256(96de8fc8c256fa1e1556d41af431cace7dca68707c78dd88c3acab8b17164c47),or_d(sha256(96de8fc8c256fa1e1556d41af431cace7dca68707c78dd88c3acab8b17164c47),older(16)))" ;
13221322 let ms: Segwitv0Script = Miniscript :: from_str_insane ( ms) . unwrap ( ) ;
1323- assert_eq ! ( ms, Segwitv0Script :: parse_insane ( & ms. encode( ) ) . unwrap( ) ) ;
1323+ assert_eq ! ( ms, Segwitv0Script :: decode_insane ( & ms. encode( ) ) . unwrap( ) ) ;
13241324
13251325 let ms = "and_v(v:ripemd160(20195b5a3d650c17f0f29f91c33f8f6335193d07),or_d(sha256(96de8fc8c256fa1e1556d41af431cace7dca68707c78dd88c3acab8b17164c47),older(16)))" ;
13261326 let ms: Segwitv0Script = Miniscript :: from_str_insane ( ms) . unwrap ( ) ;
1327- assert_eq ! ( ms, Segwitv0Script :: parse_insane ( & ms. encode( ) ) . unwrap( ) ) ;
1327+ assert_eq ! ( ms, Segwitv0Script :: decode_insane ( & ms. encode( ) ) . unwrap( ) ) ;
13281328
13291329 let ms = "and_v(v:hash256(96de8fc8c256fa1e1556d41af431cace7dca68707c78dd88c3acab8b17164c47),or_d(sha256(96de8fc8c256fa1e1556d41af431cace7dca68707c78dd88c3acab8b17164c47),older(16)))" ;
13301330 let ms: Segwitv0Script = Miniscript :: from_str_insane ( ms) . unwrap ( ) ;
1331- assert_eq ! ( ms, Segwitv0Script :: parse_insane ( & ms. encode( ) ) . unwrap( ) ) ;
1331+ assert_eq ! ( ms, Segwitv0Script :: decode_insane ( & ms. encode( ) ) . unwrap( ) ) ;
13321332 }
13331333
13341334 #[ test]
@@ -1519,21 +1519,21 @@ mod tests {
15191519 #[ test]
15201520 fn deserialize ( ) {
15211521 // Most of these came from fuzzing, hence the increasing lengths
1522- assert ! ( Segwitv0Script :: parse_insane ( & hex_script( "" ) ) . is_err( ) ) ; // empty
1523- assert ! ( Segwitv0Script :: parse_insane ( & hex_script( "00" ) ) . is_ok( ) ) ; // FALSE
1524- assert ! ( Segwitv0Script :: parse_insane ( & hex_script( "51" ) ) . is_ok( ) ) ; // TRUE
1525- assert ! ( Segwitv0Script :: parse_insane ( & hex_script( "69" ) ) . is_err( ) ) ; // VERIFY
1526- assert ! ( Segwitv0Script :: parse_insane ( & hex_script( "0000" ) ) . is_err( ) ) ; //and_v(FALSE,FALSE)
1527- assert ! ( Segwitv0Script :: parse_insane ( & hex_script( "1001" ) ) . is_err( ) ) ; // incomplete push
1528- assert ! ( Segwitv0Script :: parse_insane ( & hex_script( "03990300b2" ) ) . is_err( ) ) ; // non-minimal #
1529- assert ! ( Segwitv0Script :: parse_insane ( & hex_script( "8559b2" ) ) . is_err( ) ) ; // leading bytes
1530- assert ! ( Segwitv0Script :: parse_insane ( & hex_script( "4c0169b2" ) ) . is_err( ) ) ; // non-minimal push
1531- assert ! ( Segwitv0Script :: parse_insane ( & hex_script( "0000af0000ae85" ) ) . is_err( ) ) ; // OR not BOOLOR
1522+ assert ! ( Segwitv0Script :: decode_insane ( & hex_script( "" ) ) . is_err( ) ) ; // empty
1523+ assert ! ( Segwitv0Script :: decode_insane ( & hex_script( "00" ) ) . is_ok( ) ) ; // FALSE
1524+ assert ! ( Segwitv0Script :: decode_insane ( & hex_script( "51" ) ) . is_ok( ) ) ; // TRUE
1525+ assert ! ( Segwitv0Script :: decode_insane ( & hex_script( "69" ) ) . is_err( ) ) ; // VERIFY
1526+ assert ! ( Segwitv0Script :: decode_insane ( & hex_script( "0000" ) ) . is_err( ) ) ; //and_v(FALSE,FALSE)
1527+ assert ! ( Segwitv0Script :: decode_insane ( & hex_script( "1001" ) ) . is_err( ) ) ; // incomplete push
1528+ assert ! ( Segwitv0Script :: decode_insane ( & hex_script( "03990300b2" ) ) . is_err( ) ) ; // non-minimal #
1529+ assert ! ( Segwitv0Script :: decode_insane ( & hex_script( "8559b2" ) ) . is_err( ) ) ; // leading bytes
1530+ assert ! ( Segwitv0Script :: decode_insane ( & hex_script( "4c0169b2" ) ) . is_err( ) ) ; // non-minimal push
1531+ assert ! ( Segwitv0Script :: decode_insane ( & hex_script( "0000af0000ae85" ) ) . is_err( ) ) ; // OR not BOOLOR
15321532
15331533 // misc fuzzer problems
1534- assert ! ( Segwitv0Script :: parse_insane ( & hex_script( "0000000000af" ) ) . is_err( ) ) ;
1535- assert ! ( Segwitv0Script :: parse_insane ( & hex_script( "04009a2970af00" ) ) . is_err( ) ) ; // giant CMS key num
1536- assert ! ( Segwitv0Script :: parse_insane ( & hex_script(
1534+ assert ! ( Segwitv0Script :: decode_insane ( & hex_script( "0000000000af" ) ) . is_err( ) ) ;
1535+ assert ! ( Segwitv0Script :: decode_insane ( & hex_script( "04009a2970af00" ) ) . is_err( ) ) ; // giant CMS key num
1536+ assert ! ( Segwitv0Script :: decode_insane ( & hex_script(
15371537 "2102ffffffffffffffefefefefefefefefefefef394c0fe5b711179e124008584753ac6900"
15381538 ) )
15391539 . is_err( ) ) ;
@@ -1573,22 +1573,22 @@ mod tests {
15731573
15741574 //---------------- test script <-> miniscript ---------------
15751575 // Test parsing from scripts: x-only fails decoding in segwitv0 ctx
1576- Segwitv0Script :: parse_insane ( & hex_script (
1576+ Segwitv0Script :: decode_insane ( & hex_script (
15771577 "202788ee41e76f4f3af603da5bc8fa22997bc0344bb0f95666ba6aaff0242baa99ac" ,
15781578 ) )
15791579 . unwrap_err ( ) ;
15801580 // x-only succeeds in tap ctx
1581- Tapscript :: parse_insane ( & hex_script (
1581+ Tapscript :: decode_insane ( & hex_script (
15821582 "202788ee41e76f4f3af603da5bc8fa22997bc0344bb0f95666ba6aaff0242baa99ac" ,
15831583 ) )
15841584 . unwrap ( ) ;
15851585 // tapscript fails decoding with compressed
1586- Tapscript :: parse_insane ( & hex_script (
1586+ Tapscript :: decode_insane ( & hex_script (
15871587 "21022788ee41e76f4f3af603da5bc8fa22997bc0344bb0f95666ba6aaff0242baa99ac" ,
15881588 ) )
15891589 . unwrap_err ( ) ;
15901590 // Segwitv0 succeeds decoding with tapscript.
1591- Segwitv0Script :: parse_insane ( & hex_script (
1591+ Segwitv0Script :: decode_insane ( & hex_script (
15921592 "21022788ee41e76f4f3af603da5bc8fa22997bc0344bb0f95666ba6aaff0242baa99ac" ,
15931593 ) )
15941594 . unwrap ( ) ;
@@ -1624,7 +1624,7 @@ mod tests {
16241624 . unwrap ( ) ;
16251625 // script rtt test
16261626 assert_eq ! (
1627- Miniscript :: <XOnlyPublicKey , Tap >:: parse_insane ( & tap_ms. encode( ) ) . unwrap( ) ,
1627+ Miniscript :: <XOnlyPublicKey , Tap >:: decode_insane ( & tap_ms. encode( ) ) . unwrap( ) ,
16281628 tap_ms
16291629 ) ;
16301630 assert_eq ! ( tap_ms. script_size( ) , 104 ) ;
@@ -1665,7 +1665,7 @@ mod tests {
16651665 . unwrap ( ) ;
16661666 let ms_trans = ms. translate_pk ( & mut StrKeyTranslator :: new ( ) ) . unwrap ( ) ;
16671667 let enc = ms_trans. encode ( ) ;
1668- let ms = Miniscript :: < bitcoin:: PublicKey , Segwitv0 > :: parse_insane ( & enc) . unwrap ( ) ;
1668+ let ms = Miniscript :: < bitcoin:: PublicKey , Segwitv0 > :: decode_insane ( & enc) . unwrap ( ) ;
16691669 assert_eq ! ( ms_trans. encode( ) , ms. encode( ) ) ;
16701670 }
16711671
@@ -1687,9 +1687,9 @@ mod tests {
16871687
16881688 let script = ms. encode ( ) ;
16891689 // The same test, but parsing from script
1690- SegwitMs :: parse ( & script) . unwrap_err ( ) ;
1691- SegwitMs :: parse_insane ( & script) . unwrap_err ( ) ;
1692- SegwitMs :: parse_with_ext ( & script, & ExtParams :: allow_all ( ) ) . unwrap ( ) ;
1690+ SegwitMs :: decode ( & script) . unwrap_err ( ) ;
1691+ SegwitMs :: decode_insane ( & script) . unwrap_err ( ) ;
1692+ SegwitMs :: decode_with_ext ( & script, & ExtParams :: allow_all ( ) ) . unwrap ( ) ;
16931693
16941694 // Try replacing the raw_pkh with a pkh
16951695 let mut map = BTreeMap :: new ( ) ;
@@ -1881,7 +1881,7 @@ mod tests {
18811881 for _ in 0 ..10000 {
18821882 script = script. push_opcode ( bitcoin:: opcodes:: all:: OP_0NOTEQUAL ) ;
18831883 }
1884- Tapscript :: parse_insane ( & script. into_script ( ) ) . unwrap_err ( ) ;
1884+ Tapscript :: decode_insane ( & script. into_script ( ) ) . unwrap_err ( ) ;
18851885 }
18861886
18871887 #[ test]
0 commit comments