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