@@ -320,9 +320,12 @@ macro_rules! match_token {
320
320
struct TerminalStack < Pk : MiniscriptKey , Ctx : ScriptContext > ( Vec < Miniscript < Pk , Ctx > > ) ;
321
321
322
322
impl < Pk : MiniscriptKey , Ctx : ScriptContext > TerminalStack < Pk , Ctx > {
323
- ///Wrapper around self.0.pop()
323
+ /// Wrapper around self.0.pop()
324
324
fn pop ( & mut self ) -> Option < Miniscript < Pk , Ctx > > { self . 0 . pop ( ) }
325
325
326
+ /// Wrapper around self.0.push()
327
+ fn push ( & mut self , ms : Miniscript < Pk , Ctx > ) { self . 0 . push ( ms) }
328
+
326
329
///reduce, type check and push a 0-arg node
327
330
fn reduce0 ( & mut self , ms : Terminal < Pk , Ctx > ) -> Result < ( ) , Error > {
328
331
let ms = Miniscript :: from_ast ( ms) ?;
@@ -375,12 +378,12 @@ pub fn parse<Ctx: ScriptContext>(
375
378
Tk :: Bytes33 ( pk) => {
376
379
let ret = Ctx :: Key :: from_slice( & pk)
377
380
. map_err( |e| Error :: PubKeyCtxError ( e, Ctx :: name_str( ) ) ) ?;
378
- term. reduce0 ( Terminal :: PkK ( ret) ) ?
381
+ term. push ( Miniscript :: pk_k ( ret) ) ;
379
382
} ,
380
383
Tk :: Bytes65 ( pk) => {
381
384
let ret = Ctx :: Key :: from_slice( & pk)
382
385
. map_err( |e| Error :: PubKeyCtxError ( e, Ctx :: name_str( ) ) ) ?;
383
- term. reduce0 ( Terminal :: PkK ( ret) ) ?
386
+ term. push ( Miniscript :: pk_k ( ret) ) ;
384
387
} ,
385
388
// Note this does not collide with hash32 because they always followed by equal
386
389
// and would be parsed in different branch. If we get a naked Bytes32, it must be
@@ -396,7 +399,7 @@ pub fn parse<Ctx: ScriptContext>(
396
399
// Finally for the first case, K being parsed as a solo expression is a Pk type
397
400
Tk :: Bytes32 ( pk) => {
398
401
let ret = Ctx :: Key :: from_slice( & pk) . map_err( |e| Error :: PubKeyCtxError ( e, Ctx :: name_str( ) ) ) ?;
399
- term. reduce0 ( Terminal :: PkK ( ret) ) ?
402
+ term. push ( Miniscript :: pk_k ( ret) ) ;
400
403
} ,
401
404
// checksig
402
405
Tk :: CheckSig => {
@@ -413,38 +416,38 @@ pub fn parse<Ctx: ScriptContext>(
413
416
Tk :: Hash160 => match_token!(
414
417
tokens,
415
418
Tk :: Dup => {
416
- term. reduce0 ( Terminal :: RawPkH (
419
+ term. push ( Miniscript :: expr_raw_pkh (
417
420
hash160:: Hash :: from_byte_array( hash)
418
- ) ) ?
421
+ ) ) ;
419
422
} ,
420
423
Tk :: Verify , Tk :: Equal , Tk :: Num ( 32 ) , Tk :: Size => {
421
424
non_term. push( NonTerm :: Verify ) ;
422
- term. reduce0 ( Terminal :: Hash160 (
425
+ term. push ( Miniscript :: hash160 (
423
426
hash160:: Hash :: from_byte_array( hash)
424
- ) ) ?
427
+ ) ) ;
425
428
} ,
426
429
) ,
427
430
Tk :: Ripemd160 , Tk :: Verify , Tk :: Equal , Tk :: Num ( 32 ) , Tk :: Size => {
428
431
non_term. push( NonTerm :: Verify ) ;
429
- term. reduce0 ( Terminal :: Ripemd160 (
432
+ term. push ( Miniscript :: ripemd160 (
430
433
ripemd160:: Hash :: from_byte_array( hash)
431
- ) ) ?
434
+ ) ) ;
432
435
} ,
433
436
) ,
434
437
// Tk::Hash20(hash),
435
438
Tk :: Bytes32 ( hash) => match_token!(
436
439
tokens,
437
440
Tk :: Sha256 , Tk :: Verify , Tk :: Equal , Tk :: Num ( 32 ) , Tk :: Size => {
438
441
non_term. push( NonTerm :: Verify ) ;
439
- term. reduce0 ( Terminal :: Sha256 (
442
+ term. push ( Miniscript :: sha256 (
440
443
sha256:: Hash :: from_byte_array( hash)
441
- ) ) ?
444
+ ) ) ;
442
445
} ,
443
446
Tk :: Hash256 , Tk :: Verify , Tk :: Equal , Tk :: Num ( 32 ) , Tk :: Size => {
444
447
non_term. push( NonTerm :: Verify ) ;
445
- term. reduce0 ( Terminal :: Hash256 (
448
+ term. push ( Miniscript :: hash256 (
446
449
hash256:: Hash :: from_byte_array( hash)
447
- ) ) ?
450
+ ) ) ;
448
451
} ,
449
452
) ,
450
453
Tk :: Num ( k) => {
@@ -467,9 +470,9 @@ pub fn parse<Ctx: ScriptContext>(
467
470
} ,
468
471
// timelocks
469
472
Tk :: CheckSequenceVerify , Tk :: Num ( n)
470
- => term. reduce0 ( Terminal :: Older ( RelLockTime :: from_consensus( n) . map_err( Error :: RelativeLockTime ) ?) ) ? ,
473
+ => term. push ( Miniscript :: older ( RelLockTime :: from_consensus( n) . map_err( Error :: RelativeLockTime ) ?) ) ,
471
474
Tk :: CheckLockTimeVerify , Tk :: Num ( n)
472
- => term. reduce0 ( Terminal :: After ( AbsLockTime :: from_consensus( n) . map_err( Error :: AbsoluteLockTime ) ?) ) ? ,
475
+ => term. push ( Miniscript :: after ( AbsLockTime :: from_consensus( n) . map_err( Error :: AbsoluteLockTime ) ?) ) ,
473
476
// hashlocks
474
477
Tk :: Equal => match_token!(
475
478
tokens,
@@ -479,33 +482,33 @@ pub fn parse<Ctx: ScriptContext>(
479
482
Tk :: Verify ,
480
483
Tk :: Equal ,
481
484
Tk :: Num ( 32 ) ,
482
- Tk :: Size => term. reduce0 ( Terminal :: Sha256 (
485
+ Tk :: Size => term. push ( Miniscript :: sha256 (
483
486
sha256:: Hash :: from_byte_array( hash)
484
- ) ) ? ,
487
+ ) ) ,
485
488
Tk :: Hash256 ,
486
489
Tk :: Verify ,
487
490
Tk :: Equal ,
488
491
Tk :: Num ( 32 ) ,
489
- Tk :: Size => term. reduce0 ( Terminal :: Hash256 (
492
+ Tk :: Size => term. push ( Miniscript :: hash256 (
490
493
hash256:: Hash :: from_byte_array( hash)
491
- ) ) ? ,
494
+ ) ) ,
492
495
) ,
493
496
Tk :: Hash20 ( hash) => match_token!(
494
497
tokens,
495
498
Tk :: Ripemd160 ,
496
499
Tk :: Verify ,
497
500
Tk :: Equal ,
498
501
Tk :: Num ( 32 ) ,
499
- Tk :: Size => term. reduce0 ( Terminal :: Ripemd160 (
502
+ Tk :: Size => term. push ( Miniscript :: ripemd160 (
500
503
ripemd160:: Hash :: from_byte_array( hash)
501
- ) ) ? ,
504
+ ) ) ,
502
505
Tk :: Hash160 ,
503
506
Tk :: Verify ,
504
507
Tk :: Equal ,
505
508
Tk :: Num ( 32 ) ,
506
- Tk :: Size => term. reduce0 ( Terminal :: Hash160 (
509
+ Tk :: Size => term. push ( Miniscript :: hash160 (
507
510
hash160:: Hash :: from_byte_array( hash)
508
- ) ) ? ,
511
+ ) ) ,
509
512
) ,
510
513
// thresholds
511
514
Tk :: Num ( k) => {
@@ -519,8 +522,8 @@ pub fn parse<Ctx: ScriptContext>(
519
522
} ,
520
523
) ,
521
524
// most other fragments
522
- Tk :: Num ( 0 ) => term. reduce0 ( Terminal :: False ) ? ,
523
- Tk :: Num ( 1 ) => term. reduce0 ( Terminal :: True ) ? ,
525
+ Tk :: Num ( 0 ) => term. push ( Miniscript :: FALSE ) ,
526
+ Tk :: Num ( 1 ) => term. push ( Miniscript :: TRUE ) ,
524
527
Tk :: EndIf => {
525
528
non_term. push( NonTerm :: EndIf ) ;
526
529
non_term. push( NonTerm :: MaybeAndV ) ;
@@ -557,7 +560,7 @@ pub fn parse<Ctx: ScriptContext>(
557
560
) ;
558
561
keys. reverse( ) ;
559
562
let thresh = Threshold :: new( k as usize , keys) . map_err( Error :: Threshold ) ?;
560
- term. reduce0 ( Terminal :: Multi ( thresh) ) ? ;
563
+ term. push ( Miniscript :: multi ( thresh) ) ;
561
564
} ,
562
565
// MultiA
563
566
Tk :: NumEqual , Tk :: Num ( k) => {
@@ -579,7 +582,7 @@ pub fn parse<Ctx: ScriptContext>(
579
582
) ;
580
583
keys. reverse( ) ;
581
584
let thresh = Threshold :: new( k as usize , keys) . map_err( Error :: Threshold ) ?;
582
- term. reduce0 ( Terminal :: MultiA ( thresh) ) ? ;
585
+ term. push ( Miniscript :: multi_a ( thresh) ) ;
583
586
} ,
584
587
) ;
585
588
}
0 commit comments