@@ -145,16 +145,13 @@ struct CompilerExtData {
145145 dissat_cost : Option < f64 > ,
146146}
147147
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 } ;
152150
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 ) } ;
156153
157- fn from_pk_k < Ctx : ScriptContext > ( ) -> Self {
154+ fn pk_k < Ctx : ScriptContext > ( ) -> Self {
158155 CompilerExtData {
159156 branch_prob : None ,
160157 sat_cost : match Ctx :: sig_type ( ) {
@@ -165,7 +162,7 @@ impl Property for CompilerExtData {
165162 }
166163 }
167164
168- fn from_pk_h < Ctx : ScriptContext > ( ) -> Self {
165+ fn pk_h < Ctx : ScriptContext > ( ) -> Self {
169166 CompilerExtData {
170167 branch_prob : None ,
171168 sat_cost : match Ctx :: sig_type ( ) {
@@ -181,29 +178,27 @@ impl Property for CompilerExtData {
181178 }
182179 }
183180
184- fn from_multi ( k : usize , _n : usize ) -> Self {
181+ fn multi ( k : usize , _n : usize ) -> Self {
185182 CompilerExtData {
186183 branch_prob : None ,
187184 sat_cost : 1.0 + 73.0 * k as f64 ,
188185 dissat_cost : Some ( 1.0 * ( k + 1 ) as f64 ) ,
189186 }
190187 }
191188
192- fn from_multi_a ( k : usize , n : usize ) -> Self {
189+ fn multi_a ( k : usize , n : usize ) -> Self {
193190 CompilerExtData {
194191 branch_prob : None ,
195192 sat_cost : 66.0 * k as f64 + ( n - k) as f64 ,
196193 dissat_cost : Some ( n as f64 ) , /* <w_n> ... <w_1> := 0x00 ... 0x00 (n times) */
197194 }
198195 }
199196
200- fn from_hash ( ) -> Self {
197+ fn hash ( ) -> Self {
201198 CompilerExtData { branch_prob : None , sat_cost : 33.0 , dissat_cost : Some ( 33.0 ) }
202199 }
203200
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 } }
207202
208203 fn cast_alt ( self ) -> Result < Self , types:: ErrorKind > {
209204 Ok ( CompilerExtData {
@@ -257,11 +252,6 @@ impl Property for CompilerExtData {
257252 Ok ( CompilerExtData { branch_prob : None , sat_cost : self . sat_cost , dissat_cost : None } )
258253 }
259254
260- fn cast_or_i_false ( self ) -> Result < Self , types:: ErrorKind > {
261- // never called directly
262- unreachable ! ( )
263- }
264-
265255 fn cast_unlikely ( self ) -> Result < Self , types:: ErrorKind > {
266256 Ok ( CompilerExtData {
267257 branch_prob : None ,
@@ -386,14 +376,6 @@ impl Property for CompilerExtData {
386376 } )
387377 }
388378
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-
397379 fn threshold < S > ( k : usize , n : usize , mut sub_ck : S ) -> Result < Self , types:: ErrorKind >
398380 where
399381 S : FnMut ( usize ) -> Result < Self , types:: ErrorKind > ,
@@ -457,11 +439,11 @@ impl CompilerExtData {
457439 . map_err ( |kind| types:: Error { fragment_string : fragment. to_string ( ) , error : kind } )
458440 } ;
459441
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 > ( ) ) ,
465447 Terminal :: Multi ( k, ref pks) | Terminal :: MultiA ( k, ref pks) => {
466448 if k == 0 {
467449 return Err ( types:: Error {
@@ -476,8 +458,8 @@ impl CompilerExtData {
476458 } ) ;
477459 }
478460 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 ( ) ) ) ,
481463 _ => unreachable ! ( ) ,
482464 }
483465 }
@@ -491,7 +473,7 @@ impl CompilerExtData {
491473 error : types:: ErrorKind :: InvalidTime ,
492474 } ) ;
493475 }
494- Ok ( Self :: from_after ( t . into ( ) ) )
476+ Ok ( Self :: time ( ) )
495477 }
496478 Terminal :: Older ( t) => {
497479 if t == Sequence :: ZERO || !t. is_relative_lock_time ( ) {
@@ -500,12 +482,12 @@ impl CompilerExtData {
500482 error : types:: ErrorKind :: InvalidTime ,
501483 } ) ;
502484 }
503- Ok ( Self :: from_older ( t ) )
485+ Ok ( Self :: time ( ) )
504486 }
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 ( ) ) ,
509491 Terminal :: Alt ( ref sub) => wrap_err ( Self :: cast_alt ( get_child ( & sub. node , 0 ) ?) ) ,
510492 Terminal :: Swap ( ref sub) => wrap_err ( Self :: cast_swap ( get_child ( & sub. node , 0 ) ?) ) ,
511493 Terminal :: Check ( ref sub) => wrap_err ( Self :: cast_check ( get_child ( & sub. node , 0 ) ?) ) ,
@@ -579,11 +561,7 @@ impl CompilerExtData {
579561 error : kind,
580562 } )
581563 }
582- } ;
583- if let Ok ( ref ret) = ret {
584- ret. sanity_checks ( )
585564 }
586- ret
587565 }
588566}
589567
0 commit comments