@@ -529,8 +529,8 @@ impl<Ctx: ScriptContext> Miniscript<Ctx::Key, Ctx> {
529
529
/// Some of the analysis guarantees of miniscript are lost when dealing with
530
530
/// insane scripts. In general, in a multi-party setting users should only
531
531
/// 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 ( ) )
534
534
}
535
535
536
536
/// 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> {
540
540
/// - Parsing miniscripts with raw pubkey hashes
541
541
///
542
542
/// Allowed extra features can be specified by the ext [`ExtParams`] argument.
543
- pub fn parse_with_ext (
543
+ pub fn decode_with_ext (
544
544
script : & script:: Script ,
545
545
ext : & ExtParams ,
546
546
) -> Result < Miniscript < Ctx :: Key , Ctx > , Error > {
547
547
let tokens = lex ( script) ?;
548
548
let mut iter = TokenIter :: new ( tokens) ;
549
549
550
- let top = decode:: parse ( & mut iter) ?;
550
+ let top = decode:: decode ( & mut iter) ?;
551
551
Ctx :: check_global_validity ( & top) ?;
552
552
let type_check = types:: Type :: type_check ( & top. node ) ?;
553
553
if type_check. corr . base != types:: Base :: B {
@@ -578,24 +578,24 @@ impl<Ctx: ScriptContext> Miniscript<Ctx::Key, Ctx> {
578
578
/// type TapScript = Miniscript<XOnlyPublicKey, Tap>;
579
579
///
580
580
/// // 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(
582
582
/// "202788ee41e76f4f3af603da5bc8fa22997bc0344bb0f95666ba6aaff0242baa99ac",
583
583
/// ).expect("Even length hex"))
584
584
/// .expect("Xonly keys are valid only in taproot context");
585
585
/// // 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(
587
587
/// "21022788ee41e76f4f3af603da5bc8fa22997bc0344bb0f95666ba6aaff0242baa99ac",
588
588
/// ).expect("Even length hex"))
589
589
/// .expect_err("Compressed keys cannot be used in Taproot context");
590
590
/// // Segwitv0 succeeds decoding with full keys.
591
- /// Segwitv0Script::parse (&bitcoin::ScriptBuf::from_hex(
591
+ /// Segwitv0Script::decode (&bitcoin::ScriptBuf::from_hex(
592
592
/// "21022788ee41e76f4f3af603da5bc8fa22997bc0344bb0f95666ba6aaff0242baa99ac",
593
593
/// ).expect("Even length hex"))
594
594
/// .expect("Compressed keys are allowed in Segwit context");
595
595
///
596
596
/// ```
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 ( ) ) ?;
599
599
Ok ( ms)
600
600
}
601
601
}
@@ -1165,7 +1165,7 @@ mod tests {
1165
1165
assert_eq ! ( format!( "{:x}" , bitcoin_script) , expected) ;
1166
1166
}
1167
1167
// 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 ( ) )
1169
1169
. expect ( "parse string serialization" ) ;
1170
1170
assert_eq ! ( roundtrip, script) ;
1171
1171
}
@@ -1175,7 +1175,7 @@ mod tests {
1175
1175
let ser = tree. encode ( ) ;
1176
1176
assert_eq ! ( ser. len( ) , tree. script_size( ) ) ;
1177
1177
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" ) ;
1179
1179
assert_eq ! ( * tree, deser) ;
1180
1180
}
1181
1181
@@ -1316,19 +1316,19 @@ mod tests {
1316
1316
fn verify_parse ( ) {
1317
1317
let ms = "and_v(v:hash160(20195b5a3d650c17f0f29f91c33f8f6335193d07),or_d(sha256(96de8fc8c256fa1e1556d41af431cace7dca68707c78dd88c3acab8b17164c47),older(16)))" ;
1318
1318
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( ) ) ;
1320
1320
1321
1321
let ms = "and_v(v:sha256(96de8fc8c256fa1e1556d41af431cace7dca68707c78dd88c3acab8b17164c47),or_d(sha256(96de8fc8c256fa1e1556d41af431cace7dca68707c78dd88c3acab8b17164c47),older(16)))" ;
1322
1322
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( ) ) ;
1324
1324
1325
1325
let ms = "and_v(v:ripemd160(20195b5a3d650c17f0f29f91c33f8f6335193d07),or_d(sha256(96de8fc8c256fa1e1556d41af431cace7dca68707c78dd88c3acab8b17164c47),older(16)))" ;
1326
1326
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( ) ) ;
1328
1328
1329
1329
let ms = "and_v(v:hash256(96de8fc8c256fa1e1556d41af431cace7dca68707c78dd88c3acab8b17164c47),or_d(sha256(96de8fc8c256fa1e1556d41af431cace7dca68707c78dd88c3acab8b17164c47),older(16)))" ;
1330
1330
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( ) ) ;
1332
1332
}
1333
1333
1334
1334
#[ test]
@@ -1519,21 +1519,21 @@ mod tests {
1519
1519
#[ test]
1520
1520
fn deserialize ( ) {
1521
1521
// 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
1532
1532
1533
1533
// 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(
1537
1537
"2102ffffffffffffffefefefefefefefefefefef394c0fe5b711179e124008584753ac6900"
1538
1538
) )
1539
1539
. is_err( ) ) ;
@@ -1573,22 +1573,22 @@ mod tests {
1573
1573
1574
1574
//---------------- test script <-> miniscript ---------------
1575
1575
// Test parsing from scripts: x-only fails decoding in segwitv0 ctx
1576
- Segwitv0Script :: parse_insane ( & hex_script (
1576
+ Segwitv0Script :: decode_insane ( & hex_script (
1577
1577
"202788ee41e76f4f3af603da5bc8fa22997bc0344bb0f95666ba6aaff0242baa99ac" ,
1578
1578
) )
1579
1579
. unwrap_err ( ) ;
1580
1580
// x-only succeeds in tap ctx
1581
- Tapscript :: parse_insane ( & hex_script (
1581
+ Tapscript :: decode_insane ( & hex_script (
1582
1582
"202788ee41e76f4f3af603da5bc8fa22997bc0344bb0f95666ba6aaff0242baa99ac" ,
1583
1583
) )
1584
1584
. unwrap ( ) ;
1585
1585
// tapscript fails decoding with compressed
1586
- Tapscript :: parse_insane ( & hex_script (
1586
+ Tapscript :: decode_insane ( & hex_script (
1587
1587
"21022788ee41e76f4f3af603da5bc8fa22997bc0344bb0f95666ba6aaff0242baa99ac" ,
1588
1588
) )
1589
1589
. unwrap_err ( ) ;
1590
1590
// Segwitv0 succeeds decoding with tapscript.
1591
- Segwitv0Script :: parse_insane ( & hex_script (
1591
+ Segwitv0Script :: decode_insane ( & hex_script (
1592
1592
"21022788ee41e76f4f3af603da5bc8fa22997bc0344bb0f95666ba6aaff0242baa99ac" ,
1593
1593
) )
1594
1594
. unwrap ( ) ;
@@ -1624,7 +1624,7 @@ mod tests {
1624
1624
. unwrap ( ) ;
1625
1625
// script rtt test
1626
1626
assert_eq ! (
1627
- Miniscript :: <XOnlyPublicKey , Tap >:: parse_insane ( & tap_ms. encode( ) ) . unwrap( ) ,
1627
+ Miniscript :: <XOnlyPublicKey , Tap >:: decode_insane ( & tap_ms. encode( ) ) . unwrap( ) ,
1628
1628
tap_ms
1629
1629
) ;
1630
1630
assert_eq ! ( tap_ms. script_size( ) , 104 ) ;
@@ -1665,7 +1665,7 @@ mod tests {
1665
1665
. unwrap ( ) ;
1666
1666
let ms_trans = ms. translate_pk ( & mut StrKeyTranslator :: new ( ) ) . unwrap ( ) ;
1667
1667
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 ( ) ;
1669
1669
assert_eq ! ( ms_trans. encode( ) , ms. encode( ) ) ;
1670
1670
}
1671
1671
@@ -1687,9 +1687,9 @@ mod tests {
1687
1687
1688
1688
let script = ms. encode ( ) ;
1689
1689
// 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 ( ) ;
1693
1693
1694
1694
// Try replacing the raw_pkh with a pkh
1695
1695
let mut map = BTreeMap :: new ( ) ;
@@ -1881,7 +1881,7 @@ mod tests {
1881
1881
for _ in 0 ..10000 {
1882
1882
script = script. push_opcode ( bitcoin:: opcodes:: all:: OP_0NOTEQUAL ) ;
1883
1883
}
1884
- Tapscript :: parse_insane ( & script. into_script ( ) ) . unwrap_err ( ) ;
1884
+ Tapscript :: decode_insane ( & script. into_script ( ) ) . unwrap_err ( ) ;
1885
1885
}
1886
1886
1887
1887
#[ test]
0 commit comments