@@ -21,8 +21,7 @@ use crate::miniscript::ScriptContext;
2121use crate :: prelude:: * ;
2222use crate :: util:: MsKeyBuilder ;
2323use crate :: {
24- errstr, expression, script_num_size, AbsLockTime , Error , Miniscript , MiniscriptKey , Terminal ,
25- ToPublicKey ,
24+ errstr, expression, AbsLockTime , Error , Miniscript , MiniscriptKey , Terminal , ToPublicKey ,
2625} ;
2726
2827impl < Pk : MiniscriptKey , Ctx : ScriptContext > Terminal < Pk , Ctx > {
@@ -665,64 +664,4 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Terminal<Pk, Ctx> {
665664 }
666665 }
667666 }
668-
669- /// Size, in bytes of the script-pubkey. If this Miniscript is used outside
670- /// of segwit (e.g. in a bare or P2SH descriptor), this quantity should be
671- /// multiplied by 4 to compute the weight.
672- ///
673- /// In general, it is not recommended to use this function directly, but
674- /// to instead call the corresponding function on a `Descriptor`, which
675- /// will handle the segwit/non-segwit technicalities for you.
676- pub fn script_size ( & self ) -> usize {
677- match * self {
678- Terminal :: PkK ( ref pk) => Ctx :: pk_len ( pk) ,
679- Terminal :: PkH ( ..) | Terminal :: RawPkH ( ..) => 24 ,
680- Terminal :: After ( n) => script_num_size ( n. to_consensus_u32 ( ) as usize ) + 1 ,
681- Terminal :: Older ( n) => script_num_size ( n. to_consensus_u32 ( ) as usize ) + 1 ,
682- Terminal :: Sha256 ( ..) => 33 + 6 ,
683- Terminal :: Hash256 ( ..) => 33 + 6 ,
684- Terminal :: Ripemd160 ( ..) => 21 + 6 ,
685- Terminal :: Hash160 ( ..) => 21 + 6 ,
686- Terminal :: True => 1 ,
687- Terminal :: False => 1 ,
688- Terminal :: Alt ( ref sub) => sub. node . script_size ( ) + 2 ,
689- Terminal :: Swap ( ref sub) => sub. node . script_size ( ) + 1 ,
690- Terminal :: Check ( ref sub) => sub. node . script_size ( ) + 1 ,
691- Terminal :: DupIf ( ref sub) => sub. node . script_size ( ) + 3 ,
692- Terminal :: Verify ( ref sub) => {
693- sub. node . script_size ( ) + usize:: from ( !sub. ext . has_free_verify )
694- }
695- Terminal :: NonZero ( ref sub) => sub. node . script_size ( ) + 4 ,
696- Terminal :: ZeroNotEqual ( ref sub) => sub. node . script_size ( ) + 1 ,
697- Terminal :: AndV ( ref l, ref r) => l. node . script_size ( ) + r. node . script_size ( ) ,
698- Terminal :: AndB ( ref l, ref r) => l. node . script_size ( ) + r. node . script_size ( ) + 1 ,
699- Terminal :: AndOr ( ref a, ref b, ref c) => {
700- a. node . script_size ( ) + b. node . script_size ( ) + c. node . script_size ( ) + 3
701- }
702- Terminal :: OrB ( ref l, ref r) => l. node . script_size ( ) + r. node . script_size ( ) + 1 ,
703- Terminal :: OrD ( ref l, ref r) => l. node . script_size ( ) + r. node . script_size ( ) + 3 ,
704- Terminal :: OrC ( ref l, ref r) => l. node . script_size ( ) + r. node . script_size ( ) + 2 ,
705- Terminal :: OrI ( ref l, ref r) => l. node . script_size ( ) + r. node . script_size ( ) + 3 ,
706- Terminal :: Thresh ( k, ref subs) => {
707- assert ! ( !subs. is_empty( ) , "threshold must be nonempty" ) ;
708- script_num_size ( k) // k
709- + 1 // EQUAL
710- + subs. iter ( ) . map ( |s| s. node . script_size ( ) ) . sum :: < usize > ( )
711- + subs. len ( ) // ADD
712- - 1 // no ADD on first element
713- }
714- Terminal :: Multi ( k, ref pks) => {
715- script_num_size ( k)
716- + 1
717- + script_num_size ( pks. len ( ) )
718- + pks. iter ( ) . map ( |pk| Ctx :: pk_len ( pk) ) . sum :: < usize > ( )
719- }
720- Terminal :: MultiA ( k, ref pks) => {
721- script_num_size ( k)
722- + 1 // NUMEQUAL
723- + pks. iter ( ) . map ( |pk| Ctx :: pk_len ( pk) ) . sum :: < usize > ( ) // n keys
724- + pks. len ( ) // n times CHECKSIGADD
725- }
726- }
727- }
728667}
0 commit comments