@@ -122,33 +122,24 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Miniscript<Pk, Ctx> {
122
122
/// to instead call the corresponding function on a `Descriptor`, which
123
123
/// will handle the segwit/non-segwit technicalities for you.
124
124
pub fn script_size ( & self ) -> usize {
125
+ use Terminal :: * ;
126
+
125
127
let mut len = 0 ;
126
128
for ms in self . pre_order_iter ( ) {
127
129
len += match ms. node {
130
+ AndV ( ..) => 0 ,
131
+ True | False | Swap ( ..) | Check ( ..) | ZeroNotEqual ( ..) | AndB ( ..) | OrB ( ..) => 1 ,
132
+ Alt ( ..) | OrC ( ..) => 2 ,
133
+ DupIf ( ..) | AndOr ( ..) | OrD ( ..) | OrI ( ..) => 3 ,
134
+ NonZero ( ..) => 4 ,
135
+ PkH ( ..) | RawPkH ( ..) => 24 ,
136
+ Ripemd160 ( ..) | Hash160 ( ..) => 21 + 6 ,
137
+ Sha256 ( ..) | Hash256 ( ..) => 33 + 6 ,
138
+
128
139
Terminal :: PkK ( ref pk) => Ctx :: pk_len ( pk) ,
129
- Terminal :: PkH ( ..) | Terminal :: RawPkH ( ..) => 24 ,
130
140
Terminal :: After ( n) => script_num_size ( n. to_consensus_u32 ( ) as usize ) + 1 ,
131
141
Terminal :: Older ( n) => script_num_size ( n. to_consensus_u32 ( ) as usize ) + 1 ,
132
- Terminal :: Sha256 ( ..) => 33 + 6 ,
133
- Terminal :: Hash256 ( ..) => 33 + 6 ,
134
- Terminal :: Ripemd160 ( ..) => 21 + 6 ,
135
- Terminal :: Hash160 ( ..) => 21 + 6 ,
136
- Terminal :: True => 1 ,
137
- Terminal :: False => 1 ,
138
- Terminal :: Alt ( ..) => 2 ,
139
- Terminal :: Swap ( ..) => 1 ,
140
- Terminal :: Check ( ..) => 1 ,
141
- Terminal :: DupIf ( ..) => 3 ,
142
142
Terminal :: Verify ( ref sub) => usize:: from ( !sub. ext . has_free_verify ) ,
143
- Terminal :: NonZero ( ..) => 4 ,
144
- Terminal :: ZeroNotEqual ( ..) => 1 ,
145
- Terminal :: AndV ( ..) => 0 ,
146
- Terminal :: AndB ( ..) => 1 ,
147
- Terminal :: AndOr ( ..) => 3 ,
148
- Terminal :: OrB ( ..) => 1 ,
149
- Terminal :: OrD ( ..) => 3 ,
150
- Terminal :: OrC ( ..) => 2 ,
151
- Terminal :: OrI ( ..) => 3 ,
152
143
Terminal :: Thresh ( k, ref subs) => {
153
144
assert ! ( !subs. is_empty( ) , "threshold must be nonempty" ) ;
154
145
script_num_size ( k) // k
0 commit comments