1#![allow(non_camel_case_types)]
22
23#[cfg(feature = "serde")] use serde;
24
25#[cfg(feature = "serde")] use prelude::*;
26
27use core::{fmt, convert::From};
28
29#[derive(Copy, Clone, PartialEq, Eq)]
35pub struct All {
36 code: u8,
37}
38
39pub mod all {
40 use super::All;
42
43 pub const OP_PUSHBYTES_0: All = All {code: 0x00};
45 pub const OP_PUSHBYTES_1: All = All {code: 0x01};
47 pub const OP_PUSHBYTES_2: All = All {code: 0x02};
49 pub const OP_PUSHBYTES_3: All = All {code: 0x03};
51 pub const OP_PUSHBYTES_4: All = All {code: 0x04};
53 pub const OP_PUSHBYTES_5: All = All {code: 0x05};
55 pub const OP_PUSHBYTES_6: All = All {code: 0x06};
57 pub const OP_PUSHBYTES_7: All = All {code: 0x07};
59 pub const OP_PUSHBYTES_8: All = All {code: 0x08};
61 pub const OP_PUSHBYTES_9: All = All {code: 0x09};
63 pub const OP_PUSHBYTES_10: All = All {code: 0x0a};
65 pub const OP_PUSHBYTES_11: All = All {code: 0x0b};
67 pub const OP_PUSHBYTES_12: All = All {code: 0x0c};
69 pub const OP_PUSHBYTES_13: All = All {code: 0x0d};
71 pub const OP_PUSHBYTES_14: All = All {code: 0x0e};
73 pub const OP_PUSHBYTES_15: All = All {code: 0x0f};
75 pub const OP_PUSHBYTES_16: All = All {code: 0x10};
77 pub const OP_PUSHBYTES_17: All = All {code: 0x11};
79 pub const OP_PUSHBYTES_18: All = All {code: 0x12};
81 pub const OP_PUSHBYTES_19: All = All {code: 0x13};
83 pub const OP_PUSHBYTES_20: All = All {code: 0x14};
85 pub const OP_PUSHBYTES_21: All = All {code: 0x15};
87 pub const OP_PUSHBYTES_22: All = All {code: 0x16};
89 pub const OP_PUSHBYTES_23: All = All {code: 0x17};
91 pub const OP_PUSHBYTES_24: All = All {code: 0x18};
93 pub const OP_PUSHBYTES_25: All = All {code: 0x19};
95 pub const OP_PUSHBYTES_26: All = All {code: 0x1a};
97 pub const OP_PUSHBYTES_27: All = All {code: 0x1b};
99 pub const OP_PUSHBYTES_28: All = All {code: 0x1c};
101 pub const OP_PUSHBYTES_29: All = All {code: 0x1d};
103 pub const OP_PUSHBYTES_30: All = All {code: 0x1e};
105 pub const OP_PUSHBYTES_31: All = All {code: 0x1f};
107 pub const OP_PUSHBYTES_32: All = All {code: 0x20};
109 pub const OP_PUSHBYTES_33: All = All {code: 0x21};
111 pub const OP_PUSHBYTES_34: All = All {code: 0x22};
113 pub const OP_PUSHBYTES_35: All = All {code: 0x23};
115 pub const OP_PUSHBYTES_36: All = All {code: 0x24};
117 pub const OP_PUSHBYTES_37: All = All {code: 0x25};
119 pub const OP_PUSHBYTES_38: All = All {code: 0x26};
121 pub const OP_PUSHBYTES_39: All = All {code: 0x27};
123 pub const OP_PUSHBYTES_40: All = All {code: 0x28};
125 pub const OP_PUSHBYTES_41: All = All {code: 0x29};
127 pub const OP_PUSHBYTES_42: All = All {code: 0x2a};
129 pub const OP_PUSHBYTES_43: All = All {code: 0x2b};
131 pub const OP_PUSHBYTES_44: All = All {code: 0x2c};
133 pub const OP_PUSHBYTES_45: All = All {code: 0x2d};
135 pub const OP_PUSHBYTES_46: All = All {code: 0x2e};
137 pub const OP_PUSHBYTES_47: All = All {code: 0x2f};
139 pub const OP_PUSHBYTES_48: All = All {code: 0x30};
141 pub const OP_PUSHBYTES_49: All = All {code: 0x31};
143 pub const OP_PUSHBYTES_50: All = All {code: 0x32};
145 pub const OP_PUSHBYTES_51: All = All {code: 0x33};
147 pub const OP_PUSHBYTES_52: All = All {code: 0x34};
149 pub const OP_PUSHBYTES_53: All = All {code: 0x35};
151 pub const OP_PUSHBYTES_54: All = All {code: 0x36};
153 pub const OP_PUSHBYTES_55: All = All {code: 0x37};
155 pub const OP_PUSHBYTES_56: All = All {code: 0x38};
157 pub const OP_PUSHBYTES_57: All = All {code: 0x39};
159 pub const OP_PUSHBYTES_58: All = All {code: 0x3a};
161 pub const OP_PUSHBYTES_59: All = All {code: 0x3b};
163 pub const OP_PUSHBYTES_60: All = All {code: 0x3c};
165 pub const OP_PUSHBYTES_61: All = All {code: 0x3d};
167 pub const OP_PUSHBYTES_62: All = All {code: 0x3e};
169 pub const OP_PUSHBYTES_63: All = All {code: 0x3f};
171 pub const OP_PUSHBYTES_64: All = All {code: 0x40};
173 pub const OP_PUSHBYTES_65: All = All {code: 0x41};
175 pub const OP_PUSHBYTES_66: All = All {code: 0x42};
177 pub const OP_PUSHBYTES_67: All = All {code: 0x43};
179 pub const OP_PUSHBYTES_68: All = All {code: 0x44};
181 pub const OP_PUSHBYTES_69: All = All {code: 0x45};
183 pub const OP_PUSHBYTES_70: All = All {code: 0x46};
185 pub const OP_PUSHBYTES_71: All = All {code: 0x47};
187 pub const OP_PUSHBYTES_72: All = All {code: 0x48};
189 pub const OP_PUSHBYTES_73: All = All {code: 0x49};
191 pub const OP_PUSHBYTES_74: All = All {code: 0x4a};
193 pub const OP_PUSHBYTES_75: All = All {code: 0x4b};
195 pub const OP_PUSHDATA1: All = All {code: 0x4c};
197 pub const OP_PUSHDATA2: All = All {code: 0x4d};
199 pub const OP_PUSHDATA4: All = All {code: 0x4e};
201 pub const OP_PUSHNUM_NEG1: All = All {code: 0x4f};
203 pub const OP_RESERVED: All = All {code: 0x50};
205 pub const OP_PUSHNUM_1: All = All {code: 0x51};
207 pub const OP_PUSHNUM_2: All = All {code: 0x52};
209 pub const OP_PUSHNUM_3: All = All {code: 0x53};
211 pub const OP_PUSHNUM_4: All = All {code: 0x54};
213 pub const OP_PUSHNUM_5: All = All {code: 0x55};
215 pub const OP_PUSHNUM_6: All = All {code: 0x56};
217 pub const OP_PUSHNUM_7: All = All {code: 0x57};
219 pub const OP_PUSHNUM_8: All = All {code: 0x58};
221 pub const OP_PUSHNUM_9: All = All {code: 0x59};
223 pub const OP_PUSHNUM_10: All = All {code: 0x5a};
225 pub const OP_PUSHNUM_11: All = All {code: 0x5b};
227 pub const OP_PUSHNUM_12: All = All {code: 0x5c};
229 pub const OP_PUSHNUM_13: All = All {code: 0x5d};
231 pub const OP_PUSHNUM_14: All = All {code: 0x5e};
233 pub const OP_PUSHNUM_15: All = All {code: 0x5f};
235 pub const OP_PUSHNUM_16: All = All {code: 0x60};
237 pub const OP_NOP: All = All {code: 0x61};
239 pub const OP_VER: All = All {code: 0x62};
241 pub const OP_IF: All = All {code: 0x63};
243 pub const OP_NOTIF: All = All {code: 0x64};
245 pub const OP_VERIF: All = All {code: 0x65};
247 pub const OP_VERNOTIF: All = All {code: 0x66};
249 pub const OP_ELSE: All = All {code: 0x67};
252 pub const OP_ENDIF: All = All {code: 0x68};
254 pub const OP_VERIFY: All = All {code: 0x69};
256 pub const OP_RETURN: All = All {code: 0x6a};
258 pub const OP_TOALTSTACK: All = All {code: 0x6b};
260 pub const OP_FROMALTSTACK: All = All {code: 0x6c};
262 pub const OP_2DROP: All = All {code: 0x6d};
264 pub const OP_2DUP: All = All {code: 0x6e};
266 pub const OP_3DUP: All = All {code: 0x6f};
268 pub const OP_2OVER: All = All {code: 0x70};
271 pub const OP_2ROT: All = All {code: 0x71};
274 pub const OP_2SWAP: All = All {code: 0x72};
276 pub const OP_IFDUP: All = All {code: 0x73};
278 pub const OP_DEPTH: All = All {code: 0x74};
280 pub const OP_DROP: All = All {code: 0x75};
282 pub const OP_DUP: All = All {code: 0x76};
284 pub const OP_NIP: All = All {code: 0x77};
286 pub const OP_OVER: All = All {code: 0x78};
288 pub const OP_PICK: All = All {code: 0x79};
290 pub const OP_ROLL: All = All {code: 0x7a};
292 pub const OP_ROT: All = All {code: 0x7b};
294 pub const OP_SWAP: All = All {code: 0x7c};
296 pub const OP_TUCK: All = All {code: 0x7d};
298 pub const OP_CAT: All = All {code: 0x7e};
300 pub const OP_SUBSTR: All = All {code: 0x7f};
302 pub const OP_LEFT: All = All {code: 0x80};
304 pub const OP_RIGHT: All = All {code: 0x81};
306 pub const OP_SIZE: All = All {code: 0x82};
308 pub const OP_INVERT: All = All {code: 0x83};
310 pub const OP_AND: All = All {code: 0x84};
312 pub const OP_OR: All = All {code: 0x85};
314 pub const OP_XOR: All = All {code: 0x86};
316 pub const OP_EQUAL: All = All {code: 0x87};
318 pub const OP_EQUALVERIFY: All = All {code: 0x88};
320 pub const OP_RESERVED1: All = All {code: 0x89};
322 pub const OP_RESERVED2: All = All {code: 0x8a};
324 pub const OP_1ADD: All = All {code: 0x8b};
326 pub const OP_1SUB: All = All {code: 0x8c};
328 pub const OP_2MUL: All = All {code: 0x8d};
330 pub const OP_2DIV: All = All {code: 0x8e};
332 pub const OP_NEGATE: All = All {code: 0x8f};
334 pub const OP_ABS: All = All {code: 0x90};
336 pub const OP_NOT: All = All {code: 0x91};
338 pub const OP_0NOTEQUAL: All = All {code: 0x92};
340 pub const OP_ADD: All = All {code: 0x93};
342 pub const OP_SUB: All = All {code: 0x94};
344 pub const OP_MUL: All = All {code: 0x95};
346 pub const OP_DIV: All = All {code: 0x96};
348 pub const OP_MOD: All = All {code: 0x97};
350 pub const OP_LSHIFT: All = All {code: 0x98};
352 pub const OP_RSHIFT: All = All {code: 0x99};
354 pub const OP_BOOLAND: All = All {code: 0x9a};
356 pub const OP_BOOLOR: All = All {code: 0x9b};
358 pub const OP_NUMEQUAL: All = All {code: 0x9c};
360 pub const OP_NUMEQUALVERIFY: All = All {code: 0x9d};
362 pub const OP_NUMNOTEQUAL: All = All {code: 0x9e};
364 pub const OP_LESSTHAN : All = All {code: 0x9f};
366 pub const OP_GREATERTHAN : All = All {code: 0xa0};
368 pub const OP_LESSTHANOREQUAL : All = All {code: 0xa1};
370 pub const OP_GREATERTHANOREQUAL : All = All {code: 0xa2};
372 pub const OP_MIN: All = All {code: 0xa3};
374 pub const OP_MAX: All = All {code: 0xa4};
376 pub const OP_WITHIN: All = All {code: 0xa5};
378 pub const OP_RIPEMD160: All = All {code: 0xa6};
380 pub const OP_SHA1: All = All {code: 0xa7};
382 pub const OP_SHA256: All = All {code: 0xa8};
384 pub const OP_HASH160: All = All {code: 0xa9};
386 pub const OP_HASH256: All = All {code: 0xaa};
388 pub const OP_CODESEPARATOR: All = All {code: 0xab};
390 pub const OP_CHECKSIG: All = All {code: 0xac};
392 pub const OP_CHECKSIGVERIFY: All = All {code: 0xad};
394 pub const OP_CHECKMULTISIG: All = All {code: 0xae};
397 pub const OP_CHECKMULTISIGVERIFY: All = All {code: 0xaf};
399 pub const OP_NOP1: All = All {code: 0xb0};
401 pub const OP_CLTV: All = All {code: 0xb1};
403 pub const OP_CSV: All = All {code: 0xb2};
405 pub const OP_NOP4: All = All {code: 0xb3};
407 pub const OP_NOP5: All = All {code: 0xb4};
409 pub const OP_NOP6: All = All {code: 0xb5};
411 pub const OP_NOP7: All = All {code: 0xb6};
413 pub const OP_NOP8: All = All {code: 0xb7};
415 pub const OP_NOP9: All = All {code: 0xb8};
417 pub const OP_NOP10: All = All {code: 0xb9};
419 pub const OP_CHECKSIGADD: All = All {code: 0xba};
422 pub const OP_RETURN_187: All = All {code: 0xbb};
424 pub const OP_RETURN_188: All = All {code: 0xbc};
426 pub const OP_RETURN_189: All = All {code: 0xbd};
428 pub const OP_RETURN_190: All = All {code: 0xbe};
430 pub const OP_RETURN_191: All = All {code: 0xbf};
432 pub const OP_RETURN_192: All = All {code: 0xc0};
434 pub const OP_RETURN_193: All = All {code: 0xc1};
436 pub const OP_RETURN_194: All = All {code: 0xc2};
438 pub const OP_RETURN_195: All = All {code: 0xc3};
440 pub const OP_RETURN_196: All = All {code: 0xc4};
442 pub const OP_RETURN_197: All = All {code: 0xc5};
444 pub const OP_RETURN_198: All = All {code: 0xc6};
446 pub const OP_RETURN_199: All = All {code: 0xc7};
448 pub const OP_RETURN_200: All = All {code: 0xc8};
450 pub const OP_RETURN_201: All = All {code: 0xc9};
452 pub const OP_RETURN_202: All = All {code: 0xca};
454 pub const OP_RETURN_203: All = All {code: 0xcb};
456 pub const OP_RETURN_204: All = All {code: 0xcc};
458 pub const OP_RETURN_205: All = All {code: 0xcd};
460 pub const OP_RETURN_206: All = All {code: 0xce};
462 pub const OP_RETURN_207: All = All {code: 0xcf};
464 pub const OP_RETURN_208: All = All {code: 0xd0};
466 pub const OP_RETURN_209: All = All {code: 0xd1};
468 pub const OP_RETURN_210: All = All {code: 0xd2};
470 pub const OP_RETURN_211: All = All {code: 0xd3};
472 pub const OP_RETURN_212: All = All {code: 0xd4};
474 pub const OP_RETURN_213: All = All {code: 0xd5};
476 pub const OP_RETURN_214: All = All {code: 0xd6};
478 pub const OP_RETURN_215: All = All {code: 0xd7};
480 pub const OP_RETURN_216: All = All {code: 0xd8};
482 pub const OP_RETURN_217: All = All {code: 0xd9};
484 pub const OP_RETURN_218: All = All {code: 0xda};
486 pub const OP_RETURN_219: All = All {code: 0xdb};
488 pub const OP_RETURN_220: All = All {code: 0xdc};
490 pub const OP_RETURN_221: All = All {code: 0xdd};
492 pub const OP_RETURN_222: All = All {code: 0xde};
494 pub const OP_RETURN_223: All = All {code: 0xdf};
496 pub const OP_RETURN_224: All = All {code: 0xe0};
498 pub const OP_RETURN_225: All = All {code: 0xe1};
500 pub const OP_RETURN_226: All = All {code: 0xe2};
502 pub const OP_RETURN_227: All = All {code: 0xe3};
504 pub const OP_RETURN_228: All = All {code: 0xe4};
506 pub const OP_RETURN_229: All = All {code: 0xe5};
508 pub const OP_RETURN_230: All = All {code: 0xe6};
510 pub const OP_RETURN_231: All = All {code: 0xe7};
512 pub const OP_RETURN_232: All = All {code: 0xe8};
514 pub const OP_RETURN_233: All = All {code: 0xe9};
516 pub const OP_RETURN_234: All = All {code: 0xea};
518 pub const OP_RETURN_235: All = All {code: 0xeb};
520 pub const OP_RETURN_236: All = All {code: 0xec};
522 pub const OP_RETURN_237: All = All {code: 0xed};
524 pub const OP_RETURN_238: All = All {code: 0xee};
526 pub const OP_RETURN_239: All = All {code: 0xef};
528 pub const OP_RETURN_240: All = All {code: 0xf0};
530 pub const OP_RETURN_241: All = All {code: 0xf1};
532 pub const OP_RETURN_242: All = All {code: 0xf2};
534 pub const OP_RETURN_243: All = All {code: 0xf3};
536 pub const OP_RETURN_244: All = All {code: 0xf4};
538 pub const OP_RETURN_245: All = All {code: 0xf5};
540 pub const OP_RETURN_246: All = All {code: 0xf6};
542 pub const OP_RETURN_247: All = All {code: 0xf7};
544 pub const OP_RETURN_248: All = All {code: 0xf8};
546 pub const OP_RETURN_249: All = All {code: 0xf9};
548 pub const OP_RETURN_250: All = All {code: 0xfa};
550 pub const OP_RETURN_251: All = All {code: 0xfb};
552 pub const OP_RETURN_252: All = All {code: 0xfc};
554 pub const OP_RETURN_253: All = All {code: 0xfd};
556 pub const OP_RETURN_254: All = All {code: 0xfe};
558 pub const OP_INVALIDOPCODE: All = All {code: 0xff};
560}
561
562impl fmt::Debug for All {
563 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
564 f.write_str("OP_")?;
565 match *self {
566 All {code: x} if x <= 75 => write!(f, "PUSHBYTES_{}", self.code),
567 all::OP_PUSHDATA1 => write!(f, "PUSHDATA1"),
568 all::OP_PUSHDATA2 => write!(f, "PUSHDATA2"),
569 all::OP_PUSHDATA4 => write!(f, "PUSHDATA4"),
570 all::OP_PUSHNUM_NEG1 => write!(f, "PUSHNUM_NEG1"),
571 all::OP_RESERVED => write!(f, "RESERVED"),
572 All {code: x} if x >= all::OP_PUSHNUM_1.code && x <= all::OP_PUSHNUM_16.code => write!(f, "PUSHNUM_{}", x - all::OP_PUSHNUM_1.code + 1),
573 all::OP_NOP => write!(f, "NOP"),
574 all::OP_VER => write!(f, "VER"),
575 all::OP_IF => write!(f, "IF"),
576 all::OP_NOTIF => write!(f, "NOTIF"),
577 all::OP_VERIF => write!(f, "VERIF"),
578 all::OP_VERNOTIF => write!(f, "VERNOTIF"),
579 all::OP_ELSE => write!(f, "ELSE"),
580 all::OP_ENDIF => write!(f, "ENDIF"),
581 all::OP_VERIFY => write!(f, "VERIFY"),
582 all::OP_RETURN => write!(f, "RETURN"),
583 all::OP_TOALTSTACK => write!(f, "TOALTSTACK"),
584 all::OP_FROMALTSTACK => write!(f, "FROMALTSTACK"),
585 all::OP_2DROP => write!(f, "2DROP"),
586 all::OP_2DUP => write!(f, "2DUP"),
587 all::OP_3DUP => write!(f, "3DUP"),
588 all::OP_2OVER => write!(f, "2OVER"),
589 all::OP_2ROT => write!(f, "2ROT"),
590 all::OP_2SWAP => write!(f, "2SWAP"),
591 all::OP_IFDUP => write!(f, "IFDUP"),
592 all::OP_DEPTH => write!(f, "DEPTH"),
593 all::OP_DROP => write!(f, "DROP"),
594 all::OP_DUP => write!(f, "DUP"),
595 all::OP_NIP => write!(f, "NIP"),
596 all::OP_OVER => write!(f, "OVER"),
597 all::OP_PICK => write!(f, "PICK"),
598 all::OP_ROLL => write!(f, "ROLL"),
599 all::OP_ROT => write!(f, "ROT"),
600 all::OP_SWAP => write!(f, "SWAP"),
601 all::OP_TUCK => write!(f, "TUCK"),
602 all::OP_CAT => write!(f, "CAT"),
603 all::OP_SUBSTR => write!(f, "SUBSTR"),
604 all::OP_LEFT => write!(f, "LEFT"),
605 all::OP_RIGHT => write!(f, "RIGHT"),
606 all::OP_SIZE => write!(f, "SIZE"),
607 all::OP_INVERT => write!(f, "INVERT"),
608 all::OP_AND => write!(f, "AND"),
609 all::OP_OR => write!(f, "OR"),
610 all::OP_XOR => write!(f, "XOR"),
611 all::OP_EQUAL => write!(f, "EQUAL"),
612 all::OP_EQUALVERIFY => write!(f, "EQUALVERIFY"),
613 all::OP_RESERVED1 => write!(f, "RESERVED1"),
614 all::OP_RESERVED2 => write!(f, "RESERVED2"),
615 all::OP_1ADD => write!(f, "1ADD"),
616 all::OP_1SUB => write!(f, "1SUB"),
617 all::OP_2MUL => write!(f, "2MUL"),
618 all::OP_2DIV => write!(f, "2DIV"),
619 all::OP_NEGATE => write!(f, "NEGATE"),
620 all::OP_ABS => write!(f, "ABS"),
621 all::OP_NOT => write!(f, "NOT"),
622 all::OP_0NOTEQUAL => write!(f, "0NOTEQUAL"),
623 all::OP_ADD => write!(f, "ADD"),
624 all::OP_SUB => write!(f, "SUB"),
625 all::OP_MUL => write!(f, "MUL"),
626 all::OP_DIV => write!(f, "DIV"),
627 all::OP_MOD => write!(f, "MOD"),
628 all::OP_LSHIFT => write!(f, "LSHIFT"),
629 all::OP_RSHIFT => write!(f, "RSHIFT"),
630 all::OP_BOOLAND => write!(f, "BOOLAND"),
631 all::OP_BOOLOR => write!(f, "BOOLOR"),
632 all::OP_NUMEQUAL => write!(f, "NUMEQUAL"),
633 all::OP_NUMEQUALVERIFY => write!(f, "NUMEQUALVERIFY"),
634 all::OP_NUMNOTEQUAL => write!(f, "NUMNOTEQUAL"),
635 all::OP_LESSTHAN => write!(f, "LESSTHAN"),
636 all::OP_GREATERTHAN => write!(f, "GREATERTHAN"),
637 all::OP_LESSTHANOREQUAL => write!(f, "LESSTHANOREQUAL"),
638 all::OP_GREATERTHANOREQUAL => write!(f, "GREATERTHANOREQUAL"),
639 all::OP_MIN => write!(f, "MIN"),
640 all::OP_MAX => write!(f, "MAX"),
641 all::OP_WITHIN => write!(f, "WITHIN"),
642 all::OP_RIPEMD160 => write!(f, "RIPEMD160"),
643 all::OP_SHA1 => write!(f, "SHA1"),
644 all::OP_SHA256 => write!(f, "SHA256"),
645 all::OP_HASH160 => write!(f, "HASH160"),
646 all::OP_HASH256 => write!(f, "HASH256"),
647 all::OP_CODESEPARATOR => write!(f, "CODESEPARATOR"),
648 all::OP_CHECKSIG => write!(f, "CHECKSIG"),
649 all::OP_CHECKSIGVERIFY => write!(f, "CHECKSIGVERIFY"),
650 all::OP_CHECKMULTISIG => write!(f, "CHECKMULTISIG"),
651 all::OP_CHECKMULTISIGVERIFY => write!(f, "CHECKMULTISIGVERIFY"),
652 all::OP_CLTV => write!(f, "CLTV"),
653 all::OP_CSV => write!(f, "CSV"),
654 All {code: x} if x >= all::OP_NOP1.code && x <= all::OP_NOP10.code => write!(f, "NOP{}", x - all::OP_NOP1.code + 1),
655 all::OP_INVALIDOPCODE => write!(f, "INVALIDOPCODE"),
656 all::OP_CHECKSIGADD => write!(f, "CHECKSIGADD"),
657 All {code: x} => write!(f, "RETURN_{}", x),
658 }
659 }
660}
661
662#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
667pub enum ClassifyContext {
668 TapScript,
670 Legacy,
672}
673
674impl All {
675 #[inline]
677 pub fn classify(self, ctx: ClassifyContext) -> Class {
678 use self::all::*;
679 match (self, ctx) {
680 (OP_VERIF, _) | (OP_VERNOTIF, _) | (OP_INVALIDOPCODE, _) => Class::IllegalOp,
682
683 (OP_CAT, ctx) | (OP_SUBSTR, ctx)
685 | (OP_LEFT, ctx) | (OP_RIGHT, ctx)
686 | (OP_INVERT, ctx)
687 | (OP_AND, ctx) | (OP_OR, ctx) | (OP_XOR, ctx)
688 | (OP_2MUL, ctx) | (OP_2DIV, ctx)
689 | (OP_MUL, ctx) | (OP_DIV, ctx) | (OP_MOD, ctx)
690 | (OP_LSHIFT, ctx) | (OP_RSHIFT, ctx) if ctx == ClassifyContext::Legacy => Class::IllegalOp,
691
692 (op, ClassifyContext::TapScript)
694 if op.code == 80 || op.code == 98 ||
695 (op.code >= 126 && op.code <= 129) ||
696 (op.code >= 131 && op.code <= 134) ||
697 (op.code >= 137 && op.code <= 138) ||
698 (op.code >= 141 && op.code <= 142) ||
699 (op.code >= 149 && op.code <= 153) ||
700 (op.code >= 187 && op.code <= 254) => Class::SuccessOp,
701
702 (OP_NOP, _) => Class::NoOp,
704 (op, _) if op.code >= OP_NOP1.code && op.code <= OP_NOP10.code => Class::NoOp,
705
706 (OP_RETURN, _) => Class::ReturnOp,
708
709 (OP_RESERVED, ctx)
711 | (OP_RESERVED1, ctx) | (OP_RESERVED2, ctx)
712 | (OP_VER, ctx) if ctx == ClassifyContext::Legacy => Class::ReturnOp,
713
714 (op, ClassifyContext::Legacy) if op.code >= OP_CHECKSIGADD.code => Class::ReturnOp,
716
717 (OP_CHECKMULTISIG, ClassifyContext::TapScript)
719 | (OP_CHECKMULTISIGVERIFY, ClassifyContext::TapScript) => Class::ReturnOp,
720
721 (OP_PUSHNUM_NEG1, _) => Class::PushNum(-1),
723
724 (op, _) if op.code >= OP_PUSHNUM_1.code && op.code <= OP_PUSHNUM_16.code => {
726 Class::PushNum(1 + self.code as i32 - OP_PUSHNUM_1.code as i32)
727 },
728
729 (op, _) if op.code <= OP_PUSHBYTES_75.code => Class::PushBytes(self.code as u32),
731
732 (_, _) => Class::Ordinary(Ordinary::with(self)),
734 }
735 }
736
737 #[inline]
739 pub fn into_u8(self) -> u8 {
740 self.code
741 }
742}
743
744impl From<u8> for All {
745 #[inline]
746 fn from(b: u8) -> All {
747 All {code: b}
748 }
749}
750
751display_from_debug!(All);
752
753#[cfg(feature = "serde")]
754#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
755impl serde::Serialize for All {
756 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
757 where
758 S: serde::Serializer,
759 {
760 serializer.serialize_str(&self.to_string())
761 }
762}
763
764pub static OP_FALSE: All = all::OP_PUSHBYTES_0;
766pub static OP_TRUE: All = all::OP_PUSHNUM_1;
768pub static OP_NOP2: All = all::OP_CLTV;
770pub static OP_NOP3: All = all::OP_CSV;
772
773#[derive(Copy, Clone, PartialEq, Eq, Debug)]
775pub enum Class {
776 PushNum(i32),
778 PushBytes(u32),
780 ReturnOp,
782 SuccessOp,
784 IllegalOp,
786 NoOp,
788 Ordinary(Ordinary)
790}
791
792display_from_debug!(Class);
793
794#[cfg(feature = "serde")]
795#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
796impl serde::Serialize for Class {
797 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
798 where
799 S: serde::Serializer,
800 {
801 serializer.serialize_str(&self.to_string())
802 }
803}
804
805macro_rules! ordinary_opcode {
806 ($($op:ident),*) => (
807 #[repr(u8)]
808 #[doc(hidden)]
809 #[derive(Copy, Clone, PartialEq, Eq, Debug)]
810 pub enum Ordinary {
811 $( $op = all::$op.code ),*
812 }
813
814 impl Ordinary {
815 fn with(b: All) -> Self {
816 match b {
817 $( all::$op => { Ordinary::$op } ),*
818 _ => unreachable!("construction of `Ordinary` type from non-ordinary opcode {}", b),
819 }
820 }
821
822 pub fn try_from_all(b: All) -> Option<Self> {
824 match b {
825 $( all::$op => { Some(Ordinary::$op) } ),*
826 _ => None,
827 }
828 }
829 }
830 );
831}
832
833ordinary_opcode! {
835 OP_PUSHDATA1, OP_PUSHDATA2, OP_PUSHDATA4,
837 OP_IF, OP_NOTIF, OP_ELSE, OP_ENDIF, OP_VERIFY,
839 OP_TOALTSTACK, OP_FROMALTSTACK,
841 OP_2DROP, OP_2DUP, OP_3DUP, OP_2OVER, OP_2ROT, OP_2SWAP,
842 OP_DROP, OP_DUP, OP_NIP, OP_OVER, OP_PICK, OP_ROLL, OP_ROT, OP_SWAP, OP_TUCK,
843 OP_IFDUP, OP_DEPTH, OP_SIZE,
844 OP_EQUAL, OP_EQUALVERIFY,
846 OP_1ADD, OP_1SUB, OP_NEGATE, OP_ABS, OP_NOT, OP_0NOTEQUAL,
848 OP_ADD, OP_SUB, OP_BOOLAND, OP_BOOLOR,
849 OP_NUMEQUAL, OP_NUMEQUALVERIFY, OP_NUMNOTEQUAL, OP_LESSTHAN,
850 OP_GREATERTHAN, OP_LESSTHANOREQUAL, OP_GREATERTHANOREQUAL,
851 OP_MIN, OP_MAX, OP_WITHIN,
852 OP_RIPEMD160, OP_SHA1, OP_SHA256, OP_HASH160, OP_HASH256,
854 OP_CODESEPARATOR, OP_CHECKSIG, OP_CHECKSIGVERIFY,
855 OP_CHECKMULTISIG, OP_CHECKMULTISIGVERIFY,
856 OP_CHECKSIGADD
857}
858
859impl Ordinary {
860 #[inline]
862 pub fn into_u8(self) -> u8 {
863 self as u8
864 }
865}
866
867#[cfg(test)]
868mod tests {
869 use std::collections::HashSet;
870
871 use super::*;
872
873 macro_rules! roundtrip {
874 ($unique:expr, $op:ident) => {
875 assert_eq!(all::$op, All::from(all::$op.into_u8()));
876
877 let s1 = format!("{}", all::$op);
878 let s2 = format!("{:?}", all::$op);
879 assert_eq!(s1, s2);
880 assert_eq!(s1, stringify!($op));
881 assert!($unique.insert(s1));
882 }
883 }
884
885 #[test]
886 fn classify_test() {
887 let op174 = all::OP_CHECKMULTISIG;
888 assert_eq!(op174.classify(ClassifyContext::Legacy), Class::Ordinary(Ordinary::OP_CHECKMULTISIG));
889 assert_eq!(op174.classify(ClassifyContext::TapScript), Class::ReturnOp);
890
891 let op175 = all::OP_CHECKMULTISIGVERIFY;
892 assert_eq!(op175.classify(ClassifyContext::Legacy), Class::Ordinary(Ordinary::OP_CHECKMULTISIGVERIFY));
893 assert_eq!(op175.classify(ClassifyContext::TapScript), Class::ReturnOp);
894
895 let op186 = all::OP_CHECKSIGADD;
896 assert_eq!(op186.classify(ClassifyContext::Legacy), Class::ReturnOp);
897 assert_eq!(op186.classify(ClassifyContext::TapScript), Class::Ordinary(Ordinary::OP_CHECKSIGADD));
898
899 let op187 = all::OP_RETURN_187;
900 assert_eq!(op187.classify(ClassifyContext::Legacy), Class::ReturnOp);
901 assert_eq!(op187.classify(ClassifyContext::TapScript), Class::SuccessOp);
902 }
903
904 #[test]
905 fn str_roundtrip() {
906 let mut unique = HashSet::new();
907 roundtrip!(unique, OP_PUSHBYTES_0);
908 roundtrip!(unique, OP_PUSHBYTES_1);
909 roundtrip!(unique, OP_PUSHBYTES_2);
910 roundtrip!(unique, OP_PUSHBYTES_3);
911 roundtrip!(unique, OP_PUSHBYTES_4);
912 roundtrip!(unique, OP_PUSHBYTES_5);
913 roundtrip!(unique, OP_PUSHBYTES_6);
914 roundtrip!(unique, OP_PUSHBYTES_7);
915 roundtrip!(unique, OP_PUSHBYTES_8);
916 roundtrip!(unique, OP_PUSHBYTES_9);
917 roundtrip!(unique, OP_PUSHBYTES_10);
918 roundtrip!(unique, OP_PUSHBYTES_11);
919 roundtrip!(unique, OP_PUSHBYTES_12);
920 roundtrip!(unique, OP_PUSHBYTES_13);
921 roundtrip!(unique, OP_PUSHBYTES_14);
922 roundtrip!(unique, OP_PUSHBYTES_15);
923 roundtrip!(unique, OP_PUSHBYTES_16);
924 roundtrip!(unique, OP_PUSHBYTES_17);
925 roundtrip!(unique, OP_PUSHBYTES_18);
926 roundtrip!(unique, OP_PUSHBYTES_19);
927 roundtrip!(unique, OP_PUSHBYTES_20);
928 roundtrip!(unique, OP_PUSHBYTES_21);
929 roundtrip!(unique, OP_PUSHBYTES_22);
930 roundtrip!(unique, OP_PUSHBYTES_23);
931 roundtrip!(unique, OP_PUSHBYTES_24);
932 roundtrip!(unique, OP_PUSHBYTES_25);
933 roundtrip!(unique, OP_PUSHBYTES_26);
934 roundtrip!(unique, OP_PUSHBYTES_27);
935 roundtrip!(unique, OP_PUSHBYTES_28);
936 roundtrip!(unique, OP_PUSHBYTES_29);
937 roundtrip!(unique, OP_PUSHBYTES_30);
938 roundtrip!(unique, OP_PUSHBYTES_31);
939 roundtrip!(unique, OP_PUSHBYTES_32);
940 roundtrip!(unique, OP_PUSHBYTES_33);
941 roundtrip!(unique, OP_PUSHBYTES_34);
942 roundtrip!(unique, OP_PUSHBYTES_35);
943 roundtrip!(unique, OP_PUSHBYTES_36);
944 roundtrip!(unique, OP_PUSHBYTES_37);
945 roundtrip!(unique, OP_PUSHBYTES_38);
946 roundtrip!(unique, OP_PUSHBYTES_39);
947 roundtrip!(unique, OP_PUSHBYTES_40);
948 roundtrip!(unique, OP_PUSHBYTES_41);
949 roundtrip!(unique, OP_PUSHBYTES_42);
950 roundtrip!(unique, OP_PUSHBYTES_43);
951 roundtrip!(unique, OP_PUSHBYTES_44);
952 roundtrip!(unique, OP_PUSHBYTES_45);
953 roundtrip!(unique, OP_PUSHBYTES_46);
954 roundtrip!(unique, OP_PUSHBYTES_47);
955 roundtrip!(unique, OP_PUSHBYTES_48);
956 roundtrip!(unique, OP_PUSHBYTES_49);
957 roundtrip!(unique, OP_PUSHBYTES_50);
958 roundtrip!(unique, OP_PUSHBYTES_51);
959 roundtrip!(unique, OP_PUSHBYTES_52);
960 roundtrip!(unique, OP_PUSHBYTES_53);
961 roundtrip!(unique, OP_PUSHBYTES_54);
962 roundtrip!(unique, OP_PUSHBYTES_55);
963 roundtrip!(unique, OP_PUSHBYTES_56);
964 roundtrip!(unique, OP_PUSHBYTES_57);
965 roundtrip!(unique, OP_PUSHBYTES_58);
966 roundtrip!(unique, OP_PUSHBYTES_59);
967 roundtrip!(unique, OP_PUSHBYTES_60);
968 roundtrip!(unique, OP_PUSHBYTES_61);
969 roundtrip!(unique, OP_PUSHBYTES_62);
970 roundtrip!(unique, OP_PUSHBYTES_63);
971 roundtrip!(unique, OP_PUSHBYTES_64);
972 roundtrip!(unique, OP_PUSHBYTES_65);
973 roundtrip!(unique, OP_PUSHBYTES_66);
974 roundtrip!(unique, OP_PUSHBYTES_67);
975 roundtrip!(unique, OP_PUSHBYTES_68);
976 roundtrip!(unique, OP_PUSHBYTES_69);
977 roundtrip!(unique, OP_PUSHBYTES_70);
978 roundtrip!(unique, OP_PUSHBYTES_71);
979 roundtrip!(unique, OP_PUSHBYTES_72);
980 roundtrip!(unique, OP_PUSHBYTES_73);
981 roundtrip!(unique, OP_PUSHBYTES_74);
982 roundtrip!(unique, OP_PUSHBYTES_75);
983 roundtrip!(unique, OP_PUSHDATA1);
984 roundtrip!(unique, OP_PUSHDATA2);
985 roundtrip!(unique, OP_PUSHDATA4);
986 roundtrip!(unique, OP_PUSHNUM_NEG1);
987 roundtrip!(unique, OP_RESERVED);
988 roundtrip!(unique, OP_PUSHNUM_1);
989 roundtrip!(unique, OP_PUSHNUM_2);
990 roundtrip!(unique, OP_PUSHNUM_3);
991 roundtrip!(unique, OP_PUSHNUM_4);
992 roundtrip!(unique, OP_PUSHNUM_5);
993 roundtrip!(unique, OP_PUSHNUM_6);
994 roundtrip!(unique, OP_PUSHNUM_7);
995 roundtrip!(unique, OP_PUSHNUM_8);
996 roundtrip!(unique, OP_PUSHNUM_9);
997 roundtrip!(unique, OP_PUSHNUM_10);
998 roundtrip!(unique, OP_PUSHNUM_11);
999 roundtrip!(unique, OP_PUSHNUM_12);
1000 roundtrip!(unique, OP_PUSHNUM_13);
1001 roundtrip!(unique, OP_PUSHNUM_14);
1002 roundtrip!(unique, OP_PUSHNUM_15);
1003 roundtrip!(unique, OP_PUSHNUM_16);
1004 roundtrip!(unique, OP_NOP);
1005 roundtrip!(unique, OP_VER);
1006 roundtrip!(unique, OP_IF);
1007 roundtrip!(unique, OP_NOTIF);
1008 roundtrip!(unique, OP_VERIF);
1009 roundtrip!(unique, OP_VERNOTIF);
1010 roundtrip!(unique, OP_ELSE);
1011 roundtrip!(unique, OP_ENDIF);
1012 roundtrip!(unique, OP_VERIFY);
1013 roundtrip!(unique, OP_RETURN);
1014 roundtrip!(unique, OP_TOALTSTACK);
1015 roundtrip!(unique, OP_FROMALTSTACK);
1016 roundtrip!(unique, OP_2DROP);
1017 roundtrip!(unique, OP_2DUP);
1018 roundtrip!(unique, OP_3DUP);
1019 roundtrip!(unique, OP_2OVER);
1020 roundtrip!(unique, OP_2ROT);
1021 roundtrip!(unique, OP_2SWAP);
1022 roundtrip!(unique, OP_IFDUP);
1023 roundtrip!(unique, OP_DEPTH);
1024 roundtrip!(unique, OP_DROP);
1025 roundtrip!(unique, OP_DUP);
1026 roundtrip!(unique, OP_NIP);
1027 roundtrip!(unique, OP_OVER);
1028 roundtrip!(unique, OP_PICK);
1029 roundtrip!(unique, OP_ROLL);
1030 roundtrip!(unique, OP_ROT);
1031 roundtrip!(unique, OP_SWAP);
1032 roundtrip!(unique, OP_TUCK);
1033 roundtrip!(unique, OP_CAT);
1034 roundtrip!(unique, OP_SUBSTR);
1035 roundtrip!(unique, OP_LEFT);
1036 roundtrip!(unique, OP_RIGHT);
1037 roundtrip!(unique, OP_SIZE);
1038 roundtrip!(unique, OP_INVERT);
1039 roundtrip!(unique, OP_AND);
1040 roundtrip!(unique, OP_OR);
1041 roundtrip!(unique, OP_XOR);
1042 roundtrip!(unique, OP_EQUAL);
1043 roundtrip!(unique, OP_EQUALVERIFY);
1044 roundtrip!(unique, OP_RESERVED1);
1045 roundtrip!(unique, OP_RESERVED2);
1046 roundtrip!(unique, OP_1ADD);
1047 roundtrip!(unique, OP_1SUB);
1048 roundtrip!(unique, OP_2MUL);
1049 roundtrip!(unique, OP_2DIV);
1050 roundtrip!(unique, OP_NEGATE);
1051 roundtrip!(unique, OP_ABS);
1052 roundtrip!(unique, OP_NOT);
1053 roundtrip!(unique, OP_0NOTEQUAL);
1054 roundtrip!(unique, OP_ADD);
1055 roundtrip!(unique, OP_SUB);
1056 roundtrip!(unique, OP_MUL);
1057 roundtrip!(unique, OP_DIV);
1058 roundtrip!(unique, OP_MOD);
1059 roundtrip!(unique, OP_LSHIFT);
1060 roundtrip!(unique, OP_RSHIFT);
1061 roundtrip!(unique, OP_BOOLAND);
1062 roundtrip!(unique, OP_BOOLOR);
1063 roundtrip!(unique, OP_NUMEQUAL);
1064 roundtrip!(unique, OP_NUMEQUALVERIFY);
1065 roundtrip!(unique, OP_NUMNOTEQUAL);
1066 roundtrip!(unique, OP_LESSTHAN );
1067 roundtrip!(unique, OP_GREATERTHAN );
1068 roundtrip!(unique, OP_LESSTHANOREQUAL );
1069 roundtrip!(unique, OP_GREATERTHANOREQUAL );
1070 roundtrip!(unique, OP_MIN);
1071 roundtrip!(unique, OP_MAX);
1072 roundtrip!(unique, OP_WITHIN);
1073 roundtrip!(unique, OP_RIPEMD160);
1074 roundtrip!(unique, OP_SHA1);
1075 roundtrip!(unique, OP_SHA256);
1076 roundtrip!(unique, OP_HASH160);
1077 roundtrip!(unique, OP_HASH256);
1078 roundtrip!(unique, OP_CODESEPARATOR);
1079 roundtrip!(unique, OP_CHECKSIG);
1080 roundtrip!(unique, OP_CHECKSIGVERIFY);
1081 roundtrip!(unique, OP_CHECKMULTISIG);
1082 roundtrip!(unique, OP_CHECKMULTISIGVERIFY);
1083 roundtrip!(unique, OP_NOP1);
1084 roundtrip!(unique, OP_CLTV);
1085 roundtrip!(unique, OP_CSV);
1086 roundtrip!(unique, OP_NOP4);
1087 roundtrip!(unique, OP_NOP5);
1088 roundtrip!(unique, OP_NOP6);
1089 roundtrip!(unique, OP_NOP7);
1090 roundtrip!(unique, OP_NOP8);
1091 roundtrip!(unique, OP_NOP9);
1092 roundtrip!(unique, OP_NOP10);
1093 roundtrip!(unique, OP_CHECKSIGADD);
1094 roundtrip!(unique, OP_RETURN_187);
1095 roundtrip!(unique, OP_RETURN_188);
1096 roundtrip!(unique, OP_RETURN_189);
1097 roundtrip!(unique, OP_RETURN_190);
1098 roundtrip!(unique, OP_RETURN_191);
1099 roundtrip!(unique, OP_RETURN_192);
1100 roundtrip!(unique, OP_RETURN_193);
1101 roundtrip!(unique, OP_RETURN_194);
1102 roundtrip!(unique, OP_RETURN_195);
1103 roundtrip!(unique, OP_RETURN_196);
1104 roundtrip!(unique, OP_RETURN_197);
1105 roundtrip!(unique, OP_RETURN_198);
1106 roundtrip!(unique, OP_RETURN_199);
1107 roundtrip!(unique, OP_RETURN_200);
1108 roundtrip!(unique, OP_RETURN_201);
1109 roundtrip!(unique, OP_RETURN_202);
1110 roundtrip!(unique, OP_RETURN_203);
1111 roundtrip!(unique, OP_RETURN_204);
1112 roundtrip!(unique, OP_RETURN_205);
1113 roundtrip!(unique, OP_RETURN_206);
1114 roundtrip!(unique, OP_RETURN_207);
1115 roundtrip!(unique, OP_RETURN_208);
1116 roundtrip!(unique, OP_RETURN_209);
1117 roundtrip!(unique, OP_RETURN_210);
1118 roundtrip!(unique, OP_RETURN_211);
1119 roundtrip!(unique, OP_RETURN_212);
1120 roundtrip!(unique, OP_RETURN_213);
1121 roundtrip!(unique, OP_RETURN_214);
1122 roundtrip!(unique, OP_RETURN_215);
1123 roundtrip!(unique, OP_RETURN_216);
1124 roundtrip!(unique, OP_RETURN_217);
1125 roundtrip!(unique, OP_RETURN_218);
1126 roundtrip!(unique, OP_RETURN_219);
1127 roundtrip!(unique, OP_RETURN_220);
1128 roundtrip!(unique, OP_RETURN_221);
1129 roundtrip!(unique, OP_RETURN_222);
1130 roundtrip!(unique, OP_RETURN_223);
1131 roundtrip!(unique, OP_RETURN_224);
1132 roundtrip!(unique, OP_RETURN_225);
1133 roundtrip!(unique, OP_RETURN_226);
1134 roundtrip!(unique, OP_RETURN_227);
1135 roundtrip!(unique, OP_RETURN_228);
1136 roundtrip!(unique, OP_RETURN_229);
1137 roundtrip!(unique, OP_RETURN_230);
1138 roundtrip!(unique, OP_RETURN_231);
1139 roundtrip!(unique, OP_RETURN_232);
1140 roundtrip!(unique, OP_RETURN_233);
1141 roundtrip!(unique, OP_RETURN_234);
1142 roundtrip!(unique, OP_RETURN_235);
1143 roundtrip!(unique, OP_RETURN_236);
1144 roundtrip!(unique, OP_RETURN_237);
1145 roundtrip!(unique, OP_RETURN_238);
1146 roundtrip!(unique, OP_RETURN_239);
1147 roundtrip!(unique, OP_RETURN_240);
1148 roundtrip!(unique, OP_RETURN_241);
1149 roundtrip!(unique, OP_RETURN_242);
1150 roundtrip!(unique, OP_RETURN_243);
1151 roundtrip!(unique, OP_RETURN_244);
1152 roundtrip!(unique, OP_RETURN_245);
1153 roundtrip!(unique, OP_RETURN_246);
1154 roundtrip!(unique, OP_RETURN_247);
1155 roundtrip!(unique, OP_RETURN_248);
1156 roundtrip!(unique, OP_RETURN_249);
1157 roundtrip!(unique, OP_RETURN_250);
1158 roundtrip!(unique, OP_RETURN_251);
1159 roundtrip!(unique, OP_RETURN_252);
1160 roundtrip!(unique, OP_RETURN_253);
1161 roundtrip!(unique, OP_RETURN_254);
1162 roundtrip!(unique, OP_INVALIDOPCODE);
1163 assert_eq!(unique.len(), 256);
1164 }
1165}