Skip to content

Commit aed7009

Browse files
committed
Removed Legacy enum from types
1 parent 16916ef commit aed7009

File tree

1 file changed

+0
-52
lines changed

1 file changed

+0
-52
lines changed

src/miniscript/types/extra_props.rs

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,12 @@ use Terminal;
99

1010
pub const MAX_OPS_PER_SCRIPT: usize = 201;
1111

12-
/// Whether a fragment is OK to be used in non-segwit scripts
13-
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
14-
pub enum LegacySafe {
15-
/// The fragment can be used in pre-segwit contexts without concern
16-
/// about malleability attacks/unbounded 3rd-party fee stuffing. This
17-
/// means it has no `pk_h` constructions (cannot estimate public key
18-
/// size from a hash) and no `d:`/`or_i` constructions (cannot control
19-
/// the size of the switch input to `OP_IF`)
20-
LegacySafe,
21-
/// This fragment can only be safely used with Segwit
22-
SegwitOnly,
23-
}
24-
2512
/// Structure representing the extra type properties of a fragment which are
2613
/// relevant to legacy(pre-segwit) safety and fee estimation. If a fragment is
2714
/// used in pre-segwit transactions it will only be malleable but still is
2815
/// correct and sound.
2916
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
3017
pub struct ExtData {
31-
///enum sorting whether the fragment is safe to be in used in pre-segwit context
32-
pub legacy_safe: LegacySafe,
3318
/// The number of bytes needed to encode its scriptpubkey
3419
pub pk_cost: usize,
3520
/// Whether this fragment can be verify-wrapped for free
@@ -49,7 +34,6 @@ impl Property for ExtData {
4934

5035
fn from_true() -> Self {
5136
ExtData {
52-
legacy_safe: LegacySafe::LegacySafe,
5337
pk_cost: 1,
5438
has_verify_form: false,
5539
ops_count_static: 0,
@@ -60,7 +44,6 @@ impl Property for ExtData {
6044

6145
fn from_false() -> Self {
6246
ExtData {
63-
legacy_safe: LegacySafe::LegacySafe,
6447
pk_cost: 1,
6548
has_verify_form: false,
6649
ops_count_static: 0,
@@ -71,7 +54,6 @@ impl Property for ExtData {
7154

7255
fn from_pk_k() -> Self {
7356
ExtData {
74-
legacy_safe: LegacySafe::LegacySafe,
7557
pk_cost: 34,
7658
has_verify_form: false,
7759
ops_count_static: 0,
@@ -82,7 +64,6 @@ impl Property for ExtData {
8264

8365
fn from_pk_h() -> Self {
8466
ExtData {
85-
legacy_safe: LegacySafe::SegwitOnly,
8667
pk_cost: 24,
8768
has_verify_form: false,
8869
ops_count_static: 3,
@@ -99,7 +80,6 @@ impl Property for ExtData {
9980
(false, false) => 2,
10081
};
10182
ExtData {
102-
legacy_safe: LegacySafe::LegacySafe,
10383
pk_cost: num_cost + 34 * n + 1,
10484
has_verify_form: true,
10585
ops_count_static: 1,
@@ -115,7 +95,6 @@ impl Property for ExtData {
11595

11696
fn from_sha256() -> Self {
11797
ExtData {
118-
legacy_safe: LegacySafe::LegacySafe,
11998
pk_cost: 33 + 6,
12099
has_verify_form: true,
121100
ops_count_static: 4,
@@ -126,7 +105,6 @@ impl Property for ExtData {
126105

127106
fn from_hash256() -> Self {
128107
ExtData {
129-
legacy_safe: LegacySafe::LegacySafe,
130108
pk_cost: 33 + 6,
131109
has_verify_form: true,
132110
ops_count_static: 4,
@@ -137,7 +115,6 @@ impl Property for ExtData {
137115

138116
fn from_ripemd160() -> Self {
139117
ExtData {
140-
legacy_safe: LegacySafe::LegacySafe,
141118
pk_cost: 21 + 6,
142119
has_verify_form: true,
143120
ops_count_static: 4,
@@ -148,7 +125,6 @@ impl Property for ExtData {
148125

149126
fn from_hash160() -> Self {
150127
ExtData {
151-
legacy_safe: LegacySafe::LegacySafe,
152128
pk_cost: 21 + 6,
153129
has_verify_form: true,
154130
ops_count_static: 4,
@@ -159,7 +135,6 @@ impl Property for ExtData {
159135

160136
fn from_time(t: u32) -> Self {
161137
ExtData {
162-
legacy_safe: LegacySafe::LegacySafe,
163138
pk_cost: script_num_size(t as usize) + 1,
164139
has_verify_form: false,
165140
ops_count_static: 1,
@@ -169,7 +144,6 @@ impl Property for ExtData {
169144
}
170145
fn cast_alt(self) -> Result<Self, ErrorKind> {
171146
Ok(ExtData {
172-
legacy_safe: self.legacy_safe,
173147
pk_cost: self.pk_cost + 2,
174148
has_verify_form: false,
175149
ops_count_static: self.ops_count_static + 2,
@@ -180,7 +154,6 @@ impl Property for ExtData {
180154

181155
fn cast_swap(self) -> Result<Self, ErrorKind> {
182156
Ok(ExtData {
183-
legacy_safe: self.legacy_safe,
184157
pk_cost: self.pk_cost + 1,
185158
has_verify_form: self.has_verify_form,
186159
ops_count_static: self.ops_count_static + 1,
@@ -191,7 +164,6 @@ impl Property for ExtData {
191164

192165
fn cast_check(self) -> Result<Self, ErrorKind> {
193166
Ok(ExtData {
194-
legacy_safe: self.legacy_safe,
195167
pk_cost: self.pk_cost + 1,
196168
has_verify_form: true,
197169
ops_count_static: self.ops_count_static + 1,
@@ -202,7 +174,6 @@ impl Property for ExtData {
202174

203175
fn cast_dupif(self) -> Result<Self, ErrorKind> {
204176
Ok(ExtData {
205-
legacy_safe: LegacySafe::SegwitOnly,
206177
pk_cost: self.pk_cost + 3,
207178
has_verify_form: false,
208179
ops_count_static: self.ops_count_static + 3,
@@ -214,7 +185,6 @@ impl Property for ExtData {
214185
fn cast_verify(self) -> Result<Self, ErrorKind> {
215186
let verify_cost = if self.has_verify_form { 0 } else { 1 };
216187
Ok(ExtData {
217-
legacy_safe: self.legacy_safe,
218188
pk_cost: self.pk_cost + if self.has_verify_form { 0 } else { 1 },
219189
has_verify_form: false,
220190
ops_count_static: self.ops_count_static + verify_cost,
@@ -225,7 +195,6 @@ impl Property for ExtData {
225195

226196
fn cast_nonzero(self) -> Result<Self, ErrorKind> {
227197
Ok(ExtData {
228-
legacy_safe: self.legacy_safe,
229198
pk_cost: self.pk_cost + 4,
230199
has_verify_form: false,
231200
ops_count_static: self.ops_count_static + 4,
@@ -236,7 +205,6 @@ impl Property for ExtData {
236205

237206
fn cast_zeronotequal(self) -> Result<Self, ErrorKind> {
238207
Ok(ExtData {
239-
legacy_safe: self.legacy_safe,
240208
pk_cost: self.pk_cost + 1,
241209
has_verify_form: false,
242210
ops_count_static: self.ops_count_static + 1,
@@ -247,7 +215,6 @@ impl Property for ExtData {
247215

248216
fn cast_true(self) -> Result<Self, ErrorKind> {
249217
Ok(ExtData {
250-
legacy_safe: self.legacy_safe,
251218
pk_cost: self.pk_cost + 1,
252219
has_verify_form: false,
253220
ops_count_static: self.ops_count_static,
@@ -263,7 +230,6 @@ impl Property for ExtData {
263230

264231
fn cast_unlikely(self) -> Result<Self, ErrorKind> {
265232
Ok(ExtData {
266-
legacy_safe: self.legacy_safe,
267233
pk_cost: self.pk_cost + 4,
268234
has_verify_form: false,
269235
ops_count_static: self.ops_count_static + 3,
@@ -274,7 +240,6 @@ impl Property for ExtData {
274240

275241
fn cast_likely(self) -> Result<Self, ErrorKind> {
276242
Ok(ExtData {
277-
legacy_safe: self.legacy_safe,
278243
pk_cost: self.pk_cost + 4,
279244
has_verify_form: false,
280245
ops_count_static: self.ops_count_static + 3,
@@ -285,7 +250,6 @@ impl Property for ExtData {
285250

286251
fn and_b(l: Self, r: Self) -> Result<Self, ErrorKind> {
287252
Ok(ExtData {
288-
legacy_safe: legacy_safe2(l.legacy_safe, r.legacy_safe),
289253
pk_cost: l.pk_cost + r.pk_cost + 1,
290254
has_verify_form: false,
291255
ops_count_static: l.ops_count_static + r.ops_count_static + 1,
@@ -300,7 +264,6 @@ impl Property for ExtData {
300264

301265
fn and_v(l: Self, r: Self) -> Result<Self, ErrorKind> {
302266
Ok(ExtData {
303-
legacy_safe: legacy_safe2(l.legacy_safe, r.legacy_safe),
304267
pk_cost: l.pk_cost + r.pk_cost,
305268
has_verify_form: r.has_verify_form,
306269
ops_count_static: l.ops_count_static + r.ops_count_static,
@@ -311,7 +274,6 @@ impl Property for ExtData {
311274

312275
fn or_b(l: Self, r: Self) -> Result<Self, ErrorKind> {
313276
Ok(ExtData {
314-
legacy_safe: legacy_safe2(l.legacy_safe, r.legacy_safe),
315277
pk_cost: l.pk_cost + r.pk_cost + 1,
316278
has_verify_form: false,
317279
ops_count_static: l.ops_count_static + r.ops_count_static + 1,
@@ -329,7 +291,6 @@ impl Property for ExtData {
329291

330292
fn or_d(l: Self, r: Self) -> Result<Self, ErrorKind> {
331293
Ok(ExtData {
332-
legacy_safe: LegacySafe::SegwitOnly,
333294
pk_cost: l.pk_cost + r.pk_cost + 3,
334295
has_verify_form: false,
335296
ops_count_static: l.ops_count_static + r.ops_count_static + 1,
@@ -346,7 +307,6 @@ impl Property for ExtData {
346307

347308
fn or_c(l: Self, r: Self) -> Result<Self, ErrorKind> {
348309
Ok(ExtData {
349-
legacy_safe: legacy_safe2(l.legacy_safe, r.legacy_safe),
350310
pk_cost: l.pk_cost + r.pk_cost + 2,
351311
has_verify_form: false,
352312
ops_count_static: l.ops_count_static + r.ops_count_static + 2,
@@ -361,7 +321,6 @@ impl Property for ExtData {
361321

362322
fn or_i(l: Self, r: Self) -> Result<Self, ErrorKind> {
363323
Ok(ExtData {
364-
legacy_safe: legacy_safe2(l.legacy_safe, r.legacy_safe),
365324
pk_cost: l.pk_cost + r.pk_cost + 3,
366325
has_verify_form: false,
367326
ops_count_static: l.ops_count_static + r.ops_count_static + 3,
@@ -379,7 +338,6 @@ impl Property for ExtData {
379338

380339
fn and_or(a: Self, b: Self, c: Self) -> Result<Self, ErrorKind> {
381340
Ok(ExtData {
382-
legacy_safe: legacy_safe2(legacy_safe2(a.legacy_safe, b.legacy_safe), c.legacy_safe),
383341
pk_cost: a.pk_cost + b.pk_cost + c.pk_cost + 3,
384342
has_verify_form: false,
385343
ops_count_static: a.ops_count_static + b.ops_count_static + c.ops_count_static + 3,
@@ -400,7 +358,6 @@ impl Property for ExtData {
400358
S: FnMut(usize) -> Result<Self, ErrorKind>,
401359
{
402360
let mut pk_cost = 1 + script_num_size(k); //Equal and k
403-
let mut legacy_safe = LegacySafe::LegacySafe;
404361
let mut ops_count_static = 0 as usize;
405362
let mut ops_count_sat_vec = Vec::with_capacity(n);
406363
let mut ops_count_nsat_sum = 0 as usize;
@@ -424,7 +381,6 @@ impl Property for ExtData {
424381
}
425382
_ => {}
426383
}
427-
legacy_safe = legacy_safe2(legacy_safe, sub.legacy_safe);
428384
}
429385
let remaining_sat = k - sat_count;
430386
let mut sum: i32 = 0;
@@ -440,7 +396,6 @@ impl Property for ExtData {
440396
.sum();
441397
}
442398
Ok(ExtData {
443-
legacy_safe: legacy_safe,
444399
pk_cost: pk_cost + n - 1, //all pk cost + (n-1)*ADD
445400
has_verify_form: true,
446401
ops_count_static: ops_count_static + (n - 1) + 1, //adds and equal
@@ -582,10 +537,3 @@ impl Property for ExtData {
582537
ret
583538
}
584539
}
585-
586-
fn legacy_safe2(a: LegacySafe, b: LegacySafe) -> LegacySafe {
587-
match (a, b) {
588-
(LegacySafe::LegacySafe, LegacySafe::LegacySafe) => LegacySafe::LegacySafe,
589-
_ => LegacySafe::SegwitOnly,
590-
}
591-
}

0 commit comments

Comments
 (0)