1#![allow(non_camel_case_types)]
22
23#[cfg(feature = "serde")] use serde;
24
25use std::fmt;
26
27use consensus::encode::{self, Decoder, Encoder};
28use consensus::encode::{Decodable, Encodable};
29
30#[derive(Copy, Clone, PartialEq, Eq)]
36pub struct All {
37 code: u8,
38}
39
40pub mod all {
41 use super::All;
43
44 pub const OP_PUSHBYTES_0: All = All {code: 0x00};
46 pub const OP_PUSHBYTES_1: All = All {code: 0x01};
48 pub const OP_PUSHBYTES_2: All = All {code: 0x02};
50 pub const OP_PUSHBYTES_3: All = All {code: 0x03};
52 pub const OP_PUSHBYTES_4: All = All {code: 0x04};
54 pub const OP_PUSHBYTES_5: All = All {code: 0x05};
56 pub const OP_PUSHBYTES_6: All = All {code: 0x06};
58 pub const OP_PUSHBYTES_7: All = All {code: 0x07};
60 pub const OP_PUSHBYTES_8: All = All {code: 0x08};
62 pub const OP_PUSHBYTES_9: All = All {code: 0x09};
64 pub const OP_PUSHBYTES_10: All = All {code: 0x0a};
66 pub const OP_PUSHBYTES_11: All = All {code: 0x0b};
68 pub const OP_PUSHBYTES_12: All = All {code: 0x0c};
70 pub const OP_PUSHBYTES_13: All = All {code: 0x0d};
72 pub const OP_PUSHBYTES_14: All = All {code: 0x0e};
74 pub const OP_PUSHBYTES_15: All = All {code: 0x0f};
76 pub const OP_PUSHBYTES_16: All = All {code: 0x10};
78 pub const OP_PUSHBYTES_17: All = All {code: 0x11};
80 pub const OP_PUSHBYTES_18: All = All {code: 0x12};
82 pub const OP_PUSHBYTES_19: All = All {code: 0x13};
84 pub const OP_PUSHBYTES_20: All = All {code: 0x14};
86 pub const OP_PUSHBYTES_21: All = All {code: 0x15};
88 pub const OP_PUSHBYTES_22: All = All {code: 0x16};
90 pub const OP_PUSHBYTES_23: All = All {code: 0x17};
92 pub const OP_PUSHBYTES_24: All = All {code: 0x18};
94 pub const OP_PUSHBYTES_25: All = All {code: 0x19};
96 pub const OP_PUSHBYTES_26: All = All {code: 0x1a};
98 pub const OP_PUSHBYTES_27: All = All {code: 0x1b};
100 pub const OP_PUSHBYTES_28: All = All {code: 0x1c};
102 pub const OP_PUSHBYTES_29: All = All {code: 0x1d};
104 pub const OP_PUSHBYTES_30: All = All {code: 0x1e};
106 pub const OP_PUSHBYTES_31: All = All {code: 0x1f};
108 pub const OP_PUSHBYTES_32: All = All {code: 0x20};
110 pub const OP_PUSHBYTES_33: All = All {code: 0x21};
112 pub const OP_PUSHBYTES_34: All = All {code: 0x22};
114 pub const OP_PUSHBYTES_35: All = All {code: 0x23};
116 pub const OP_PUSHBYTES_36: All = All {code: 0x24};
118 pub const OP_PUSHBYTES_37: All = All {code: 0x25};
120 pub const OP_PUSHBYTES_38: All = All {code: 0x26};
122 pub const OP_PUSHBYTES_39: All = All {code: 0x27};
124 pub const OP_PUSHBYTES_40: All = All {code: 0x28};
126 pub const OP_PUSHBYTES_41: All = All {code: 0x29};
128 pub const OP_PUSHBYTES_42: All = All {code: 0x2a};
130 pub const OP_PUSHBYTES_43: All = All {code: 0x2b};
132 pub const OP_PUSHBYTES_44: All = All {code: 0x2c};
134 pub const OP_PUSHBYTES_45: All = All {code: 0x2d};
136 pub const OP_PUSHBYTES_46: All = All {code: 0x2e};
138 pub const OP_PUSHBYTES_47: All = All {code: 0x2f};
140 pub const OP_PUSHBYTES_48: All = All {code: 0x30};
142 pub const OP_PUSHBYTES_49: All = All {code: 0x31};
144 pub const OP_PUSHBYTES_50: All = All {code: 0x32};
146 pub const OP_PUSHBYTES_51: All = All {code: 0x33};
148 pub const OP_PUSHBYTES_52: All = All {code: 0x34};
150 pub const OP_PUSHBYTES_53: All = All {code: 0x35};
152 pub const OP_PUSHBYTES_54: All = All {code: 0x36};
154 pub const OP_PUSHBYTES_55: All = All {code: 0x37};
156 pub const OP_PUSHBYTES_56: All = All {code: 0x38};
158 pub const OP_PUSHBYTES_57: All = All {code: 0x39};
160 pub const OP_PUSHBYTES_58: All = All {code: 0x3a};
162 pub const OP_PUSHBYTES_59: All = All {code: 0x3b};
164 pub const OP_PUSHBYTES_60: All = All {code: 0x3c};
166 pub const OP_PUSHBYTES_61: All = All {code: 0x3d};
168 pub const OP_PUSHBYTES_62: All = All {code: 0x3e};
170 pub const OP_PUSHBYTES_63: All = All {code: 0x3f};
172 pub const OP_PUSHBYTES_64: All = All {code: 0x40};
174 pub const OP_PUSHBYTES_65: All = All {code: 0x41};
176 pub const OP_PUSHBYTES_66: All = All {code: 0x42};
178 pub const OP_PUSHBYTES_67: All = All {code: 0x43};
180 pub const OP_PUSHBYTES_68: All = All {code: 0x44};
182 pub const OP_PUSHBYTES_69: All = All {code: 0x45};
184 pub const OP_PUSHBYTES_70: All = All {code: 0x46};
186 pub const OP_PUSHBYTES_71: All = All {code: 0x47};
188 pub const OP_PUSHBYTES_72: All = All {code: 0x48};
190 pub const OP_PUSHBYTES_73: All = All {code: 0x49};
192 pub const OP_PUSHBYTES_74: All = All {code: 0x4a};
194 pub const OP_PUSHBYTES_75: All = All {code: 0x4b};
196 pub const OP_PUSHDATA1: All = All {code: 0x4c};
198 pub const OP_PUSHDATA2: All = All {code: 0x4d};
200 pub const OP_PUSHDATA4: All = All {code: 0x4e};
202 pub const OP_PUSHNUM_NEG1: All = All {code: 0x4f};
204 pub const OP_RESERVED: All = All {code: 0x50};
206 pub const OP_PUSHNUM_1: All = All {code: 0x51};
208 pub const OP_PUSHNUM_2: All = All {code: 0x52};
210 pub const OP_PUSHNUM_3: All = All {code: 0x53};
212 pub const OP_PUSHNUM_4: All = All {code: 0x54};
214 pub const OP_PUSHNUM_5: All = All {code: 0x55};
216 pub const OP_PUSHNUM_6: All = All {code: 0x56};
218 pub const OP_PUSHNUM_7: All = All {code: 0x57};
220 pub const OP_PUSHNUM_8: All = All {code: 0x58};
222 pub const OP_PUSHNUM_9: All = All {code: 0x59};
224 pub const OP_PUSHNUM_10: All = All {code: 0x5a};
226 pub const OP_PUSHNUM_11: All = All {code: 0x5b};
228 pub const OP_PUSHNUM_12: All = All {code: 0x5c};
230 pub const OP_PUSHNUM_13: All = All {code: 0x5d};
232 pub const OP_PUSHNUM_14: All = All {code: 0x5e};
234 pub const OP_PUSHNUM_15: All = All {code: 0x5f};
236 pub const OP_PUSHNUM_16: All = All {code: 0x60};
238 pub const OP_NOP: All = All {code: 0x61};
240 pub const OP_VER: All = All {code: 0x62};
242 pub const OP_IF: All = All {code: 0x63};
244 pub const OP_NOTIF: All = All {code: 0x64};
246 pub const OP_VERIF: All = All {code: 0x65};
248 pub const OP_VERNOTIF: All = All {code: 0x66};
250 pub const OP_ELSE: All = All {code: 0x67};
253 pub const OP_ENDIF: All = All {code: 0x68};
255 pub const OP_VERIFY: All = All {code: 0x69};
257 pub const OP_RETURN: All = All {code: 0x6a};
259 pub const OP_TOALTSTACK: All = All {code: 0x6b};
261 pub const OP_FROMALTSTACK: All = All {code: 0x6c};
263 pub const OP_2DROP: All = All {code: 0x6d};
265 pub const OP_2DUP: All = All {code: 0x6e};
267 pub const OP_3DUP: All = All {code: 0x6f};
269 pub const OP_2OVER: All = All {code: 0x70};
272 pub const OP_2ROT: All = All {code: 0x71};
275 pub const OP_2SWAP: All = All {code: 0x72};
277 pub const OP_IFDUP: All = All {code: 0x73};
279 pub const OP_DEPTH: All = All {code: 0x74};
281 pub const OP_DROP: All = All {code: 0x75};
283 pub const OP_DUP: All = All {code: 0x76};
285 pub const OP_NIP: All = All {code: 0x77};
287 pub const OP_OVER: All = All {code: 0x78};
289 pub const OP_PICK: All = All {code: 0x79};
291 pub const OP_ROLL: All = All {code: 0x7a};
293 pub const OP_ROT: All = All {code: 0x7b};
295 pub const OP_SWAP: All = All {code: 0x7c};
297 pub const OP_TUCK: All = All {code: 0x7d};
299 pub const OP_CAT: All = All {code: 0x7e};
301 pub const OP_SUBSTR: All = All {code: 0x7f};
303 pub const OP_LEFT: All = All {code: 0x80};
305 pub const OP_RIGHT: All = All {code: 0x81};
307 pub const OP_SIZE: All = All {code: 0x82};
309 pub const OP_INVERT: All = All {code: 0x83};
311 pub const OP_AND: All = All {code: 0x84};
313 pub const OP_OR: All = All {code: 0x85};
315 pub const OP_XOR: All = All {code: 0x86};
317 pub const OP_EQUAL: All = All {code: 0x87};
319 pub const OP_EQUALVERIFY: All = All {code: 0x88};
321 pub const OP_RESERVED1: All = All {code: 0x89};
323 pub const OP_RESERVED2: All = All {code: 0x8a};
325 pub const OP_1ADD: All = All {code: 0x8b};
327 pub const OP_1SUB: All = All {code: 0x8c};
329 pub const OP_2MUL: All = All {code: 0x8d};
331 pub const OP_2DIV: All = All {code: 0x8e};
333 pub const OP_NEGATE: All = All {code: 0x8f};
335 pub const OP_ABS: All = All {code: 0x90};
337 pub const OP_NOT: All = All {code: 0x91};
339 pub const OP_0NOTEQUAL: All = All {code: 0x92};
341 pub const OP_ADD: All = All {code: 0x93};
343 pub const OP_SUB: All = All {code: 0x94};
345 pub const OP_MUL: All = All {code: 0x95};
347 pub const OP_DIV: All = All {code: 0x96};
349 pub const OP_MOD: All = All {code: 0x97};
351 pub const OP_LSHIFT: All = All {code: 0x98};
353 pub const OP_RSHIFT: All = All {code: 0x99};
355 pub const OP_BOOLAND: All = All {code: 0x9a};
357 pub const OP_BOOLOR: All = All {code: 0x9b};
359 pub const OP_NUMEQUAL: All = All {code: 0x9c};
361 pub const OP_NUMEQUALVERIFY: All = All {code: 0x9d};
363 pub const OP_NUMNOTEQUAL: All = All {code: 0x9e};
365 pub const OP_LESSTHAN : All = All {code: 0x9f};
367 pub const OP_GREATERTHAN : All = All {code: 0xa0};
369 pub const OP_LESSTHANOREQUAL : All = All {code: 0xa1};
371 pub const OP_GREATERTHANOREQUAL : All = All {code: 0xa2};
373 pub const OP_MIN: All = All {code: 0xa3};
375 pub const OP_MAX: All = All {code: 0xa4};
377 pub const OP_WITHIN: All = All {code: 0xa5};
379 pub const OP_RIPEMD160: All = All {code: 0xa6};
381 pub const OP_SHA1: All = All {code: 0xa7};
383 pub const OP_SHA256: All = All {code: 0xa8};
385 pub const OP_HASH160: All = All {code: 0xa9};
387 pub const OP_HASH256: All = All {code: 0xaa};
389 pub const OP_CODESEPARATOR: All = All {code: 0xab};
391 pub const OP_CHECKSIG: All = All {code: 0xac};
393 pub const OP_CHECKSIGVERIFY: All = All {code: 0xad};
395 pub const OP_CHECKMULTISIG: All = All {code: 0xae};
398 pub const OP_CHECKMULTISIGVERIFY: All = All {code: 0xaf};
400 pub const OP_NOP1: All = All {code: 0xb0};
402 pub const OP_NOP2: All = All {code: 0xb1};
404 pub const OP_NOP3: All = All {code: 0xb2};
406 pub const OP_NOP4: All = All {code: 0xb3};
408 pub const OP_NOP5: All = All {code: 0xb4};
410 pub const OP_NOP6: All = All {code: 0xb5};
412 pub const OP_NOP7: All = All {code: 0xb6};
414 pub const OP_NOP8: All = All {code: 0xb7};
416 pub const OP_NOP9: All = All {code: 0xb8};
418 pub const OP_NOP10: All = All {code: 0xb9};
420 pub const OP_RETURN_186: All = All {code: 0xba};
423 pub const OP_RETURN_187: All = All {code: 0xbb};
425 pub const OP_RETURN_188: All = All {code: 0xbc};
427 pub const OP_RETURN_189: All = All {code: 0xbd};
429 pub const OP_RETURN_190: All = All {code: 0xbe};
431 pub const OP_RETURN_191: All = All {code: 0xbf};
433 pub const OP_RETURN_192: All = All {code: 0xc0};
435 pub const OP_RETURN_193: All = All {code: 0xc1};
437 pub const OP_RETURN_194: All = All {code: 0xc2};
439 pub const OP_RETURN_195: All = All {code: 0xc3};
441 pub const OP_RETURN_196: All = All {code: 0xc4};
443 pub const OP_RETURN_197: All = All {code: 0xc5};
445 pub const OP_RETURN_198: All = All {code: 0xc6};
447 pub const OP_RETURN_199: All = All {code: 0xc7};
449 pub const OP_RETURN_200: All = All {code: 0xc8};
451 pub const OP_RETURN_201: All = All {code: 0xc9};
453 pub const OP_RETURN_202: All = All {code: 0xca};
455 pub const OP_RETURN_203: All = All {code: 0xcb};
457 pub const OP_RETURN_204: All = All {code: 0xcc};
459 pub const OP_RETURN_205: All = All {code: 0xcd};
461 pub const OP_RETURN_206: All = All {code: 0xce};
463 pub const OP_RETURN_207: All = All {code: 0xcf};
465 pub const OP_RETURN_208: All = All {code: 0xd0};
467 pub const OP_RETURN_209: All = All {code: 0xd1};
469 pub const OP_RETURN_210: All = All {code: 0xd2};
471 pub const OP_RETURN_211: All = All {code: 0xd3};
473 pub const OP_RETURN_212: All = All {code: 0xd4};
475 pub const OP_RETURN_213: All = All {code: 0xd5};
477 pub const OP_RETURN_214: All = All {code: 0xd6};
479 pub const OP_RETURN_215: All = All {code: 0xd7};
481 pub const OP_RETURN_216: All = All {code: 0xd8};
483 pub const OP_RETURN_217: All = All {code: 0xd9};
485 pub const OP_RETURN_218: All = All {code: 0xda};
487 pub const OP_RETURN_219: All = All {code: 0xdb};
489 pub const OP_RETURN_220: All = All {code: 0xdc};
491 pub const OP_RETURN_221: All = All {code: 0xdd};
493 pub const OP_RETURN_222: All = All {code: 0xde};
495 pub const OP_RETURN_223: All = All {code: 0xdf};
497 pub const OP_RETURN_224: All = All {code: 0xe0};
499 pub const OP_RETURN_225: All = All {code: 0xe1};
501 pub const OP_RETURN_226: All = All {code: 0xe2};
503 pub const OP_RETURN_227: All = All {code: 0xe3};
505 pub const OP_RETURN_228: All = All {code: 0xe4};
507 pub const OP_RETURN_229: All = All {code: 0xe5};
509 pub const OP_RETURN_230: All = All {code: 0xe6};
511 pub const OP_RETURN_231: All = All {code: 0xe7};
513 pub const OP_RETURN_232: All = All {code: 0xe8};
515 pub const OP_RETURN_233: All = All {code: 0xe9};
517 pub const OP_RETURN_234: All = All {code: 0xea};
519 pub const OP_RETURN_235: All = All {code: 0xeb};
521 pub const OP_RETURN_236: All = All {code: 0xec};
523 pub const OP_RETURN_237: All = All {code: 0xed};
525 pub const OP_RETURN_238: All = All {code: 0xee};
527 pub const OP_RETURN_239: All = All {code: 0xef};
529 pub const OP_RETURN_240: All = All {code: 0xf0};
531 pub const OP_RETURN_241: All = All {code: 0xf1};
533 pub const OP_RETURN_242: All = All {code: 0xf2};
535 pub const OP_RETURN_243: All = All {code: 0xf3};
537 pub const OP_RETURN_244: All = All {code: 0xf4};
539 pub const OP_RETURN_245: All = All {code: 0xf5};
541 pub const OP_RETURN_246: All = All {code: 0xf6};
543 pub const OP_RETURN_247: All = All {code: 0xf7};
545 pub const OP_RETURN_248: All = All {code: 0xf8};
547 pub const OP_RETURN_249: All = All {code: 0xf9};
549 pub const OP_RETURN_250: All = All {code: 0xfa};
551 pub const OP_RETURN_251: All = All {code: 0xfb};
553 pub const OP_RETURN_252: All = All {code: 0xfc};
555 pub const OP_RETURN_253: All = All {code: 0xfd};
557 pub const OP_RETURN_254: All = All {code: 0xfe};
559 pub const OP_RETURN_255: All = All {code: 0xff};
561}
562
563impl fmt::Debug for All {
564 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
565 f.write_str("OP_")?;
566 match *self {
567 All {code: x} if x <= 75 => write!(f, "PUSHBYTES_{}", self.code),
568 all::OP_PUSHDATA1 => write!(f, "PUSHDATA1"),
569 all::OP_PUSHDATA2 => write!(f, "PUSHDATA2"),
570 all::OP_PUSHDATA4 => write!(f, "PUSHDATA4"),
571 all::OP_PUSHNUM_NEG1 => write!(f, "PUSHNUM_NEG1"),
572 all::OP_RESERVED => write!(f, "RESERVED"),
573 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),
574 all::OP_NOP => write!(f, "NOP"),
575 all::OP_VER => write!(f, "VER"),
576 all::OP_IF => write!(f, "IF"),
577 all::OP_NOTIF => write!(f, "NOTIF"),
578 all::OP_VERIF => write!(f, "VERIF"),
579 all::OP_VERNOTIF => write!(f, "VERNOTIF"),
580 all::OP_ELSE => write!(f, "ELSE"),
581 all::OP_ENDIF => write!(f, "ENDIF"),
582 all::OP_VERIFY => write!(f, "VERIFY"),
583 all::OP_RETURN => write!(f, "RETURN"),
584 all::OP_TOALTSTACK => write!(f, "TOALTSTACK"),
585 all::OP_FROMALTSTACK => write!(f, "FROMALTSTACK"),
586 all::OP_2DROP => write!(f, "2DROP"),
587 all::OP_2DUP => write!(f, "2DUP"),
588 all::OP_3DUP => write!(f, "3DUP"),
589 all::OP_2OVER => write!(f, "2OVER"),
590 all::OP_2ROT => write!(f, "2ROT"),
591 all::OP_2SWAP => write!(f, "2SWAP"),
592 all::OP_IFDUP => write!(f, "IFDUP"),
593 all::OP_DEPTH => write!(f, "DEPTH"),
594 all::OP_DROP => write!(f, "DROP"),
595 all::OP_DUP => write!(f, "DUP"),
596 all::OP_NIP => write!(f, "NIP"),
597 all::OP_OVER => write!(f, "OVER"),
598 all::OP_PICK => write!(f, "PICK"),
599 all::OP_ROLL => write!(f, "ROLL"),
600 all::OP_ROT => write!(f, "ROT"),
601 all::OP_SWAP => write!(f, "SWAP"),
602 all::OP_TUCK => write!(f, "TUCK"),
603 all::OP_CAT => write!(f, "CAT"),
604 all::OP_SUBSTR => write!(f, "SUBSTR"),
605 all::OP_LEFT => write!(f, "LEFT"),
606 all::OP_RIGHT => write!(f, "RIGHT"),
607 all::OP_SIZE => write!(f, "SIZE"),
608 all::OP_INVERT => write!(f, "INVERT"),
609 all::OP_AND => write!(f, "AND"),
610 all::OP_OR => write!(f, "OR"),
611 all::OP_XOR => write!(f, "XOR"),
612 all::OP_EQUAL => write!(f, "EQUAL"),
613 all::OP_EQUALVERIFY => write!(f, "EQUALVERIFY"),
614 all::OP_RESERVED1 => write!(f, "RESERVED1"),
615 all::OP_RESERVED2 => write!(f, "RESERVED2"),
616 all::OP_1ADD => write!(f, "1ADD"),
617 all::OP_1SUB => write!(f, "1SUB"),
618 all::OP_2MUL => write!(f, "2MUL"),
619 all::OP_2DIV => write!(f, "2DIV"),
620 all::OP_NEGATE => write!(f, "NEGATE"),
621 all::OP_ABS => write!(f, "ABS"),
622 all::OP_NOT => write!(f, "NOT"),
623 all::OP_0NOTEQUAL => write!(f, "0NOTEQUAL"),
624 all::OP_ADD => write!(f, "ADD"),
625 all::OP_SUB => write!(f, "SUB"),
626 all::OP_MUL => write!(f, "MUL"),
627 all::OP_DIV => write!(f, "DIV"),
628 all::OP_MOD => write!(f, "MOD"),
629 all::OP_LSHIFT => write!(f, "LSHIFT"),
630 all::OP_RSHIFT => write!(f, "RSHIFT"),
631 all::OP_BOOLAND => write!(f, "BOOLAND"),
632 all::OP_BOOLOR => write!(f, "BOOLOR"),
633 all::OP_NUMEQUAL => write!(f, "NUMEQUAL"),
634 all::OP_NUMEQUALVERIFY => write!(f, "NUMEQUALVERIFY"),
635 all::OP_NUMNOTEQUAL => write!(f, "NUMNOTEQUAL"),
636 all::OP_LESSTHAN => write!(f, "LESSTHAN"),
637 all::OP_GREATERTHAN => write!(f, "GREATERTHAN"),
638 all::OP_LESSTHANOREQUAL => write!(f, "LESSTHANOREQUAL"),
639 all::OP_GREATERTHANOREQUAL => write!(f, "GREATERTHANOREQUAL"),
640 all::OP_MIN => write!(f, "MIN"),
641 all::OP_MAX => write!(f, "MAX"),
642 all::OP_WITHIN => write!(f, "WITHIN"),
643 all::OP_RIPEMD160 => write!(f, "RIPEMD160"),
644 all::OP_SHA1 => write!(f, "SHA1"),
645 all::OP_SHA256 => write!(f, "SHA256"),
646 all::OP_HASH160 => write!(f, "HASH160"),
647 all::OP_HASH256 => write!(f, "HASH256"),
648 all::OP_CODESEPARATOR => write!(f, "CODESEPARATOR"),
649 all::OP_CHECKSIG => write!(f, "CHECKSIG"),
650 all::OP_CHECKSIGVERIFY => write!(f, "CHECKSIGVERIFY"),
651 all::OP_CHECKMULTISIG => write!(f, "CHECKMULTISIG"),
652 all::OP_CHECKMULTISIGVERIFY => write!(f, "CHECKMULTISIGVERIFY"),
653 All {code: x} if x >= all::OP_NOP1.code && x <= all::OP_NOP10.code => write!(f, "NOP{}", x - all::OP_NOP1.code + 1),
654 All {code: x} => write!(f, "RETURN_{}", x),
655 }
656 }
657}
658
659impl All {
660 #[inline]
662 pub fn classify(&self) -> Class {
663 if *self == all::OP_VERIF || *self == all::OP_VERNOTIF ||
665 *self == all::OP_CAT || *self == all::OP_SUBSTR ||
666 *self == all::OP_LEFT || *self == all::OP_RIGHT ||
667 *self == all::OP_INVERT || *self == all::OP_AND ||
668 *self == all::OP_OR || *self == all::OP_XOR ||
669 *self == all::OP_2MUL || *self == all::OP_2DIV ||
670 *self == all::OP_MUL || *self == all::OP_DIV || *self == all::OP_MOD ||
671 *self == all::OP_LSHIFT || *self == all::OP_RSHIFT {
672 Class::IllegalOp
673 } else if *self == all::OP_NOP ||
675 (all::OP_NOP1.code <= self.code &&
676 self.code <= all::OP_NOP10.code) {
677 Class::NoOp
678 } else if *self == all::OP_RESERVED || *self == all::OP_VER || *self == all::OP_RETURN ||
680 *self == all::OP_RESERVED1 || *self == all::OP_RESERVED2 ||
681 self.code >= all::OP_RETURN_186.code {
682 Class::ReturnOp
683 } else if *self == all::OP_PUSHNUM_NEG1 {
685 Class::PushNum(-1)
686 } else if all::OP_PUSHNUM_1.code <= self.code &&
688 self.code <= all::OP_PUSHNUM_16.code {
689 Class::PushNum(1 + self.code as i32 - all::OP_PUSHNUM_1.code as i32)
690 } else if self.code <= all::OP_PUSHBYTES_75.code {
692 Class::PushBytes(self.code as u32)
693 } else {
695 Class::Ordinary(Ordinary::try_from_all(*self).unwrap())
696 }
697 }
698
699 #[inline]
701 pub fn into_u8(&self) -> u8 {
702 self.code
703 }
704}
705
706impl From<u8> for All {
707 #[inline]
708 fn from(b: u8) -> All {
709 All {code: b}
710 }
711}
712
713
714display_from_debug!(All);
715
716impl<D: Decoder> Decodable<D> for All {
717 #[inline]
718 fn consensus_decode(d: &mut D) -> Result<All, encode::Error> {
719 Ok(All::from(d.read_u8()?))
720 }
721}
722
723impl<S: Encoder> Encodable<S> for All {
724 #[inline]
725 fn consensus_encode(&self, s: &mut S) -> Result<(), encode::Error> {
726 s.emit_u8(self.code)
727 }
728}
729
730#[cfg(feature = "serde")]
731impl serde::Serialize for All {
732 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
733 where
734 S: serde::Serializer,
735 {
736 serializer.serialize_str(&self.to_string())
737 }
738}
739
740pub static OP_FALSE: All = all::OP_PUSHBYTES_0;
742pub static OP_TRUE: All = all::OP_PUSHNUM_1;
744pub static OP_CLTV: All = all::OP_NOP2;
746pub static OP_CSV: All = all::OP_NOP3;
748
749#[derive(Copy, Clone, PartialEq, Eq, Debug)]
751pub enum Class {
752 PushNum(i32),
754 PushBytes(u32),
756 ReturnOp,
758 IllegalOp,
760 NoOp,
762 Ordinary(Ordinary)
764}
765
766display_from_debug!(Class);
767
768#[cfg(feature = "serde")]
769impl serde::Serialize for Class {
770 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
771 where
772 S: serde::Serializer,
773 {
774 serializer.serialize_str(&self.to_string())
775 }
776}
777
778macro_rules! ordinary_opcode {
779 ($($op:ident),*) => (
780 #[repr(u8)]
781 #[doc(hidden)]
782 #[derive(Copy, Clone, PartialEq, Eq, Debug)]
783 pub enum Ordinary {
784 $( $op = all::$op.code ),*
785 }
786
787 impl Ordinary {
788 pub fn try_from_all(b: All) -> Option<Self> {
790 match b {
791 $( all::$op => { Some(Ordinary::$op) } ),*
792 _ => None,
793 }
794 }
795 }
796 );
797}
798
799ordinary_opcode! {
801 OP_PUSHDATA1, OP_PUSHDATA2, OP_PUSHDATA4,
803 OP_IF, OP_NOTIF, OP_ELSE, OP_ENDIF, OP_VERIFY,
805 OP_TOALTSTACK, OP_FROMALTSTACK,
807 OP_2DROP, OP_2DUP, OP_3DUP, OP_2OVER, OP_2ROT, OP_2SWAP,
808 OP_DROP, OP_DUP, OP_NIP, OP_OVER, OP_PICK, OP_ROLL, OP_ROT, OP_SWAP, OP_TUCK,
809 OP_IFDUP, OP_DEPTH, OP_SIZE,
810 OP_EQUAL, OP_EQUALVERIFY,
812 OP_1ADD, OP_1SUB, OP_NEGATE, OP_ABS, OP_NOT, OP_0NOTEQUAL,
814 OP_ADD, OP_SUB, OP_BOOLAND, OP_BOOLOR,
815 OP_NUMEQUAL, OP_NUMEQUALVERIFY, OP_NUMNOTEQUAL, OP_LESSTHAN,
816 OP_GREATERTHAN, OP_LESSTHANOREQUAL, OP_GREATERTHANOREQUAL,
817 OP_MIN, OP_MAX, OP_WITHIN,
818 OP_RIPEMD160, OP_SHA1, OP_SHA256, OP_HASH160, OP_HASH256,
820 OP_CODESEPARATOR, OP_CHECKSIG, OP_CHECKSIGVERIFY,
821 OP_CHECKMULTISIG, OP_CHECKMULTISIGVERIFY
822}
823
824impl Ordinary {
825 #[inline]
827 pub fn into_u8(&self) -> u8 {
828 *self as u8
829 }
830}
831
832#[cfg(test)]
833mod tests {
834 use std::collections::HashSet;
835
836 use consensus::encode::{serialize, deserialize};
837 use super::*;
838
839 macro_rules! roundtrip {
840 ($unique:expr, $op:ident) => {
841 assert_eq!(all::$op, All::from(all::$op.into_u8()));
842
843 let s1 = format!("{}", all::$op);
844 let s2 = format!("{:?}", all::$op);
845 assert_eq!(s1, s2);
846 assert_eq!(s1, stringify!($op));
847 assert!($unique.insert(s1));
848
849 let enc = serialize(&all::$op);
850 assert_eq!(all::$op, deserialize(&enc).unwrap());
851 }
852 }
853
854 #[test]
855 fn str_roundtrip() {
856 let mut unique = HashSet::new();
857 roundtrip!(unique, OP_PUSHBYTES_0);
858 roundtrip!(unique, OP_PUSHBYTES_1);
859 roundtrip!(unique, OP_PUSHBYTES_2);
860 roundtrip!(unique, OP_PUSHBYTES_3);
861 roundtrip!(unique, OP_PUSHBYTES_4);
862 roundtrip!(unique, OP_PUSHBYTES_5);
863 roundtrip!(unique, OP_PUSHBYTES_6);
864 roundtrip!(unique, OP_PUSHBYTES_7);
865 roundtrip!(unique, OP_PUSHBYTES_8);
866 roundtrip!(unique, OP_PUSHBYTES_9);
867 roundtrip!(unique, OP_PUSHBYTES_10);
868 roundtrip!(unique, OP_PUSHBYTES_11);
869 roundtrip!(unique, OP_PUSHBYTES_12);
870 roundtrip!(unique, OP_PUSHBYTES_13);
871 roundtrip!(unique, OP_PUSHBYTES_14);
872 roundtrip!(unique, OP_PUSHBYTES_15);
873 roundtrip!(unique, OP_PUSHBYTES_16);
874 roundtrip!(unique, OP_PUSHBYTES_17);
875 roundtrip!(unique, OP_PUSHBYTES_18);
876 roundtrip!(unique, OP_PUSHBYTES_19);
877 roundtrip!(unique, OP_PUSHBYTES_20);
878 roundtrip!(unique, OP_PUSHBYTES_21);
879 roundtrip!(unique, OP_PUSHBYTES_22);
880 roundtrip!(unique, OP_PUSHBYTES_23);
881 roundtrip!(unique, OP_PUSHBYTES_24);
882 roundtrip!(unique, OP_PUSHBYTES_25);
883 roundtrip!(unique, OP_PUSHBYTES_26);
884 roundtrip!(unique, OP_PUSHBYTES_27);
885 roundtrip!(unique, OP_PUSHBYTES_28);
886 roundtrip!(unique, OP_PUSHBYTES_29);
887 roundtrip!(unique, OP_PUSHBYTES_30);
888 roundtrip!(unique, OP_PUSHBYTES_31);
889 roundtrip!(unique, OP_PUSHBYTES_32);
890 roundtrip!(unique, OP_PUSHBYTES_33);
891 roundtrip!(unique, OP_PUSHBYTES_34);
892 roundtrip!(unique, OP_PUSHBYTES_35);
893 roundtrip!(unique, OP_PUSHBYTES_36);
894 roundtrip!(unique, OP_PUSHBYTES_37);
895 roundtrip!(unique, OP_PUSHBYTES_38);
896 roundtrip!(unique, OP_PUSHBYTES_39);
897 roundtrip!(unique, OP_PUSHBYTES_40);
898 roundtrip!(unique, OP_PUSHBYTES_41);
899 roundtrip!(unique, OP_PUSHBYTES_42);
900 roundtrip!(unique, OP_PUSHBYTES_43);
901 roundtrip!(unique, OP_PUSHBYTES_44);
902 roundtrip!(unique, OP_PUSHBYTES_45);
903 roundtrip!(unique, OP_PUSHBYTES_46);
904 roundtrip!(unique, OP_PUSHBYTES_47);
905 roundtrip!(unique, OP_PUSHBYTES_48);
906 roundtrip!(unique, OP_PUSHBYTES_49);
907 roundtrip!(unique, OP_PUSHBYTES_50);
908 roundtrip!(unique, OP_PUSHBYTES_51);
909 roundtrip!(unique, OP_PUSHBYTES_52);
910 roundtrip!(unique, OP_PUSHBYTES_53);
911 roundtrip!(unique, OP_PUSHBYTES_54);
912 roundtrip!(unique, OP_PUSHBYTES_55);
913 roundtrip!(unique, OP_PUSHBYTES_56);
914 roundtrip!(unique, OP_PUSHBYTES_57);
915 roundtrip!(unique, OP_PUSHBYTES_58);
916 roundtrip!(unique, OP_PUSHBYTES_59);
917 roundtrip!(unique, OP_PUSHBYTES_60);
918 roundtrip!(unique, OP_PUSHBYTES_61);
919 roundtrip!(unique, OP_PUSHBYTES_62);
920 roundtrip!(unique, OP_PUSHBYTES_63);
921 roundtrip!(unique, OP_PUSHBYTES_64);
922 roundtrip!(unique, OP_PUSHBYTES_65);
923 roundtrip!(unique, OP_PUSHBYTES_66);
924 roundtrip!(unique, OP_PUSHBYTES_67);
925 roundtrip!(unique, OP_PUSHBYTES_68);
926 roundtrip!(unique, OP_PUSHBYTES_69);
927 roundtrip!(unique, OP_PUSHBYTES_70);
928 roundtrip!(unique, OP_PUSHBYTES_71);
929 roundtrip!(unique, OP_PUSHBYTES_72);
930 roundtrip!(unique, OP_PUSHBYTES_73);
931 roundtrip!(unique, OP_PUSHBYTES_74);
932 roundtrip!(unique, OP_PUSHBYTES_75);
933 roundtrip!(unique, OP_PUSHDATA1);
934 roundtrip!(unique, OP_PUSHDATA2);
935 roundtrip!(unique, OP_PUSHDATA4);
936 roundtrip!(unique, OP_PUSHNUM_NEG1);
937 roundtrip!(unique, OP_RESERVED);
938 roundtrip!(unique, OP_PUSHNUM_1);
939 roundtrip!(unique, OP_PUSHNUM_2);
940 roundtrip!(unique, OP_PUSHNUM_3);
941 roundtrip!(unique, OP_PUSHNUM_4);
942 roundtrip!(unique, OP_PUSHNUM_5);
943 roundtrip!(unique, OP_PUSHNUM_6);
944 roundtrip!(unique, OP_PUSHNUM_7);
945 roundtrip!(unique, OP_PUSHNUM_8);
946 roundtrip!(unique, OP_PUSHNUM_9);
947 roundtrip!(unique, OP_PUSHNUM_10);
948 roundtrip!(unique, OP_PUSHNUM_11);
949 roundtrip!(unique, OP_PUSHNUM_12);
950 roundtrip!(unique, OP_PUSHNUM_13);
951 roundtrip!(unique, OP_PUSHNUM_14);
952 roundtrip!(unique, OP_PUSHNUM_15);
953 roundtrip!(unique, OP_PUSHNUM_16);
954 roundtrip!(unique, OP_NOP);
955 roundtrip!(unique, OP_VER);
956 roundtrip!(unique, OP_IF);
957 roundtrip!(unique, OP_NOTIF);
958 roundtrip!(unique, OP_VERIF);
959 roundtrip!(unique, OP_VERNOTIF);
960 roundtrip!(unique, OP_ELSE);
961 roundtrip!(unique, OP_ENDIF);
962 roundtrip!(unique, OP_VERIFY);
963 roundtrip!(unique, OP_RETURN);
964 roundtrip!(unique, OP_TOALTSTACK);
965 roundtrip!(unique, OP_FROMALTSTACK);
966 roundtrip!(unique, OP_2DROP);
967 roundtrip!(unique, OP_2DUP);
968 roundtrip!(unique, OP_3DUP);
969 roundtrip!(unique, OP_2OVER);
970 roundtrip!(unique, OP_2ROT);
971 roundtrip!(unique, OP_2SWAP);
972 roundtrip!(unique, OP_IFDUP);
973 roundtrip!(unique, OP_DEPTH);
974 roundtrip!(unique, OP_DROP);
975 roundtrip!(unique, OP_DUP);
976 roundtrip!(unique, OP_NIP);
977 roundtrip!(unique, OP_OVER);
978 roundtrip!(unique, OP_PICK);
979 roundtrip!(unique, OP_ROLL);
980 roundtrip!(unique, OP_ROT);
981 roundtrip!(unique, OP_SWAP);
982 roundtrip!(unique, OP_TUCK);
983 roundtrip!(unique, OP_CAT);
984 roundtrip!(unique, OP_SUBSTR);
985 roundtrip!(unique, OP_LEFT);
986 roundtrip!(unique, OP_RIGHT);
987 roundtrip!(unique, OP_SIZE);
988 roundtrip!(unique, OP_INVERT);
989 roundtrip!(unique, OP_AND);
990 roundtrip!(unique, OP_OR);
991 roundtrip!(unique, OP_XOR);
992 roundtrip!(unique, OP_EQUAL);
993 roundtrip!(unique, OP_EQUALVERIFY);
994 roundtrip!(unique, OP_RESERVED1);
995 roundtrip!(unique, OP_RESERVED2);
996 roundtrip!(unique, OP_1ADD);
997 roundtrip!(unique, OP_1SUB);
998 roundtrip!(unique, OP_2MUL);
999 roundtrip!(unique, OP_2DIV);
1000 roundtrip!(unique, OP_NEGATE);
1001 roundtrip!(unique, OP_ABS);
1002 roundtrip!(unique, OP_NOT);
1003 roundtrip!(unique, OP_0NOTEQUAL);
1004 roundtrip!(unique, OP_ADD);
1005 roundtrip!(unique, OP_SUB);
1006 roundtrip!(unique, OP_MUL);
1007 roundtrip!(unique, OP_DIV);
1008 roundtrip!(unique, OP_MOD);
1009 roundtrip!(unique, OP_LSHIFT);
1010 roundtrip!(unique, OP_RSHIFT);
1011 roundtrip!(unique, OP_BOOLAND);
1012 roundtrip!(unique, OP_BOOLOR);
1013 roundtrip!(unique, OP_NUMEQUAL);
1014 roundtrip!(unique, OP_NUMEQUALVERIFY);
1015 roundtrip!(unique, OP_NUMNOTEQUAL);
1016 roundtrip!(unique, OP_LESSTHAN );
1017 roundtrip!(unique, OP_GREATERTHAN );
1018 roundtrip!(unique, OP_LESSTHANOREQUAL );
1019 roundtrip!(unique, OP_GREATERTHANOREQUAL );
1020 roundtrip!(unique, OP_MIN);
1021 roundtrip!(unique, OP_MAX);
1022 roundtrip!(unique, OP_WITHIN);
1023 roundtrip!(unique, OP_RIPEMD160);
1024 roundtrip!(unique, OP_SHA1);
1025 roundtrip!(unique, OP_SHA256);
1026 roundtrip!(unique, OP_HASH160);
1027 roundtrip!(unique, OP_HASH256);
1028 roundtrip!(unique, OP_CODESEPARATOR);
1029 roundtrip!(unique, OP_CHECKSIG);
1030 roundtrip!(unique, OP_CHECKSIGVERIFY);
1031 roundtrip!(unique, OP_CHECKMULTISIG);
1032 roundtrip!(unique, OP_CHECKMULTISIGVERIFY);
1033 roundtrip!(unique, OP_NOP1);
1034 roundtrip!(unique, OP_NOP2);
1035 roundtrip!(unique, OP_NOP3);
1036 roundtrip!(unique, OP_NOP4);
1037 roundtrip!(unique, OP_NOP5);
1038 roundtrip!(unique, OP_NOP6);
1039 roundtrip!(unique, OP_NOP7);
1040 roundtrip!(unique, OP_NOP8);
1041 roundtrip!(unique, OP_NOP9);
1042 roundtrip!(unique, OP_NOP10);
1043 roundtrip!(unique, OP_RETURN_186);
1044 roundtrip!(unique, OP_RETURN_187);
1045 roundtrip!(unique, OP_RETURN_188);
1046 roundtrip!(unique, OP_RETURN_189);
1047 roundtrip!(unique, OP_RETURN_190);
1048 roundtrip!(unique, OP_RETURN_191);
1049 roundtrip!(unique, OP_RETURN_192);
1050 roundtrip!(unique, OP_RETURN_193);
1051 roundtrip!(unique, OP_RETURN_194);
1052 roundtrip!(unique, OP_RETURN_195);
1053 roundtrip!(unique, OP_RETURN_196);
1054 roundtrip!(unique, OP_RETURN_197);
1055 roundtrip!(unique, OP_RETURN_198);
1056 roundtrip!(unique, OP_RETURN_199);
1057 roundtrip!(unique, OP_RETURN_200);
1058 roundtrip!(unique, OP_RETURN_201);
1059 roundtrip!(unique, OP_RETURN_202);
1060 roundtrip!(unique, OP_RETURN_203);
1061 roundtrip!(unique, OP_RETURN_204);
1062 roundtrip!(unique, OP_RETURN_205);
1063 roundtrip!(unique, OP_RETURN_206);
1064 roundtrip!(unique, OP_RETURN_207);
1065 roundtrip!(unique, OP_RETURN_208);
1066 roundtrip!(unique, OP_RETURN_209);
1067 roundtrip!(unique, OP_RETURN_210);
1068 roundtrip!(unique, OP_RETURN_211);
1069 roundtrip!(unique, OP_RETURN_212);
1070 roundtrip!(unique, OP_RETURN_213);
1071 roundtrip!(unique, OP_RETURN_214);
1072 roundtrip!(unique, OP_RETURN_215);
1073 roundtrip!(unique, OP_RETURN_216);
1074 roundtrip!(unique, OP_RETURN_217);
1075 roundtrip!(unique, OP_RETURN_218);
1076 roundtrip!(unique, OP_RETURN_219);
1077 roundtrip!(unique, OP_RETURN_220);
1078 roundtrip!(unique, OP_RETURN_221);
1079 roundtrip!(unique, OP_RETURN_222);
1080 roundtrip!(unique, OP_RETURN_223);
1081 roundtrip!(unique, OP_RETURN_224);
1082 roundtrip!(unique, OP_RETURN_225);
1083 roundtrip!(unique, OP_RETURN_226);
1084 roundtrip!(unique, OP_RETURN_227);
1085 roundtrip!(unique, OP_RETURN_228);
1086 roundtrip!(unique, OP_RETURN_229);
1087 roundtrip!(unique, OP_RETURN_230);
1088 roundtrip!(unique, OP_RETURN_231);
1089 roundtrip!(unique, OP_RETURN_232);
1090 roundtrip!(unique, OP_RETURN_233);
1091 roundtrip!(unique, OP_RETURN_234);
1092 roundtrip!(unique, OP_RETURN_235);
1093 roundtrip!(unique, OP_RETURN_236);
1094 roundtrip!(unique, OP_RETURN_237);
1095 roundtrip!(unique, OP_RETURN_238);
1096 roundtrip!(unique, OP_RETURN_239);
1097 roundtrip!(unique, OP_RETURN_240);
1098 roundtrip!(unique, OP_RETURN_241);
1099 roundtrip!(unique, OP_RETURN_242);
1100 roundtrip!(unique, OP_RETURN_243);
1101 roundtrip!(unique, OP_RETURN_244);
1102 roundtrip!(unique, OP_RETURN_245);
1103 roundtrip!(unique, OP_RETURN_246);
1104 roundtrip!(unique, OP_RETURN_247);
1105 roundtrip!(unique, OP_RETURN_248);
1106 roundtrip!(unique, OP_RETURN_249);
1107 roundtrip!(unique, OP_RETURN_250);
1108 roundtrip!(unique, OP_RETURN_251);
1109 roundtrip!(unique, OP_RETURN_252);
1110 roundtrip!(unique, OP_RETURN_253);
1111 roundtrip!(unique, OP_RETURN_254);
1112 roundtrip!(unique, OP_RETURN_255);
1113 assert_eq!(unique.len(), 256);
1114 }
1115}
1116