@@ -37,6 +37,10 @@ use {Error, MiniscriptKey};
37
37
/// to assist the compiler
38
38
#[ derive( Clone , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
39
39
pub enum Policy < Pk : MiniscriptKey > {
40
+ /// Unsatisfiable
41
+ Unsatisfiable ,
42
+ /// Trivially satisfiable
43
+ Trivial ,
40
44
/// A public key which must sign to satisfy the descriptor
41
45
Key ( Pk ) ,
42
46
/// An absolute locktime restriction
@@ -147,6 +151,8 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
147
151
Q : MiniscriptKey ,
148
152
{
149
153
match * self {
154
+ Policy :: Unsatisfiable => Ok ( Policy :: Unsatisfiable ) ,
155
+ Policy :: Trivial => Ok ( Policy :: Trivial ) ,
150
156
Policy :: Key ( ref pk) => translatefpk ( pk) . map ( Policy :: Key ) ,
151
157
Policy :: Sha256 ( ref h) => Ok ( Policy :: Sha256 ( h. clone ( ) ) ) ,
152
158
Policy :: Hash256 ( ref h) => Ok ( Policy :: Hash256 ( h. clone ( ) ) ) ,
@@ -192,7 +198,9 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
192
198
fn check_timelocks_helper ( & self ) -> TimeLockInfo {
193
199
// timelocks[csv_h, csv_t, cltv_h, cltv_t, combination]
194
200
match * self {
195
- Policy :: Key ( _)
201
+ Policy :: Unsatisfiable
202
+ | Policy :: Trivial
203
+ | Policy :: Key ( _)
196
204
| Policy :: Sha256 ( _)
197
205
| Policy :: Hash256 ( _)
198
206
| Policy :: Ripemd160 ( _)
@@ -284,6 +292,7 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
284
292
///
285
293
pub fn is_safe_nonmalleable ( & self ) -> ( bool , bool ) {
286
294
match * self {
295
+ Policy :: Unsatisfiable | Policy :: Trivial => ( true , true ) ,
287
296
Policy :: Key ( _) => ( true , true ) ,
288
297
Policy :: Sha256 ( _)
289
298
| Policy :: Hash256 ( _)
@@ -330,6 +339,8 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
330
339
impl < Pk : MiniscriptKey > fmt:: Debug for Policy < Pk > {
331
340
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
332
341
match * self {
342
+ Policy :: Unsatisfiable => f. write_str ( "UNSATISFIABLE()" ) ,
343
+ Policy :: Trivial => f. write_str ( "TRIVIAL()" ) ,
333
344
Policy :: Key ( ref pk) => write ! ( f, "pk({:?})" , pk) ,
334
345
Policy :: After ( n) => write ! ( f, "after({})" , n) ,
335
346
Policy :: Older ( n) => write ! ( f, "older({})" , n) ,
@@ -371,6 +382,8 @@ impl<Pk: MiniscriptKey> fmt::Debug for Policy<Pk> {
371
382
impl < Pk : MiniscriptKey > fmt:: Display for Policy < Pk > {
372
383
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
373
384
match * self {
385
+ Policy :: Unsatisfiable => f. write_str ( "UNSATISFIABLE" ) ,
386
+ Policy :: Trivial => f. write_str ( "TRIVIAL" ) ,
374
387
Policy :: Key ( ref pk) => write ! ( f, "pk({})" , pk) ,
375
388
Policy :: After ( n) => write ! ( f, "after({})" , n) ,
376
389
Policy :: Older ( n) => write ! ( f, "older({})" , n) ,
@@ -468,6 +481,8 @@ where
468
481
}
469
482
}
470
483
match ( frag_name, top. args . len ( ) as u32 ) {
484
+ ( "UNSATISFIABLE" , 0 ) => Ok ( Policy :: Unsatisfiable ) ,
485
+ ( "TRIVIAL" , 0 ) => Ok ( Policy :: Trivial ) ,
471
486
( "pk" , 1 ) => expression:: terminal ( & top. args [ 0 ] , |pk| Pk :: from_str ( pk) . map ( Policy :: Key ) ) ,
472
487
( "after" , 1 ) => {
473
488
let num = expression:: terminal ( & top. args [ 0 ] , |x| expression:: parse_num ( x) ) ?;
0 commit comments