@@ -145,16 +145,13 @@ struct CompilerExtData {
145
145
dissat_cost : Option < f64 > ,
146
146
}
147
147
148
- impl Property for CompilerExtData {
149
- fn from_true ( ) -> Self {
150
- CompilerExtData { branch_prob : None , sat_cost : 0.0 , dissat_cost : None }
151
- }
148
+ impl CompilerExtData {
149
+ const TRUE : Self = CompilerExtData { branch_prob : None , sat_cost : 0.0 , dissat_cost : None } ;
152
150
153
- fn from_false ( ) -> Self {
154
- CompilerExtData { branch_prob : None , sat_cost : f64:: MAX , dissat_cost : Some ( 0.0 ) }
155
- }
151
+ const FALSE : Self =
152
+ CompilerExtData { branch_prob : None , sat_cost : f64:: MAX , dissat_cost : Some ( 0.0 ) } ;
156
153
157
- fn from_pk_k < Ctx : ScriptContext > ( ) -> Self {
154
+ fn pk_k < Ctx : ScriptContext > ( ) -> Self {
158
155
CompilerExtData {
159
156
branch_prob : None ,
160
157
sat_cost : match Ctx :: sig_type ( ) {
@@ -165,7 +162,7 @@ impl Property for CompilerExtData {
165
162
}
166
163
}
167
164
168
- fn from_pk_h < Ctx : ScriptContext > ( ) -> Self {
165
+ fn pk_h < Ctx : ScriptContext > ( ) -> Self {
169
166
CompilerExtData {
170
167
branch_prob : None ,
171
168
sat_cost : match Ctx :: sig_type ( ) {
@@ -181,29 +178,27 @@ impl Property for CompilerExtData {
181
178
}
182
179
}
183
180
184
- fn from_multi ( k : usize , _n : usize ) -> Self {
181
+ fn multi ( k : usize , _n : usize ) -> Self {
185
182
CompilerExtData {
186
183
branch_prob : None ,
187
184
sat_cost : 1.0 + 73.0 * k as f64 ,
188
185
dissat_cost : Some ( 1.0 * ( k + 1 ) as f64 ) ,
189
186
}
190
187
}
191
188
192
- fn from_multi_a ( k : usize , n : usize ) -> Self {
189
+ fn multi_a ( k : usize , n : usize ) -> Self {
193
190
CompilerExtData {
194
191
branch_prob : None ,
195
192
sat_cost : 66.0 * k as f64 + ( n - k) as f64 ,
196
193
dissat_cost : Some ( n as f64 ) , /* <w_n> ... <w_1> := 0x00 ... 0x00 (n times) */
197
194
}
198
195
}
199
196
200
- fn from_hash ( ) -> Self {
197
+ fn hash ( ) -> Self {
201
198
CompilerExtData { branch_prob : None , sat_cost : 33.0 , dissat_cost : Some ( 33.0 ) }
202
199
}
203
200
204
- fn from_time ( _t : u32 ) -> Self {
205
- CompilerExtData { branch_prob : None , sat_cost : 0.0 , dissat_cost : None }
206
- }
201
+ fn time ( ) -> Self { CompilerExtData { branch_prob : None , sat_cost : 0.0 , dissat_cost : None } }
207
202
208
203
fn cast_alt ( self ) -> Result < Self , types:: ErrorKind > {
209
204
Ok ( CompilerExtData {
@@ -257,11 +252,6 @@ impl Property for CompilerExtData {
257
252
Ok ( CompilerExtData { branch_prob : None , sat_cost : self . sat_cost , dissat_cost : None } )
258
253
}
259
254
260
- fn cast_or_i_false ( self ) -> Result < Self , types:: ErrorKind > {
261
- // never called directly
262
- unreachable ! ( )
263
- }
264
-
265
255
fn cast_unlikely ( self ) -> Result < Self , types:: ErrorKind > {
266
256
Ok ( CompilerExtData {
267
257
branch_prob : None ,
@@ -386,14 +376,6 @@ impl Property for CompilerExtData {
386
376
} )
387
377
}
388
378
389
- fn and_n ( a : Self , b : Self ) -> Result < Self , types:: ErrorKind > {
390
- Ok ( CompilerExtData {
391
- branch_prob : None ,
392
- sat_cost : a. sat_cost + b. sat_cost ,
393
- dissat_cost : a. dissat_cost ,
394
- } )
395
- }
396
-
397
379
fn threshold < S > ( k : usize , n : usize , mut sub_ck : S ) -> Result < Self , types:: ErrorKind >
398
380
where
399
381
S : FnMut ( usize ) -> Result < Self , types:: ErrorKind > ,
@@ -457,11 +439,11 @@ impl CompilerExtData {
457
439
. map_err ( |kind| types:: Error { fragment_string : fragment. to_string ( ) , error : kind } )
458
440
} ;
459
441
460
- let ret = match * fragment {
461
- Terminal :: True => Ok ( Self :: from_true ( ) ) ,
462
- Terminal :: False => Ok ( Self :: from_false ( ) ) ,
463
- Terminal :: PkK ( ..) => Ok ( Self :: from_pk_k :: < Ctx > ( ) ) ,
464
- Terminal :: PkH ( ..) | Terminal :: RawPkH ( ..) => Ok ( Self :: from_pk_h :: < Ctx > ( ) ) ,
442
+ match * fragment {
443
+ Terminal :: True => Ok ( Self :: TRUE ) ,
444
+ Terminal :: False => Ok ( Self :: FALSE ) ,
445
+ Terminal :: PkK ( ..) => Ok ( Self :: pk_k :: < Ctx > ( ) ) ,
446
+ Terminal :: PkH ( ..) | Terminal :: RawPkH ( ..) => Ok ( Self :: pk_h :: < Ctx > ( ) ) ,
465
447
Terminal :: Multi ( k, ref pks) | Terminal :: MultiA ( k, ref pks) => {
466
448
if k == 0 {
467
449
return Err ( types:: Error {
@@ -476,8 +458,8 @@ impl CompilerExtData {
476
458
} ) ;
477
459
}
478
460
match * fragment {
479
- Terminal :: Multi ( ..) => Ok ( Self :: from_multi ( k, pks. len ( ) ) ) ,
480
- Terminal :: MultiA ( ..) => Ok ( Self :: from_multi_a ( k, pks. len ( ) ) ) ,
461
+ Terminal :: Multi ( ..) => Ok ( Self :: multi ( k, pks. len ( ) ) ) ,
462
+ Terminal :: MultiA ( ..) => Ok ( Self :: multi_a ( k, pks. len ( ) ) ) ,
481
463
_ => unreachable ! ( ) ,
482
464
}
483
465
}
@@ -491,7 +473,7 @@ impl CompilerExtData {
491
473
error : types:: ErrorKind :: InvalidTime ,
492
474
} ) ;
493
475
}
494
- Ok ( Self :: from_after ( t . into ( ) ) )
476
+ Ok ( Self :: time ( ) )
495
477
}
496
478
Terminal :: Older ( t) => {
497
479
if t == Sequence :: ZERO || !t. is_relative_lock_time ( ) {
@@ -500,12 +482,12 @@ impl CompilerExtData {
500
482
error : types:: ErrorKind :: InvalidTime ,
501
483
} ) ;
502
484
}
503
- Ok ( Self :: from_older ( t ) )
485
+ Ok ( Self :: time ( ) )
504
486
}
505
- Terminal :: Sha256 ( ..) => Ok ( Self :: from_sha256 ( ) ) ,
506
- Terminal :: Hash256 ( ..) => Ok ( Self :: from_hash256 ( ) ) ,
507
- Terminal :: Ripemd160 ( ..) => Ok ( Self :: from_ripemd160 ( ) ) ,
508
- Terminal :: Hash160 ( ..) => Ok ( Self :: from_hash160 ( ) ) ,
487
+ Terminal :: Sha256 ( ..) => Ok ( Self :: hash ( ) ) ,
488
+ Terminal :: Hash256 ( ..) => Ok ( Self :: hash ( ) ) ,
489
+ Terminal :: Ripemd160 ( ..) => Ok ( Self :: hash ( ) ) ,
490
+ Terminal :: Hash160 ( ..) => Ok ( Self :: hash ( ) ) ,
509
491
Terminal :: Alt ( ref sub) => wrap_err ( Self :: cast_alt ( get_child ( & sub. node , 0 ) ?) ) ,
510
492
Terminal :: Swap ( ref sub) => wrap_err ( Self :: cast_swap ( get_child ( & sub. node , 0 ) ?) ) ,
511
493
Terminal :: Check ( ref sub) => wrap_err ( Self :: cast_check ( get_child ( & sub. node , 0 ) ?) ) ,
@@ -579,11 +561,7 @@ impl CompilerExtData {
579
561
error : kind,
580
562
} )
581
563
}
582
- } ;
583
- if let Ok ( ref ret) = ret {
584
- ret. sanity_checks ( )
585
564
}
586
- ret
587
565
}
588
566
}
589
567
0 commit comments