@@ -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
@@ -577,24 +577,24 @@ impl<Ctx: ScriptContext> Miniscript<Ctx::Key, Ctx> {
577577 /// type TapScript = Miniscript<XOnlyPublicKey, Tap>;
578578 ///
579579 /// // parse x-only miniscript in Taproot context
580- /// let tapscript_ms = TapScript::parse (&bitcoin::ScriptBuf::from_hex(
580+ /// let tapscript_ms = TapScript::decode (&bitcoin::ScriptBuf::from_hex(
581581 /// "202788ee41e76f4f3af603da5bc8fa22997bc0344bb0f95666ba6aaff0242baa99ac",
582582 /// ).expect("Even length hex"))
583583 /// .expect("Xonly keys are valid only in taproot context");
584584 /// // tapscript fails decoding when we use them with compressed keys
585- /// let err = TapScript::parse (&bitcoin::ScriptBuf::from_hex(
585+ /// let err = TapScript::decode (&bitcoin::ScriptBuf::from_hex(
586586 /// "21022788ee41e76f4f3af603da5bc8fa22997bc0344bb0f95666ba6aaff0242baa99ac",
587587 /// ).expect("Even length hex"))
588588 /// .expect_err("Compressed keys cannot be used in Taproot context");
589589 /// // Segwitv0 succeeds decoding with full keys.
590- /// Segwitv0Script::parse (&bitcoin::ScriptBuf::from_hex(
590+ /// Segwitv0Script::decode (&bitcoin::ScriptBuf::from_hex(
591591 /// "21022788ee41e76f4f3af603da5bc8fa22997bc0344bb0f95666ba6aaff0242baa99ac",
592592 /// ).expect("Even length hex"))
593593 /// .expect("Compressed keys are allowed in Segwit context");
594594 ///
595595 /// ```
596- pub fn parse ( script : & script:: Script ) -> Result < Miniscript < Ctx :: Key , Ctx > , Error > {
597- let ms = Self :: parse_with_ext ( script, & ExtParams :: sane ( ) ) ?;
596+ pub fn decode ( script : & script:: Script ) -> Result < Miniscript < Ctx :: Key , Ctx > , Error > {
597+ let ms = Self :: decode_with_ext ( script, & ExtParams :: sane ( ) ) ?;
598598 Ok ( ms)
599599 }
600600}
@@ -1164,7 +1164,7 @@ mod tests {
11641164 assert_eq ! ( format!( "{:x}" , bitcoin_script) , expected) ;
11651165 }
11661166 // Parse scripts with all extensions
1167- let roundtrip = Segwitv0Script :: parse_with_ext ( & bitcoin_script, & ExtParams :: allow_all ( ) )
1167+ let roundtrip = Segwitv0Script :: decode_with_ext ( & bitcoin_script, & ExtParams :: allow_all ( ) )
11681168 . expect ( "parse string serialization" ) ;
11691169 assert_eq ! ( roundtrip, script) ;
11701170 }
@@ -1174,7 +1174,7 @@ mod tests {
11741174 let ser = tree. encode ( ) ;
11751175 assert_eq ! ( ser. len( ) , tree. script_size( ) ) ;
11761176 assert_eq ! ( ser. to_string( ) , s) ;
1177- let deser = Segwitv0Script :: parse_insane ( & ser) . expect ( "deserialize result of serialize" ) ;
1177+ let deser = Segwitv0Script :: decode_insane ( & ser) . expect ( "deserialize result of serialize" ) ;
11781178 assert_eq ! ( * tree, deser) ;
11791179 }
11801180
@@ -1315,19 +1315,19 @@ mod tests {
13151315 fn verify_parse ( ) {
13161316 let ms = "and_v(v:hash160(20195b5a3d650c17f0f29f91c33f8f6335193d07),or_d(sha256(96de8fc8c256fa1e1556d41af431cace7dca68707c78dd88c3acab8b17164c47),older(16)))" ;
13171317 let ms: Segwitv0Script = Miniscript :: from_str_insane ( ms) . unwrap ( ) ;
1318- assert_eq ! ( ms, Segwitv0Script :: parse_insane ( & ms. encode( ) ) . unwrap( ) ) ;
1318+ assert_eq ! ( ms, Segwitv0Script :: decode_insane ( & ms. encode( ) ) . unwrap( ) ) ;
13191319
13201320 let ms = "and_v(v:sha256(96de8fc8c256fa1e1556d41af431cace7dca68707c78dd88c3acab8b17164c47),or_d(sha256(96de8fc8c256fa1e1556d41af431cace7dca68707c78dd88c3acab8b17164c47),older(16)))" ;
13211321 let ms: Segwitv0Script = Miniscript :: from_str_insane ( ms) . unwrap ( ) ;
1322- assert_eq ! ( ms, Segwitv0Script :: parse_insane ( & ms. encode( ) ) . unwrap( ) ) ;
1322+ assert_eq ! ( ms, Segwitv0Script :: decode_insane ( & ms. encode( ) ) . unwrap( ) ) ;
13231323
13241324 let ms = "and_v(v:ripemd160(20195b5a3d650c17f0f29f91c33f8f6335193d07),or_d(sha256(96de8fc8c256fa1e1556d41af431cace7dca68707c78dd88c3acab8b17164c47),older(16)))" ;
13251325 let ms: Segwitv0Script = Miniscript :: from_str_insane ( ms) . unwrap ( ) ;
1326- assert_eq ! ( ms, Segwitv0Script :: parse_insane ( & ms. encode( ) ) . unwrap( ) ) ;
1326+ assert_eq ! ( ms, Segwitv0Script :: decode_insane ( & ms. encode( ) ) . unwrap( ) ) ;
13271327
13281328 let ms = "and_v(v:hash256(96de8fc8c256fa1e1556d41af431cace7dca68707c78dd88c3acab8b17164c47),or_d(sha256(96de8fc8c256fa1e1556d41af431cace7dca68707c78dd88c3acab8b17164c47),older(16)))" ;
13291329 let ms: Segwitv0Script = Miniscript :: from_str_insane ( ms) . unwrap ( ) ;
1330- assert_eq ! ( ms, Segwitv0Script :: parse_insane ( & ms. encode( ) ) . unwrap( ) ) ;
1330+ assert_eq ! ( ms, Segwitv0Script :: decode_insane ( & ms. encode( ) ) . unwrap( ) ) ;
13311331 }
13321332
13331333 #[ test]
@@ -1518,21 +1518,21 @@ mod tests {
15181518 #[ test]
15191519 fn deserialize ( ) {
15201520 // Most of these came from fuzzing, hence the increasing lengths
1521- assert ! ( Segwitv0Script :: parse_insane ( & hex_script( "" ) ) . is_err( ) ) ; // empty
1522- assert ! ( Segwitv0Script :: parse_insane ( & hex_script( "00" ) ) . is_ok( ) ) ; // FALSE
1523- assert ! ( Segwitv0Script :: parse_insane ( & hex_script( "51" ) ) . is_ok( ) ) ; // TRUE
1524- assert ! ( Segwitv0Script :: parse_insane ( & hex_script( "69" ) ) . is_err( ) ) ; // VERIFY
1525- assert ! ( Segwitv0Script :: parse_insane ( & hex_script( "0000" ) ) . is_err( ) ) ; //and_v(FALSE,FALSE)
1526- assert ! ( Segwitv0Script :: parse_insane ( & hex_script( "1001" ) ) . is_err( ) ) ; // incomplete push
1527- assert ! ( Segwitv0Script :: parse_insane ( & hex_script( "03990300b2" ) ) . is_err( ) ) ; // non-minimal #
1528- assert ! ( Segwitv0Script :: parse_insane ( & hex_script( "8559b2" ) ) . is_err( ) ) ; // leading bytes
1529- assert ! ( Segwitv0Script :: parse_insane ( & hex_script( "4c0169b2" ) ) . is_err( ) ) ; // non-minimal push
1530- assert ! ( Segwitv0Script :: parse_insane ( & hex_script( "0000af0000ae85" ) ) . is_err( ) ) ; // OR not BOOLOR
1521+ assert ! ( Segwitv0Script :: decode_insane ( & hex_script( "" ) ) . is_err( ) ) ; // empty
1522+ assert ! ( Segwitv0Script :: decode_insane ( & hex_script( "00" ) ) . is_ok( ) ) ; // FALSE
1523+ assert ! ( Segwitv0Script :: decode_insane ( & hex_script( "51" ) ) . is_ok( ) ) ; // TRUE
1524+ assert ! ( Segwitv0Script :: decode_insane ( & hex_script( "69" ) ) . is_err( ) ) ; // VERIFY
1525+ assert ! ( Segwitv0Script :: decode_insane ( & hex_script( "0000" ) ) . is_err( ) ) ; //and_v(FALSE,FALSE)
1526+ assert ! ( Segwitv0Script :: decode_insane ( & hex_script( "1001" ) ) . is_err( ) ) ; // incomplete push
1527+ assert ! ( Segwitv0Script :: decode_insane ( & hex_script( "03990300b2" ) ) . is_err( ) ) ; // non-minimal #
1528+ assert ! ( Segwitv0Script :: decode_insane ( & hex_script( "8559b2" ) ) . is_err( ) ) ; // leading bytes
1529+ assert ! ( Segwitv0Script :: decode_insane ( & hex_script( "4c0169b2" ) ) . is_err( ) ) ; // non-minimal push
1530+ assert ! ( Segwitv0Script :: decode_insane ( & hex_script( "0000af0000ae85" ) ) . is_err( ) ) ; // OR not BOOLOR
15311531
15321532 // misc fuzzer problems
1533- assert ! ( Segwitv0Script :: parse_insane ( & hex_script( "0000000000af" ) ) . is_err( ) ) ;
1534- assert ! ( Segwitv0Script :: parse_insane ( & hex_script( "04009a2970af00" ) ) . is_err( ) ) ; // giant CMS key num
1535- assert ! ( Segwitv0Script :: parse_insane ( & hex_script(
1533+ assert ! ( Segwitv0Script :: decode_insane ( & hex_script( "0000000000af" ) ) . is_err( ) ) ;
1534+ assert ! ( Segwitv0Script :: decode_insane ( & hex_script( "04009a2970af00" ) ) . is_err( ) ) ; // giant CMS key num
1535+ assert ! ( Segwitv0Script :: decode_insane ( & hex_script(
15361536 "2102ffffffffffffffefefefefefefefefefefef394c0fe5b711179e124008584753ac6900"
15371537 ) )
15381538 . is_err( ) ) ;
@@ -1572,22 +1572,22 @@ mod tests {
15721572
15731573 //---------------- test script <-> miniscript ---------------
15741574 // Test parsing from scripts: x-only fails decoding in segwitv0 ctx
1575- Segwitv0Script :: parse_insane ( & hex_script (
1575+ Segwitv0Script :: decode_insane ( & hex_script (
15761576 "202788ee41e76f4f3af603da5bc8fa22997bc0344bb0f95666ba6aaff0242baa99ac" ,
15771577 ) )
15781578 . unwrap_err ( ) ;
15791579 // x-only succeeds in tap ctx
1580- Tapscript :: parse_insane ( & hex_script (
1580+ Tapscript :: decode_insane ( & hex_script (
15811581 "202788ee41e76f4f3af603da5bc8fa22997bc0344bb0f95666ba6aaff0242baa99ac" ,
15821582 ) )
15831583 . unwrap ( ) ;
15841584 // tapscript fails decoding with compressed
1585- Tapscript :: parse_insane ( & hex_script (
1585+ Tapscript :: decode_insane ( & hex_script (
15861586 "21022788ee41e76f4f3af603da5bc8fa22997bc0344bb0f95666ba6aaff0242baa99ac" ,
15871587 ) )
15881588 . unwrap_err ( ) ;
15891589 // Segwitv0 succeeds decoding with tapscript.
1590- Segwitv0Script :: parse_insane ( & hex_script (
1590+ Segwitv0Script :: decode_insane ( & hex_script (
15911591 "21022788ee41e76f4f3af603da5bc8fa22997bc0344bb0f95666ba6aaff0242baa99ac" ,
15921592 ) )
15931593 . unwrap ( ) ;
@@ -1623,7 +1623,7 @@ mod tests {
16231623 . unwrap ( ) ;
16241624 // script rtt test
16251625 assert_eq ! (
1626- Miniscript :: <XOnlyPublicKey , Tap >:: parse_insane ( & tap_ms. encode( ) ) . unwrap( ) ,
1626+ Miniscript :: <XOnlyPublicKey , Tap >:: decode_insane ( & tap_ms. encode( ) ) . unwrap( ) ,
16271627 tap_ms
16281628 ) ;
16291629 assert_eq ! ( tap_ms. script_size( ) , 104 ) ;
@@ -1664,7 +1664,7 @@ mod tests {
16641664 . unwrap ( ) ;
16651665 let ms_trans = ms. translate_pk ( & mut StrKeyTranslator :: new ( ) ) . unwrap ( ) ;
16661666 let enc = ms_trans. encode ( ) ;
1667- let ms = Miniscript :: < bitcoin:: PublicKey , Segwitv0 > :: parse_insane ( & enc) . unwrap ( ) ;
1667+ let ms = Miniscript :: < bitcoin:: PublicKey , Segwitv0 > :: decode_insane ( & enc) . unwrap ( ) ;
16681668 assert_eq ! ( ms_trans. encode( ) , ms. encode( ) ) ;
16691669 }
16701670
@@ -1686,9 +1686,9 @@ mod tests {
16861686
16871687 let script = ms. encode ( ) ;
16881688 // The same test, but parsing from script
1689- SegwitMs :: parse ( & script) . unwrap_err ( ) ;
1690- SegwitMs :: parse_insane ( & script) . unwrap_err ( ) ;
1691- SegwitMs :: parse_with_ext ( & script, & ExtParams :: allow_all ( ) ) . unwrap ( ) ;
1689+ SegwitMs :: decode ( & script) . unwrap_err ( ) ;
1690+ SegwitMs :: decode_insane ( & script) . unwrap_err ( ) ;
1691+ SegwitMs :: decode_with_ext ( & script, & ExtParams :: allow_all ( ) ) . unwrap ( ) ;
16921692
16931693 // Try replacing the raw_pkh with a pkh
16941694 let mut map = BTreeMap :: new ( ) ;
@@ -1880,7 +1880,7 @@ mod tests {
18801880 for _ in 0 ..10000 {
18811881 script = script. push_opcode ( bitcoin:: opcodes:: all:: OP_0NOTEQUAL ) ;
18821882 }
1883- Tapscript :: parse_insane ( & script. into_script ( ) ) . unwrap_err ( ) ;
1883+ Tapscript :: decode_insane ( & script. into_script ( ) ) . unwrap_err ( ) ;
18841884 }
18851885
18861886 #[ test]
0 commit comments