@@ -195,8 +195,8 @@ pub trait ScriptContext:
195
195
ms : & Miniscript < Pk , Ctx > ,
196
196
) -> Result < ( ) , ScriptContextError > {
197
197
Self :: check_global_consensus_validity ( ms) ?;
198
- Self :: check_global_consensus_validity ( ms) ?;
199
- Self :: check_local_policy_validity ( ms) ?;
198
+ Self :: check_global_policy_validity ( ms) ?;
199
+ Self :: check_local_consensus_validity ( ms) ?;
200
200
Self :: check_local_policy_validity ( ms) ?;
201
201
Ok ( ( ) )
202
202
}
@@ -277,26 +277,28 @@ impl ScriptContext for Legacy {
277
277
fn check_local_consensus_validity < Pk : MiniscriptKey , Ctx : ScriptContext > (
278
278
ms : & Miniscript < Pk , Ctx > ,
279
279
) -> Result < ( ) , ScriptContextError > {
280
- if let Some ( op_count) = ms. ext . ops_count_sat {
281
- if op_count > MAX_OPS_PER_SCRIPT {
282
- return Err ( ScriptContextError :: MaxOpCountExceeded ) ;
280
+ match ms. ext . ops_count_sat {
281
+ None => Err ( ScriptContextError :: MaxOpCountExceeded ) ,
282
+ Some ( op_count) if op_count > MAX_OPS_PER_SCRIPT => {
283
+ Err ( ScriptContextError :: MaxOpCountExceeded )
283
284
}
285
+ _ => Ok ( ( ) ) ,
284
286
}
285
- Ok ( ( ) )
286
287
}
287
288
288
289
fn check_local_policy_validity < Pk : MiniscriptKey , Ctx : ScriptContext > (
289
290
ms : & Miniscript < Pk , Ctx > ,
290
291
) -> Result < ( ) , ScriptContextError > {
291
- if let Some ( size) = ms. max_satisfaction_size ( ) {
292
- if size > MAX_SCRIPTSIG_SIZE {
293
- return Err ( ScriptContextError :: MaxScriptSigSizeExceeded ) ;
294
- }
295
- }
296
292
// Legacy scripts permit upto 1000 stack elements, 520 bytes consensus limits
297
293
// on P2SH size, it is not possible to reach the 1000 elements limit and hence
298
294
// we do not check it.
299
- Ok ( ( ) )
295
+ match ms. max_satisfaction_size ( ) {
296
+ None => Err ( ScriptContextError :: MaxScriptSigSizeExceeded ) ,
297
+ Some ( size) if size > MAX_SCRIPTSIG_SIZE => {
298
+ Err ( ScriptContextError :: MaxScriptSigSizeExceeded )
299
+ }
300
+ _ => Ok ( ( ) ) ,
301
+ }
300
302
}
301
303
302
304
fn max_satisfaction_size < Pk : MiniscriptKey , Ctx : ScriptContext > (
@@ -348,12 +350,13 @@ impl ScriptContext for Segwitv0 {
348
350
fn check_local_consensus_validity < Pk : MiniscriptKey , Ctx : ScriptContext > (
349
351
ms : & Miniscript < Pk , Ctx > ,
350
352
) -> Result < ( ) , ScriptContextError > {
351
- if let Some ( op_count) = ms. ext . ops_count_sat {
352
- if op_count > MAX_OPS_PER_SCRIPT {
353
- return Err ( ScriptContextError :: MaxOpCountExceeded ) ;
353
+ match ms. ext . ops_count_sat {
354
+ None => Err ( ScriptContextError :: MaxOpCountExceeded ) ,
355
+ Some ( op_count) if op_count > MAX_OPS_PER_SCRIPT => {
356
+ Err ( ScriptContextError :: MaxOpCountExceeded )
354
357
}
358
+ _ => Ok ( ( ) ) ,
355
359
}
356
- Ok ( ( ) )
357
360
}
358
361
359
362
fn check_global_policy_validity < Pk : MiniscriptKey , Ctx : ScriptContext > (
@@ -371,12 +374,13 @@ impl ScriptContext for Segwitv0 {
371
374
// We don't need to know if this is actually a p2wsh as the standard satisfaction for
372
375
// other Segwitv0 defined programs all require (much) less than 100 elements.
373
376
// The witness script item is accounted for in max_satisfaction_witness_elements().
374
- if let Some ( max_witness_items) = ms. max_satisfaction_witness_elements ( ) {
375
- if max_witness_items > MAX_STANDARD_P2WSH_STACK_ITEMS {
376
- return Err ( ScriptContextError :: MaxWitnessItemssExceeded ) ;
377
+ match ms. max_satisfaction_witness_elements ( ) {
378
+ None => Err ( ScriptContextError :: MaxWitnessItemssExceeded ) ,
379
+ Some ( max_witness_items) if max_witness_items > MAX_STANDARD_P2WSH_STACK_ITEMS => {
380
+ Err ( ScriptContextError :: MaxWitnessItemssExceeded )
377
381
}
382
+ _ => Ok ( ( ) ) ,
378
383
}
379
- Ok ( ( ) )
380
384
}
381
385
382
386
fn max_satisfaction_size < Pk : MiniscriptKey , Ctx : ScriptContext > (
@@ -417,12 +421,13 @@ impl ScriptContext for Bare {
417
421
fn check_local_consensus_validity < Pk : MiniscriptKey , Ctx : ScriptContext > (
418
422
ms : & Miniscript < Pk , Ctx > ,
419
423
) -> Result < ( ) , ScriptContextError > {
420
- if let Some ( op_count) = ms. ext . ops_count_sat {
421
- if op_count > MAX_OPS_PER_SCRIPT {
422
- return Err ( ScriptContextError :: MaxOpCountExceeded ) ;
424
+ match ms. ext . ops_count_sat {
425
+ None => Err ( ScriptContextError :: MaxOpCountExceeded ) ,
426
+ Some ( op_count) if op_count > MAX_OPS_PER_SCRIPT => {
427
+ Err ( ScriptContextError :: MaxOpCountExceeded )
423
428
}
429
+ _ => Ok ( ( ) ) ,
424
430
}
425
- Ok ( ( ) )
426
431
}
427
432
428
433
fn other_top_level_checks < Pk : MiniscriptKey , Ctx : ScriptContext > (
0 commit comments