@@ -338,7 +338,11 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Miniscript<Pk, Ctx> {
338
338
} ;
339
339
Ok ( ms)
340
340
}
341
+ }
341
342
343
+ impl_block_str ! (
344
+ ; Ctx ; ScriptContext ,
345
+ Miniscript <Pk , Ctx >,
342
346
/// Attempt to parse an insane(scripts don't clear sanity checks)
343
347
/// from string into a Miniscript representation.
344
348
/// Use this to parse scripts with repeated pubkeys, timelock mixing, malleable
@@ -347,11 +351,6 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Miniscript<Pk, Ctx> {
347
351
/// insane scripts. In general, in a multi-party setting users should only
348
352
/// accept sane scripts.
349
353
pub fn from_str_insane( s: & str ) -> Result <Miniscript <Pk , Ctx >, Error >
350
- where
351
- Pk : str:: FromStr ,
352
- Pk :: Hash : str:: FromStr ,
353
- <Pk as str:: FromStr >:: Err : ToString ,
354
- <<Pk as MiniscriptKey >:: Hash as str:: FromStr >:: Err : ToString ,
355
354
{
356
355
// This checks for invalid ASCII chars
357
356
let top = expression:: Tree :: from_str( s) ?;
@@ -363,7 +362,7 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Miniscript<Pk, Ctx> {
363
362
Ok ( ms)
364
363
}
365
364
}
366
- }
365
+ ) ;
367
366
368
367
impl < Pk : MiniscriptKey , Ctx : ScriptContext > Miniscript < Pk , Ctx > {
369
368
/// Attempt to produce non-malleable satisfying witness for the
@@ -475,8 +474,7 @@ mod tests {
475
474
use crate :: policy:: Liftable ;
476
475
use crate :: prelude:: * ;
477
476
use crate :: {
478
- hex_script, DummyKey , DummyKeyHash , MiniscriptKey , Satisfier , ToPublicKey , TranslatePk ,
479
- TranslatePk1 , TranslatePk2 ,
477
+ hex_script, DummyKey , DummyKeyHash , Satisfier , ToPublicKey , TranslatePk , TranslatePk2 ,
480
478
} ;
481
479
482
480
type Segwitv0Script = Miniscript < bitcoin:: PublicKey , Segwitv0 > ;
@@ -503,19 +501,11 @@ mod tests {
503
501
ret
504
502
}
505
503
506
- fn string_rtt < Pk , Ctx , Str1 , Str2 > (
507
- script : Miniscript < Pk , Ctx > ,
508
- expected_debug : Str1 ,
509
- expected_display : Str2 ,
510
- ) where
511
- Pk : MiniscriptKey + str:: FromStr ,
512
- Pk :: Hash : str:: FromStr ,
513
- Ctx : ScriptContext ,
514
- <Pk as str:: FromStr >:: Err : ToString ,
515
- <<Pk as MiniscriptKey >:: Hash as str:: FromStr >:: Err : ToString ,
516
- Str1 : Into < Option < & ' static str > > ,
517
- Str2 : Into < Option < & ' static str > > ,
518
- {
504
+ fn string_rtt < Ctx : ScriptContext > (
505
+ script : Miniscript < bitcoin:: PublicKey , Ctx > ,
506
+ expected_debug : & str ,
507
+ expected_display : & str ,
508
+ ) {
519
509
assert_eq ! ( script. ty. corr. base, types:: Base :: B ) ;
520
510
let debug = format ! ( "{:?}" , script) ;
521
511
let display = format ! ( "{}" , script) ;
@@ -527,12 +517,24 @@ mod tests {
527
517
}
528
518
let roundtrip = Miniscript :: from_str ( & display) . expect ( "parse string serialization" ) ;
529
519
assert_eq ! ( roundtrip, script) ;
520
+ }
530
521
531
- let translated = script. translate_pk_infallible ( Pk :: clone, Pk :: Hash :: clone) ;
532
- assert_eq ! ( translated, script) ;
533
-
534
- let translated = script. translate_pk1_infallible ( Pk :: clone) ;
535
- assert_eq ! ( translated, script) ;
522
+ fn dummy_string_rtt < Ctx : ScriptContext > (
523
+ script : Miniscript < DummyKey , Ctx > ,
524
+ expected_debug : & str ,
525
+ expected_display : & str ,
526
+ ) {
527
+ assert_eq ! ( script. ty. corr. base, types:: Base :: B ) ;
528
+ let debug = format ! ( "{:?}" , script) ;
529
+ let display = format ! ( "{}" , script) ;
530
+ if let Some ( expected) = expected_debug. into ( ) {
531
+ assert_eq ! ( debug, expected) ;
532
+ }
533
+ if let Some ( expected) = expected_display. into ( ) {
534
+ assert_eq ! ( display, expected) ;
535
+ }
536
+ let roundtrip = Miniscript :: from_str ( & display) . expect ( "parse string serialization" ) ;
537
+ assert_eq ! ( roundtrip, script) ;
536
538
}
537
539
538
540
fn script_rtt < Str1 : Into < Option < & ' static str > > > ( script : Segwitv0Script , expected_hex : Str1 ) {
@@ -648,7 +650,7 @@ mod tests {
648
650
ext : ExtData :: cast_check ( ExtData :: from_pk_k :: < Segwitv0 > ( ) ) . unwrap ( ) ,
649
651
phantom : PhantomData ,
650
652
} ;
651
- string_rtt ( pkk_ms, "[B/onduesm]c:[K/onduesm]pk_k(DummyKey)" , "pk()" ) ;
653
+ dummy_string_rtt ( pkk_ms, "[B/onduesm]c:[K/onduesm]pk_k(DummyKey)" , "pk()" ) ;
652
654
653
655
let pkh_ms: Miniscript < DummyKey , Segwitv0 > = Miniscript {
654
656
node : Terminal :: Check ( Arc :: new ( Miniscript {
@@ -661,7 +663,7 @@ mod tests {
661
663
ext : ExtData :: cast_check ( ExtData :: from_pk_h :: < Segwitv0 > ( ) ) . unwrap ( ) ,
662
664
phantom : PhantomData ,
663
665
} ;
664
- string_rtt ( pkh_ms, "[B/nduesm]c:[K/nduesm]pk_h(DummyKeyHash)" , "pkh()" ) ;
666
+ dummy_string_rtt ( pkh_ms, "[B/nduesm]c:[K/nduesm]pk_h(DummyKeyHash)" , "pkh()" ) ;
665
667
666
668
let pkk_ms: Segwitv0Script = Miniscript {
667
669
node : Terminal :: Check ( Arc :: new ( Miniscript {
0 commit comments