bsv-script 0.3.0

BSV Blockchain SDK - Script parsing, execution, and address handling
Documentation
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
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
//! Bitcoin script opcode definitions.
//!
//! All standard opcodes from OP_0 (0x00) through OP_INVALIDOPCODE (0xff).
//! Includes opcode-to-string and string-to-opcode mappings for ASM output,
//! plus utility functions for classifying opcodes.

// === Push value ===

/// Push an empty byte array (false/zero) onto the stack.
pub const OP_0: u8 = 0x00;
/// Push an empty byte array (false/zero) onto the stack. Alias for `OP_0`.
pub const OP_FALSE: u8 = 0x00;

// Direct data push opcodes: OP_DATA_1 through OP_DATA_75 push 1-75 bytes.

/// Push the next 1 byte onto the stack.
pub const OP_DATA_1: u8 = 0x01;
/// Push the next 2 bytes onto the stack.
pub const OP_DATA_2: u8 = 0x02;
/// Push the next 3 bytes onto the stack.
pub const OP_DATA_3: u8 = 0x03;
/// Push the next 4 bytes onto the stack.
pub const OP_DATA_4: u8 = 0x04;
/// Push the next 5 bytes onto the stack.
pub const OP_DATA_5: u8 = 0x05;
/// Push the next 6 bytes onto the stack.
pub const OP_DATA_6: u8 = 0x06;
/// Push the next 7 bytes onto the stack.
pub const OP_DATA_7: u8 = 0x07;
/// Push the next 8 bytes onto the stack.
pub const OP_DATA_8: u8 = 0x08;
/// Push the next 9 bytes onto the stack.
pub const OP_DATA_9: u8 = 0x09;
/// Push the next 10 bytes onto the stack.
pub const OP_DATA_10: u8 = 0x0a;
/// Push the next 11 bytes onto the stack.
pub const OP_DATA_11: u8 = 0x0b;
/// Push the next 12 bytes onto the stack.
pub const OP_DATA_12: u8 = 0x0c;
/// Push the next 13 bytes onto the stack.
pub const OP_DATA_13: u8 = 0x0d;
/// Push the next 14 bytes onto the stack.
pub const OP_DATA_14: u8 = 0x0e;
/// Push the next 15 bytes onto the stack.
pub const OP_DATA_15: u8 = 0x0f;
/// Push the next 16 bytes onto the stack.
pub const OP_DATA_16: u8 = 0x10;
/// Push the next 17 bytes onto the stack.
pub const OP_DATA_17: u8 = 0x11;
/// Push the next 18 bytes onto the stack.
pub const OP_DATA_18: u8 = 0x12;
/// Push the next 19 bytes onto the stack.
pub const OP_DATA_19: u8 = 0x13;
/// Push the next 20 bytes onto the stack.
pub const OP_DATA_20: u8 = 0x14;
/// Push the next 21 bytes onto the stack.
pub const OP_DATA_21: u8 = 0x15;
/// Push the next 22 bytes onto the stack.
pub const OP_DATA_22: u8 = 0x16;
/// Push the next 23 bytes onto the stack.
pub const OP_DATA_23: u8 = 0x17;
/// Push the next 24 bytes onto the stack.
pub const OP_DATA_24: u8 = 0x18;
/// Push the next 25 bytes onto the stack.
pub const OP_DATA_25: u8 = 0x19;
/// Push the next 26 bytes onto the stack.
pub const OP_DATA_26: u8 = 0x1a;
/// Push the next 27 bytes onto the stack.
pub const OP_DATA_27: u8 = 0x1b;
/// Push the next 28 bytes onto the stack.
pub const OP_DATA_28: u8 = 0x1c;
/// Push the next 29 bytes onto the stack.
pub const OP_DATA_29: u8 = 0x1d;
/// Push the next 30 bytes onto the stack.
pub const OP_DATA_30: u8 = 0x1e;
/// Push the next 31 bytes onto the stack.
pub const OP_DATA_31: u8 = 0x1f;
/// Push the next 32 bytes onto the stack.
pub const OP_DATA_32: u8 = 0x20;
/// Push the next 33 bytes onto the stack.
pub const OP_DATA_33: u8 = 0x21;
/// Push the next 34 bytes onto the stack.
pub const OP_DATA_34: u8 = 0x22;
/// Push the next 35 bytes onto the stack.
pub const OP_DATA_35: u8 = 0x23;
/// Push the next 36 bytes onto the stack.
pub const OP_DATA_36: u8 = 0x24;
/// Push the next 37 bytes onto the stack.
pub const OP_DATA_37: u8 = 0x25;
/// Push the next 38 bytes onto the stack.
pub const OP_DATA_38: u8 = 0x26;
/// Push the next 39 bytes onto the stack.
pub const OP_DATA_39: u8 = 0x27;
/// Push the next 40 bytes onto the stack.
pub const OP_DATA_40: u8 = 0x28;
/// Push the next 41 bytes onto the stack.
pub const OP_DATA_41: u8 = 0x29;
/// Push the next 42 bytes onto the stack.
pub const OP_DATA_42: u8 = 0x2a;
/// Push the next 43 bytes onto the stack.
pub const OP_DATA_43: u8 = 0x2b;
/// Push the next 44 bytes onto the stack.
pub const OP_DATA_44: u8 = 0x2c;
/// Push the next 45 bytes onto the stack.
pub const OP_DATA_45: u8 = 0x2d;
/// Push the next 46 bytes onto the stack.
pub const OP_DATA_46: u8 = 0x2e;
/// Push the next 47 bytes onto the stack.
pub const OP_DATA_47: u8 = 0x2f;
/// Push the next 48 bytes onto the stack.
pub const OP_DATA_48: u8 = 0x30;
/// Push the next 49 bytes onto the stack.
pub const OP_DATA_49: u8 = 0x31;
/// Push the next 50 bytes onto the stack.
pub const OP_DATA_50: u8 = 0x32;
/// Push the next 51 bytes onto the stack.
pub const OP_DATA_51: u8 = 0x33;
/// Push the next 52 bytes onto the stack.
pub const OP_DATA_52: u8 = 0x34;
/// Push the next 53 bytes onto the stack.
pub const OP_DATA_53: u8 = 0x35;
/// Push the next 54 bytes onto the stack.
pub const OP_DATA_54: u8 = 0x36;
/// Push the next 55 bytes onto the stack.
pub const OP_DATA_55: u8 = 0x37;
/// Push the next 56 bytes onto the stack.
pub const OP_DATA_56: u8 = 0x38;
/// Push the next 57 bytes onto the stack.
pub const OP_DATA_57: u8 = 0x39;
/// Push the next 58 bytes onto the stack.
pub const OP_DATA_58: u8 = 0x3a;
/// Push the next 59 bytes onto the stack.
pub const OP_DATA_59: u8 = 0x3b;
/// Push the next 60 bytes onto the stack.
pub const OP_DATA_60: u8 = 0x3c;
/// Push the next 61 bytes onto the stack.
pub const OP_DATA_61: u8 = 0x3d;
/// Push the next 62 bytes onto the stack.
pub const OP_DATA_62: u8 = 0x3e;
/// Push the next 63 bytes onto the stack.
pub const OP_DATA_63: u8 = 0x3f;
/// Push the next 64 bytes onto the stack.
pub const OP_DATA_64: u8 = 0x40;
/// Push the next 65 bytes onto the stack.
pub const OP_DATA_65: u8 = 0x41;
/// Push the next 66 bytes onto the stack.
pub const OP_DATA_66: u8 = 0x42;
/// Push the next 67 bytes onto the stack.
pub const OP_DATA_67: u8 = 0x43;
/// Push the next 68 bytes onto the stack.
pub const OP_DATA_68: u8 = 0x44;
/// Push the next 69 bytes onto the stack.
pub const OP_DATA_69: u8 = 0x45;
/// Push the next 70 bytes onto the stack.
pub const OP_DATA_70: u8 = 0x46;
/// Push the next 71 bytes onto the stack.
pub const OP_DATA_71: u8 = 0x47;
/// Push the next 72 bytes onto the stack.
pub const OP_DATA_72: u8 = 0x48;
/// Push the next 73 bytes onto the stack.
pub const OP_DATA_73: u8 = 0x49;
/// Push the next 74 bytes onto the stack.
pub const OP_DATA_74: u8 = 0x4a;
/// Push the next 75 bytes onto the stack.
pub const OP_DATA_75: u8 = 0x4b;

// Extended push data opcodes.

/// Read the next 1 byte as a length N, then push the next N bytes onto the stack.
pub const OP_PUSHDATA1: u8 = 0x4c;
/// Read the next 2 bytes as a little-endian length N, then push the next N bytes onto the stack.
pub const OP_PUSHDATA2: u8 = 0x4d;
/// Read the next 4 bytes as a little-endian length N, then push the next N bytes onto the stack.
pub const OP_PUSHDATA4: u8 = 0x4e;

/// Push the number -1 onto the stack.
pub const OP_1NEGATE: u8 = 0x4f;
/// Reserved opcode. Transaction is invalid if executed.
pub const OP_RESERVED: u8 = 0x50;
/// Base value for small integer opcodes (OP_1 through OP_16 = OP_BASE + N).
pub const OP_BASE: u8 = 0x50;
/// Push the number 1 onto the stack.
pub const OP_1: u8 = 0x51;
/// Push the number 1 onto the stack. Alias for `OP_1`.
pub const OP_TRUE: u8 = 0x51;
/// Push the number 2 onto the stack.
pub const OP_2: u8 = 0x52;
/// Push the number 3 onto the stack.
pub const OP_3: u8 = 0x53;
/// Push the number 4 onto the stack.
pub const OP_4: u8 = 0x54;
/// Push the number 5 onto the stack.
pub const OP_5: u8 = 0x55;
/// Push the number 6 onto the stack.
pub const OP_6: u8 = 0x56;
/// Push the number 7 onto the stack.
pub const OP_7: u8 = 0x57;
/// Push the number 8 onto the stack.
pub const OP_8: u8 = 0x58;
/// Push the number 9 onto the stack.
pub const OP_9: u8 = 0x59;
/// Push the number 10 onto the stack.
pub const OP_10: u8 = 0x5a;
/// Push the number 11 onto the stack.
pub const OP_11: u8 = 0x5b;
/// Push the number 12 onto the stack.
pub const OP_12: u8 = 0x5c;
/// Push the number 13 onto the stack.
pub const OP_13: u8 = 0x5d;
/// Push the number 14 onto the stack.
pub const OP_14: u8 = 0x5e;
/// Push the number 15 onto the stack.
pub const OP_15: u8 = 0x5f;
/// Push the number 16 onto the stack.
pub const OP_16: u8 = 0x60;

// === Flow control ===

/// Do nothing.
pub const OP_NOP: u8 = 0x61;
/// Reserved opcode. Transaction is invalid if executed.
pub const OP_VER: u8 = 0x62;
/// Execute the following statements if the top stack value is true (non-zero).
pub const OP_IF: u8 = 0x63;
/// Execute the following statements if the top stack value is false (zero).
pub const OP_NOTIF: u8 = 0x64;
/// Reserved opcode. Transaction is invalid even if not executed.
pub const OP_VERIF: u8 = 0x65;
/// Reserved opcode. Transaction is invalid even if not executed.
pub const OP_VERNOTIF: u8 = 0x66;
/// Execute the following statements if the preceding OP_IF/OP_NOTIF was not executed.
pub const OP_ELSE: u8 = 0x67;
/// End an if/else block.
pub const OP_ENDIF: u8 = 0x68;
/// Mark the transaction as invalid if the top stack value is false.
pub const OP_VERIFY: u8 = 0x69;
/// Mark the transaction output as unspendable (provably prunable).
pub const OP_RETURN: u8 = 0x6a;

// === Stack ===

/// Move the top stack item to the alt stack.
pub const OP_TOALTSTACK: u8 = 0x6b;
/// Move the top item from the alt stack to the main stack.
pub const OP_FROMALTSTACK: u8 = 0x6c;
/// Remove the top two stack items.
pub const OP_2DROP: u8 = 0x6d;
/// Duplicate the top two stack items.
pub const OP_2DUP: u8 = 0x6e;
/// Duplicate the top three stack items.
pub const OP_3DUP: u8 = 0x6f;
/// Copy the pair of items two spaces back to the front of the stack.
pub const OP_2OVER: u8 = 0x70;
/// Move the fifth and sixth items to the top of the stack.
pub const OP_2ROT: u8 = 0x71;
/// Swap the top two pairs of items on the stack.
pub const OP_2SWAP: u8 = 0x72;
/// Duplicate the top stack item if it is non-zero.
pub const OP_IFDUP: u8 = 0x73;
/// Push the number of items on the stack onto the stack.
pub const OP_DEPTH: u8 = 0x74;
/// Remove the top stack item.
pub const OP_DROP: u8 = 0x75;
/// Duplicate the top stack item.
pub const OP_DUP: u8 = 0x76;
/// Remove the second-to-top stack item.
pub const OP_NIP: u8 = 0x77;
/// Copy the second-to-top stack item to the top.
pub const OP_OVER: u8 = 0x78;
/// Copy the item N positions back in the stack to the top.
pub const OP_PICK: u8 = 0x79;
/// Move the item N positions back in the stack to the top.
pub const OP_ROLL: u8 = 0x7a;
/// Rotate the top three items on the stack (third item moves to top).
pub const OP_ROT: u8 = 0x7b;
/// Swap the top two stack items.
pub const OP_SWAP: u8 = 0x7c;
/// Copy the top stack item and insert it below the second-to-top item.
pub const OP_TUCK: u8 = 0x7d;

// === Splice ===

/// Concatenate the top two stack items.
pub const OP_CAT: u8 = 0x7e;
/// Split the second-to-top item at position given by the top item.
pub const OP_SPLIT: u8 = 0x7f;
/// Convert the top numeric value to a byte array of the specified length.
pub const OP_NUM2BIN: u8 = 0x80;
/// Convert a byte array to a numeric value.
pub const OP_BIN2NUM: u8 = 0x81;
/// Push the byte length of the top stack item (without popping it).
pub const OP_SIZE: u8 = 0x82;

// === Bitwise logic ===

/// Flip all bits of the top stack item.
pub const OP_INVERT: u8 = 0x83;
/// Bitwise AND of the top two stack items.
pub const OP_AND: u8 = 0x84;
/// Bitwise OR of the top two stack items.
pub const OP_OR: u8 = 0x85;
/// Bitwise XOR of the top two stack items.
pub const OP_XOR: u8 = 0x86;
/// Push 1 if the top two stack items are exactly equal, 0 otherwise.
pub const OP_EQUAL: u8 = 0x87;
/// Same as OP_EQUAL, then OP_VERIFY. Marks transaction invalid if not equal.
pub const OP_EQUALVERIFY: u8 = 0x88;
/// Reserved opcode. Transaction is invalid if executed.
pub const OP_RESERVED1: u8 = 0x89;
/// Reserved opcode. Transaction is invalid if executed.
pub const OP_RESERVED2: u8 = 0x8a;

// === Arithmetic ===

/// Add 1 to the top stack item.
pub const OP_1ADD: u8 = 0x8b;
/// Subtract 1 from the top stack item.
pub const OP_1SUB: u8 = 0x8c;
/// Multiply the top stack item by 2 (disabled).
pub const OP_2MUL: u8 = 0x8d;
/// Divide the top stack item by 2 (disabled).
pub const OP_2DIV: u8 = 0x8e;
/// Negate the top stack item (flip its sign).
pub const OP_NEGATE: u8 = 0x8f;
/// Replace the top stack item with its absolute value.
pub const OP_ABS: u8 = 0x90;
/// Push 1 if the top item is 0, push 0 otherwise.
pub const OP_NOT: u8 = 0x91;
/// Push 0 if the top item is 0, push 1 otherwise.
pub const OP_0NOTEQUAL: u8 = 0x92;
/// Pop two items, push their sum.
pub const OP_ADD: u8 = 0x93;
/// Pop two items, push the second minus the top.
pub const OP_SUB: u8 = 0x94;
/// Pop two items, push their product.
pub const OP_MUL: u8 = 0x95;
/// Pop two items, push the integer quotient of the second divided by the top.
pub const OP_DIV: u8 = 0x96;
/// Pop two items, push the remainder of the second divided by the top.
pub const OP_MOD: u8 = 0x97;
/// Left-shift the second item by the number of bits given by the top item.
pub const OP_LSHIFT: u8 = 0x98;
/// Right-shift the second item by the number of bits given by the top item.
pub const OP_RSHIFT: u8 = 0x99;
/// Push 1 if both top two items are non-zero, 0 otherwise.
pub const OP_BOOLAND: u8 = 0x9a;
/// Push 1 if either of the top two items is non-zero, 0 otherwise.
pub const OP_BOOLOR: u8 = 0x9b;
/// Push 1 if the top two items are numerically equal, 0 otherwise.
pub const OP_NUMEQUAL: u8 = 0x9c;
/// Same as OP_NUMEQUAL, then OP_VERIFY. Marks transaction invalid if not equal.
pub const OP_NUMEQUALVERIFY: u8 = 0x9d;
/// Push 1 if the top two items are not numerically equal, 0 otherwise.
pub const OP_NUMNOTEQUAL: u8 = 0x9e;
/// Push 1 if the second item is less than the top item, 0 otherwise.
pub const OP_LESSTHAN: u8 = 0x9f;
/// Push 1 if the second item is greater than the top item, 0 otherwise.
pub const OP_GREATERTHAN: u8 = 0xa0;
/// Push 1 if the second item is less than or equal to the top item, 0 otherwise.
pub const OP_LESSTHANOREQUAL: u8 = 0xa1;
/// Push 1 if the second item is greater than or equal to the top item, 0 otherwise.
pub const OP_GREATERTHANOREQUAL: u8 = 0xa2;
/// Push the smaller of the top two stack items.
pub const OP_MIN: u8 = 0xa3;
/// Push the larger of the top two stack items.
pub const OP_MAX: u8 = 0xa4;
/// Push 1 if the third item is within the range [second, top), 0 otherwise.
pub const OP_WITHIN: u8 = 0xa5;

// === Crypto ===

/// Hash the top item with RIPEMD-160.
pub const OP_RIPEMD160: u8 = 0xa6;
/// Hash the top item with SHA-1.
pub const OP_SHA1: u8 = 0xa7;
/// Hash the top item with SHA-256.
pub const OP_SHA256: u8 = 0xa8;
/// Hash the top item with SHA-256 then RIPEMD-160 (Bitcoin address hash).
pub const OP_HASH160: u8 = 0xa9;
/// Hash the top item with double SHA-256 (Bitcoin transaction hash).
pub const OP_HASH256: u8 = 0xaa;
/// Mark the beginning of signature-checked code.
pub const OP_CODESEPARATOR: u8 = 0xab;
/// Pop a public key and signature, push 1 if the signature is valid, 0 otherwise.
pub const OP_CHECKSIG: u8 = 0xac;
/// Same as OP_CHECKSIG, then OP_VERIFY. Marks transaction invalid if signature check fails.
pub const OP_CHECKSIGVERIFY: u8 = 0xad;
/// Pop N public keys and M signatures, push 1 if all signatures are valid, 0 otherwise.
pub const OP_CHECKMULTISIG: u8 = 0xae;
/// Same as OP_CHECKMULTISIG, then OP_VERIFY. Marks transaction invalid if check fails.
pub const OP_CHECKMULTISIGVERIFY: u8 = 0xaf;

// === Locktime ===

/// No operation (reserved for future soft-fork upgrades).
pub const OP_NOP1: u8 = 0xb0;
/// No operation (reserved for future soft-fork upgrades). Alias for OP_CHECKLOCKTIMEVERIFY in BTC.
pub const OP_NOP2: u8 = 0xb1;
/// Verify that the transaction locktime is at least the given value (BTC only, NOP in BSV).
pub const OP_CHECKLOCKTIMEVERIFY: u8 = 0xb1;
/// No operation (reserved for future soft-fork upgrades). Alias for OP_CHECKSEQUENCEVERIFY in BTC.
pub const OP_NOP3: u8 = 0xb2;
/// Verify that the input sequence number is at least the given value (BTC only, NOP in BSV).
pub const OP_CHECKSEQUENCEVERIFY: u8 = 0xb2;
/// No operation (reserved for future soft-fork upgrades).
pub const OP_NOP4: u8 = 0xb3;
/// No operation (reserved for future soft-fork upgrades).
pub const OP_NOP5: u8 = 0xb4;
/// No operation (reserved for future soft-fork upgrades).
pub const OP_NOP6: u8 = 0xb5;
/// No operation (reserved for future soft-fork upgrades).
pub const OP_NOP7: u8 = 0xb6;
/// No operation (reserved for future soft-fork upgrades).
pub const OP_NOP8: u8 = 0xb7;
/// No operation (reserved for future soft-fork upgrades).
pub const OP_NOP9: u8 = 0xb8;
/// No operation (reserved for future soft-fork upgrades).
pub const OP_NOP10: u8 = 0xb9;

// === Unknown / internal ===

/// Unknown opcode 186 (0xba). Undefined behavior.
pub const OP_UNKNOWN186: u8 = 0xba;
/// Unknown opcode 187 (0xbb). Undefined behavior.
pub const OP_UNKNOWN187: u8 = 0xbb;
/// Unknown opcode 188 (0xbc). Undefined behavior.
pub const OP_UNKNOWN188: u8 = 0xbc;
/// Unknown opcode 189 (0xbd). Undefined behavior.
pub const OP_UNKNOWN189: u8 = 0xbd;
/// Unknown opcode 190 (0xbe). Undefined behavior.
pub const OP_UNKNOWN190: u8 = 0xbe;
/// Unknown opcode 191 (0xbf). Undefined behavior.
pub const OP_UNKNOWN191: u8 = 0xbf;
/// Unknown opcode 192 (0xc0). Undefined behavior.
pub const OP_UNKNOWN192: u8 = 0xc0;
/// Unknown opcode 193 (0xc1). Undefined behavior.
pub const OP_UNKNOWN193: u8 = 0xc1;
/// Unknown opcode 194 (0xc2). Undefined behavior.
pub const OP_UNKNOWN194: u8 = 0xc2;
/// Unknown opcode 195 (0xc3). Undefined behavior.
pub const OP_UNKNOWN195: u8 = 0xc3;
/// Unknown opcode 196 (0xc4). Undefined behavior.
pub const OP_UNKNOWN196: u8 = 0xc4;
/// Unknown opcode 197 (0xc5). Undefined behavior.
pub const OP_UNKNOWN197: u8 = 0xc5;
/// Unknown opcode 198 (0xc6). Undefined behavior.
pub const OP_UNKNOWN198: u8 = 0xc6;
/// Unknown opcode 199 (0xc7). Undefined behavior.
pub const OP_UNKNOWN199: u8 = 0xc7;
/// Unknown opcode 200 (0xc8). Undefined behavior.
pub const OP_UNKNOWN200: u8 = 0xc8;
/// Unknown opcode 201 (0xc9). Undefined behavior.
pub const OP_UNKNOWN201: u8 = 0xc9;
/// Unknown opcode 202 (0xca). Undefined behavior.
pub const OP_UNKNOWN202: u8 = 0xca;
/// Unknown opcode 203 (0xcb). Undefined behavior.
pub const OP_UNKNOWN203: u8 = 0xcb;
/// Unknown opcode 204 (0xcc). Undefined behavior.
pub const OP_UNKNOWN204: u8 = 0xcc;
/// Unknown opcode 205 (0xcd). Undefined behavior.
pub const OP_UNKNOWN205: u8 = 0xcd;
/// Unknown opcode 206 (0xce). Undefined behavior.
pub const OP_UNKNOWN206: u8 = 0xce;
/// Unknown opcode 207 (0xcf). Undefined behavior.
pub const OP_UNKNOWN207: u8 = 0xcf;
/// Unknown opcode 208 (0xd0). Undefined behavior.
pub const OP_UNKNOWN208: u8 = 0xd0;
/// Unknown opcode 209 (0xd1). Undefined behavior.
pub const OP_UNKNOWN209: u8 = 0xd1;
/// Unknown opcode 210 (0xd2). Undefined behavior.
pub const OP_UNKNOWN210: u8 = 0xd2;
/// Unknown opcode 211 (0xd3). Undefined behavior.
pub const OP_UNKNOWN211: u8 = 0xd3;
/// Unknown opcode 212 (0xd4). Undefined behavior.
pub const OP_UNKNOWN212: u8 = 0xd4;
/// Unknown opcode 213 (0xd5). Undefined behavior.
pub const OP_UNKNOWN213: u8 = 0xd5;
/// Unknown opcode 214 (0xd6). Undefined behavior.
pub const OP_UNKNOWN214: u8 = 0xd6;
/// Unknown opcode 215 (0xd7). Undefined behavior.
pub const OP_UNKNOWN215: u8 = 0xd7;
/// Unknown opcode 216 (0xd8). Undefined behavior.
pub const OP_UNKNOWN216: u8 = 0xd8;
/// Unknown opcode 217 (0xd9). Undefined behavior.
pub const OP_UNKNOWN217: u8 = 0xd9;
/// Unknown opcode 218 (0xda). Undefined behavior.
pub const OP_UNKNOWN218: u8 = 0xda;
/// Unknown opcode 219 (0xdb). Undefined behavior.
pub const OP_UNKNOWN219: u8 = 0xdb;
/// Unknown opcode 220 (0xdc). Undefined behavior.
pub const OP_UNKNOWN220: u8 = 0xdc;
/// Unknown opcode 221 (0xdd). Undefined behavior.
pub const OP_UNKNOWN221: u8 = 0xdd;
/// Unknown opcode 222 (0xde). Undefined behavior.
pub const OP_UNKNOWN222: u8 = 0xde;
/// Unknown opcode 223 (0xdf). Undefined behavior.
pub const OP_UNKNOWN223: u8 = 0xdf;
/// Unknown opcode 224 (0xe0). Undefined behavior.
pub const OP_UNKNOWN224: u8 = 0xe0;
/// Unknown opcode 225 (0xe1). Undefined behavior.
pub const OP_UNKNOWN225: u8 = 0xe1;
/// Unknown opcode 226 (0xe2). Undefined behavior.
pub const OP_UNKNOWN226: u8 = 0xe2;
/// Unknown opcode 227 (0xe3). Undefined behavior.
pub const OP_UNKNOWN227: u8 = 0xe3;
/// Unknown opcode 228 (0xe4). Undefined behavior.
pub const OP_UNKNOWN228: u8 = 0xe4;
/// Unknown opcode 229 (0xe5). Undefined behavior.
pub const OP_UNKNOWN229: u8 = 0xe5;
/// Unknown opcode 230 (0xe6). Undefined behavior.
pub const OP_UNKNOWN230: u8 = 0xe6;
/// Unknown opcode 231 (0xe7). Undefined behavior.
pub const OP_UNKNOWN231: u8 = 0xe7;
/// Unknown opcode 232 (0xe8). Undefined behavior.
pub const OP_UNKNOWN232: u8 = 0xe8;
/// Unknown opcode 233 (0xe9). Undefined behavior.
pub const OP_UNKNOWN233: u8 = 0xe9;
/// Unknown opcode 234 (0xea). Undefined behavior.
pub const OP_UNKNOWN234: u8 = 0xea;
/// Unknown opcode 235 (0xeb). Undefined behavior.
pub const OP_UNKNOWN235: u8 = 0xeb;
/// Unknown opcode 236 (0xec). Undefined behavior.
pub const OP_UNKNOWN236: u8 = 0xec;
/// Unknown opcode 237 (0xed). Undefined behavior.
pub const OP_UNKNOWN237: u8 = 0xed;
/// Unknown opcode 238 (0xee). Undefined behavior.
pub const OP_UNKNOWN238: u8 = 0xee;
/// Unknown opcode 239 (0xef). Undefined behavior.
pub const OP_UNKNOWN239: u8 = 0xef;
/// Unknown opcode 240 (0xf0). Undefined behavior.
pub const OP_UNKNOWN240: u8 = 0xf0;
/// Unknown opcode 241 (0xf1). Undefined behavior.
pub const OP_UNKNOWN241: u8 = 0xf1;
/// Unknown opcode 242 (0xf2). Undefined behavior.
pub const OP_UNKNOWN242: u8 = 0xf2;
/// Unknown opcode 243 (0xf3). Undefined behavior.
pub const OP_UNKNOWN243: u8 = 0xf3;
/// Unknown opcode 244 (0xf4). Undefined behavior.
pub const OP_UNKNOWN244: u8 = 0xf4;
/// Unknown opcode 245 (0xf5). Undefined behavior.
pub const OP_UNKNOWN245: u8 = 0xf5;
/// Unknown opcode 246 (0xf6). Undefined behavior.
pub const OP_UNKNOWN246: u8 = 0xf6;
/// Unknown opcode 247 (0xf7). Undefined behavior.
pub const OP_UNKNOWN247: u8 = 0xf7;
/// Unknown opcode 248 (0xf8). Undefined behavior.
pub const OP_UNKNOWN248: u8 = 0xf8;
/// Unknown opcode 249 (0xf9). Undefined behavior.
pub const OP_UNKNOWN249: u8 = 0xf9;
/// Internal pseudo-opcode representing a small integer (used in template matching).
pub const OP_SMALLINTEGER: u8 = 0xfa;
/// Internal pseudo-opcode representing multiple public keys (used in template matching).
pub const OP_PUBKEYS: u8 = 0xfb;
/// Unknown opcode 252 (0xfc). Undefined behavior.
pub const OP_UNKNOWN252: u8 = 0xfc;
/// Internal pseudo-opcode representing a public key hash (used in template matching).
pub const OP_PUBKEYHASH: u8 = 0xfd;
/// Internal pseudo-opcode representing a public key (used in template matching).
pub const OP_PUBKEY: u8 = 0xfe;
/// Invalid opcode that always causes script failure.
pub const OP_INVALIDOPCODE: u8 = 0xff;

/// Convert an opcode byte value to its string representation for ASM output.
///
/// Returns the canonical OP_xxx name for known opcodes, or "OP_UNKNOWNxxx"
/// for unrecognized values.
///
/// # Arguments
/// * `op` - The opcode byte value.
///
/// # Returns
/// A static string slice with the opcode name.
pub fn opcode_to_string(op: u8) -> &'static str {
    match op {
        0x00 => "OP_FALSE",
        0x01 => "OP_DATA_1",
        0x02 => "OP_DATA_2",
        0x03 => "OP_DATA_3",
        0x04 => "OP_DATA_4",
        0x05 => "OP_DATA_5",
        0x06 => "OP_DATA_6",
        0x07 => "OP_DATA_7",
        0x08 => "OP_DATA_8",
        0x09 => "OP_DATA_9",
        0x0a => "OP_DATA_10",
        0x0b => "OP_DATA_11",
        0x0c => "OP_DATA_12",
        0x0d => "OP_DATA_13",
        0x0e => "OP_DATA_14",
        0x0f => "OP_DATA_15",
        0x10 => "OP_DATA_16",
        0x11 => "OP_DATA_17",
        0x12 => "OP_DATA_18",
        0x13 => "OP_DATA_19",
        0x14 => "OP_DATA_20",
        0x15 => "OP_DATA_21",
        0x16 => "OP_DATA_22",
        0x17 => "OP_DATA_23",
        0x18 => "OP_DATA_24",
        0x19 => "OP_DATA_25",
        0x1a => "OP_DATA_26",
        0x1b => "OP_DATA_27",
        0x1c => "OP_DATA_28",
        0x1d => "OP_DATA_29",
        0x1e => "OP_DATA_30",
        0x1f => "OP_DATA_31",
        0x20 => "OP_DATA_32",
        0x21 => "OP_DATA_33",
        0x22 => "OP_DATA_34",
        0x23 => "OP_DATA_35",
        0x24 => "OP_DATA_36",
        0x25 => "OP_DATA_37",
        0x26 => "OP_DATA_38",
        0x27 => "OP_DATA_39",
        0x28 => "OP_DATA_40",
        0x29 => "OP_DATA_41",
        0x2a => "OP_DATA_42",
        0x2b => "OP_DATA_43",
        0x2c => "OP_DATA_44",
        0x2d => "OP_DATA_45",
        0x2e => "OP_DATA_46",
        0x2f => "OP_DATA_47",
        0x30 => "OP_DATA_48",
        0x31 => "OP_DATA_49",
        0x32 => "OP_DATA_50",
        0x33 => "OP_DATA_51",
        0x34 => "OP_DATA_52",
        0x35 => "OP_DATA_53",
        0x36 => "OP_DATA_54",
        0x37 => "OP_DATA_55",
        0x38 => "OP_DATA_56",
        0x39 => "OP_DATA_57",
        0x3a => "OP_DATA_58",
        0x3b => "OP_DATA_59",
        0x3c => "OP_DATA_60",
        0x3d => "OP_DATA_61",
        0x3e => "OP_DATA_62",
        0x3f => "OP_DATA_63",
        0x40 => "OP_DATA_64",
        0x41 => "OP_DATA_65",
        0x42 => "OP_DATA_66",
        0x43 => "OP_DATA_67",
        0x44 => "OP_DATA_68",
        0x45 => "OP_DATA_69",
        0x46 => "OP_DATA_70",
        0x47 => "OP_DATA_71",
        0x48 => "OP_DATA_72",
        0x49 => "OP_DATA_73",
        0x4a => "OP_DATA_74",
        0x4b => "OP_DATA_75",
        0x4c => "OP_PUSHDATA1",
        0x4d => "OP_PUSHDATA2",
        0x4e => "OP_PUSHDATA4",
        0x4f => "OP_1NEGATE",
        0x50 => "OP_BASE",
        0x51 => "OP_TRUE",
        0x52 => "OP_2",
        0x53 => "OP_3",
        0x54 => "OP_4",
        0x55 => "OP_5",
        0x56 => "OP_6",
        0x57 => "OP_7",
        0x58 => "OP_8",
        0x59 => "OP_9",
        0x5a => "OP_10",
        0x5b => "OP_11",
        0x5c => "OP_12",
        0x5d => "OP_13",
        0x5e => "OP_14",
        0x5f => "OP_15",
        0x60 => "OP_16",
        0x61 => "OP_NOP",
        0x62 => "OP_VER",
        0x63 => "OP_IF",
        0x64 => "OP_NOTIF",
        0x65 => "OP_VERIF",
        0x66 => "OP_VERNOTIF",
        0x67 => "OP_ELSE",
        0x68 => "OP_ENDIF",
        0x69 => "OP_VERIFY",
        0x6a => "OP_RETURN",
        0x6b => "OP_TOALTSTACK",
        0x6c => "OP_FROMALTSTACK",
        0x6d => "OP_2DROP",
        0x6e => "OP_2DUP",
        0x6f => "OP_3DUP",
        0x70 => "OP_2OVER",
        0x71 => "OP_2ROT",
        0x72 => "OP_2SWAP",
        0x73 => "OP_IFDUP",
        0x74 => "OP_DEPTH",
        0x75 => "OP_DROP",
        0x76 => "OP_DUP",
        0x77 => "OP_NIP",
        0x78 => "OP_OVER",
        0x79 => "OP_PICK",
        0x7a => "OP_ROLL",
        0x7b => "OP_ROT",
        0x7c => "OP_SWAP",
        0x7d => "OP_TUCK",
        0x7e => "OP_CAT",
        0x7f => "OP_SPLIT",
        0x80 => "OP_NUM2BIN",
        0x81 => "OP_BIN2NUM",
        0x82 => "OP_SIZE",
        0x83 => "OP_INVERT",
        0x84 => "OP_AND",
        0x85 => "OP_OR",
        0x86 => "OP_XOR",
        0x87 => "OP_EQUAL",
        0x88 => "OP_EQUALVERIFY",
        0x89 => "OP_RESERVED1",
        0x8a => "OP_RESERVED2",
        0x8b => "OP_1ADD",
        0x8c => "OP_1SUB",
        0x8d => "OP_2MUL",
        0x8e => "OP_2DIV",
        0x8f => "OP_NEGATE",
        0x90 => "OP_ABS",
        0x91 => "OP_NOT",
        0x92 => "OP_0NOTEQUAL",
        0x93 => "OP_ADD",
        0x94 => "OP_SUB",
        0x95 => "OP_MUL",
        0x96 => "OP_DIV",
        0x97 => "OP_MOD",
        0x98 => "OP_LSHIFT",
        0x99 => "OP_RSHIFT",
        0x9a => "OP_BOOLAND",
        0x9b => "OP_BOOLOR",
        0x9c => "OP_NUMEQUAL",
        0x9d => "OP_NUMEQUALVERIFY",
        0x9e => "OP_NUMNOTEQUAL",
        0x9f => "OP_LESSTHAN",
        0xa0 => "OP_GREATERTHAN",
        0xa1 => "OP_LESSTHANOREQUAL",
        0xa2 => "OP_GREATERTHANOREQUAL",
        0xa3 => "OP_MIN",
        0xa4 => "OP_MAX",
        0xa5 => "OP_WITHIN",
        0xa6 => "OP_RIPEMD160",
        0xa7 => "OP_SHA1",
        0xa8 => "OP_SHA256",
        0xa9 => "OP_HASH160",
        0xaa => "OP_HASH256",
        0xab => "OP_CODESEPARATOR",
        0xac => "OP_CHECKSIG",
        0xad => "OP_CHECKSIGVERIFY",
        0xae => "OP_CHECKMULTISIG",
        0xaf => "OP_CHECKMULTISIGVERIFY",
        0xb0 => "OP_NOP1",
        0xb1 => "OP_NOP2",
        0xb2 => "OP_NOP3",
        0xb3 => "OP_NOP4",
        0xb4 => "OP_NOP5",
        0xb5 => "OP_NOP6",
        0xb6 => "OP_NOP7",
        0xb7 => "OP_NOP8",
        0xb8 => "OP_NOP9",
        0xb9 => "OP_NOP10",
        0xba => "OP_UNKNOWN186",
        0xbb => "OP_UNKNOWN187",
        0xbc => "OP_UNKNOWN188",
        0xbd => "OP_UNKNOWN189",
        0xbe => "OP_UNKNOWN190",
        0xbf => "OP_UNKNOWN191",
        0xc0 => "OP_UNKNOWN192",
        0xc1 => "OP_UNKNOWN193",
        0xc2 => "OP_UNKNOWN194",
        0xc3 => "OP_UNKNOWN195",
        0xc4 => "OP_UNKNOWN196",
        0xc5 => "OP_UNKNOWN197",
        0xc6 => "OP_UNKNOWN198",
        0xc7 => "OP_UNKNOWN199",
        0xc8 => "OP_UNKNOWN200",
        0xc9 => "OP_UNKNOWN201",
        0xca => "OP_UNKNOWN202",
        0xcb => "OP_UNKNOWN203",
        0xcc => "OP_UNKNOWN204",
        0xcd => "OP_UNKNOWN205",
        0xce => "OP_UNKNOWN206",
        0xcf => "OP_UNKNOWN207",
        0xd0 => "OP_UNKNOWN208",
        0xd1 => "OP_UNKNOWN209",
        0xd2 => "OP_UNKNOWN210",
        0xd3 => "OP_UNKNOWN211",
        0xd4 => "OP_UNKNOWN212",
        0xd5 => "OP_UNKNOWN213",
        0xd6 => "OP_UNKNOWN214",
        0xd7 => "OP_UNKNOWN215",
        0xd8 => "OP_UNKNOWN216",
        0xd9 => "OP_UNKNOWN217",
        0xda => "OP_UNKNOWN218",
        0xdb => "OP_UNKNOWN219",
        0xdc => "OP_UNKNOWN220",
        0xdd => "OP_UNKNOWN221",
        0xde => "OP_UNKNOWN222",
        0xdf => "OP_UNKNOWN223",
        0xe0 => "OP_UNKNOWN224",
        0xe1 => "OP_UNKNOWN225",
        0xe2 => "OP_UNKNOWN226",
        0xe3 => "OP_UNKNOWN227",
        0xe4 => "OP_UNKNOWN228",
        0xe5 => "OP_UNKNOWN229",
        0xe6 => "OP_UNKNOWN230",
        0xe7 => "OP_UNKNOWN231",
        0xe8 => "OP_UNKNOWN232",
        0xe9 => "OP_UNKNOWN233",
        0xea => "OP_UNKNOWN234",
        0xeb => "OP_UNKNOWN235",
        0xec => "OP_UNKNOWN236",
        0xed => "OP_UNKNOWN237",
        0xee => "OP_UNKNOWN238",
        0xef => "OP_UNKNOWN239",
        0xf0 => "OP_UNKNOWN240",
        0xf1 => "OP_UNKNOWN241",
        0xf2 => "OP_UNKNOWN242",
        0xf3 => "OP_UNKNOWN243",
        0xf4 => "OP_UNKNOWN244",
        0xf5 => "OP_UNKNOWN245",
        0xf6 => "OP_UNKNOWN246",
        0xf7 => "OP_UNKNOWN247",
        0xf8 => "OP_UNKNOWN248",
        0xf9 => "OP_UNKNOWN249",
        0xfa => "OP_SMALLINTEGER",
        0xfb => "OP_PUBKEYS",
        0xfc => "OP_UNKNOWN252",
        0xfd => "OP_PUBKEYHASH",
        0xfe => "OP_PUBKEY",
        0xff => "OP_INVALIDOPCODE",
    }
}

/// Convert an opcode name string to its byte value.
///
/// Supports all canonical names including aliases (e.g. OP_0, OP_ZERO, OP_FALSE
/// all map to 0x00).
///
/// # Arguments
/// * `name` - The opcode name (e.g. "OP_DUP", "OP_CHECKSIG").
///
/// # Returns
/// `Some(byte)` if the name is recognized, `None` otherwise.
pub fn string_to_opcode(name: &str) -> Option<u8> {
    match name {
        "OP_0" | "OP_ZERO" | "OP_FALSE" => Some(OP_0),
        "OP_DATA_1" => Some(0x01),
        "OP_DATA_2" => Some(0x02),
        "OP_DATA_3" => Some(0x03),
        "OP_DATA_4" => Some(0x04),
        "OP_DATA_5" => Some(0x05),
        "OP_DATA_6" => Some(0x06),
        "OP_DATA_7" => Some(0x07),
        "OP_DATA_8" => Some(0x08),
        "OP_DATA_9" => Some(0x09),
        "OP_DATA_10" => Some(0x0a),
        "OP_DATA_11" => Some(0x0b),
        "OP_DATA_12" => Some(0x0c),
        "OP_DATA_13" => Some(0x0d),
        "OP_DATA_14" => Some(0x0e),
        "OP_DATA_15" => Some(0x0f),
        "OP_DATA_16" => Some(0x10),
        "OP_DATA_17" => Some(0x11),
        "OP_DATA_18" => Some(0x12),
        "OP_DATA_19" => Some(0x13),
        "OP_DATA_20" => Some(0x14),
        "OP_DATA_21" => Some(0x15),
        "OP_DATA_22" => Some(0x16),
        "OP_DATA_23" => Some(0x17),
        "OP_DATA_24" => Some(0x18),
        "OP_DATA_25" => Some(0x19),
        "OP_DATA_26" => Some(0x1a),
        "OP_DATA_27" => Some(0x1b),
        "OP_DATA_28" => Some(0x1c),
        "OP_DATA_29" => Some(0x1d),
        "OP_DATA_30" => Some(0x1e),
        "OP_DATA_31" => Some(0x1f),
        "OP_DATA_32" => Some(0x20),
        "OP_DATA_33" => Some(0x21),
        "OP_DATA_34" => Some(0x22),
        "OP_DATA_35" => Some(0x23),
        "OP_DATA_36" => Some(0x24),
        "OP_DATA_37" => Some(0x25),
        "OP_DATA_38" => Some(0x26),
        "OP_DATA_39" => Some(0x27),
        "OP_DATA_40" => Some(0x28),
        "OP_DATA_41" => Some(0x29),
        "OP_DATA_42" => Some(0x2a),
        "OP_DATA_43" => Some(0x2b),
        "OP_DATA_44" => Some(0x2c),
        "OP_DATA_45" => Some(0x2d),
        "OP_DATA_46" => Some(0x2e),
        "OP_DATA_47" => Some(0x2f),
        "OP_DATA_48" => Some(0x30),
        "OP_DATA_49" => Some(0x31),
        "OP_DATA_50" => Some(0x32),
        "OP_DATA_51" => Some(0x33),
        "OP_DATA_52" => Some(0x34),
        "OP_DATA_53" => Some(0x35),
        "OP_DATA_54" => Some(0x36),
        "OP_DATA_55" => Some(0x37),
        "OP_DATA_56" => Some(0x38),
        "OP_DATA_57" => Some(0x39),
        "OP_DATA_58" => Some(0x3a),
        "OP_DATA_59" => Some(0x3b),
        "OP_DATA_60" => Some(0x3c),
        "OP_DATA_61" => Some(0x3d),
        "OP_DATA_62" => Some(0x3e),
        "OP_DATA_63" => Some(0x3f),
        "OP_DATA_64" => Some(0x40),
        "OP_DATA_65" => Some(0x41),
        "OP_DATA_66" => Some(0x42),
        "OP_DATA_67" => Some(0x43),
        "OP_DATA_68" => Some(0x44),
        "OP_DATA_69" => Some(0x45),
        "OP_DATA_70" => Some(0x46),
        "OP_DATA_71" => Some(0x47),
        "OP_DATA_72" => Some(0x48),
        "OP_DATA_73" => Some(0x49),
        "OP_DATA_74" => Some(0x4a),
        "OP_DATA_75" => Some(0x4b),
        "OP_PUSHDATA1" => Some(OP_PUSHDATA1),
        "OP_PUSHDATA2" => Some(OP_PUSHDATA2),
        "OP_PUSHDATA4" => Some(OP_PUSHDATA4),
        "OP_1NEGATE" => Some(OP_1NEGATE),
        "OP_RESERVED" | "OP_BASE" => Some(OP_RESERVED),
        "OP_1" | "OP_ONE" | "OP_TRUE" => Some(OP_1),
        "OP_2" => Some(OP_2),
        "OP_3" => Some(OP_3),
        "OP_4" => Some(OP_4),
        "OP_5" => Some(OP_5),
        "OP_6" => Some(OP_6),
        "OP_7" => Some(OP_7),
        "OP_8" => Some(OP_8),
        "OP_9" => Some(OP_9),
        "OP_10" => Some(OP_10),
        "OP_11" => Some(OP_11),
        "OP_12" => Some(OP_12),
        "OP_13" => Some(OP_13),
        "OP_14" => Some(OP_14),
        "OP_15" => Some(OP_15),
        "OP_16" => Some(OP_16),
        "OP_NOP" => Some(OP_NOP),
        "OP_VER" => Some(OP_VER),
        "OP_IF" => Some(OP_IF),
        "OP_NOTIF" => Some(OP_NOTIF),
        "OP_VERIF" => Some(OP_VERIF),
        "OP_VERNOTIF" => Some(OP_VERNOTIF),
        "OP_ELSE" => Some(OP_ELSE),
        "OP_ENDIF" => Some(OP_ENDIF),
        "OP_VERIFY" => Some(OP_VERIFY),
        "OP_RETURN" => Some(OP_RETURN),
        "OP_TOALTSTACK" => Some(OP_TOALTSTACK),
        "OP_FROMALTSTACK" => Some(OP_FROMALTSTACK),
        "OP_2DROP" => Some(OP_2DROP),
        "OP_2DUP" => Some(OP_2DUP),
        "OP_3DUP" => Some(OP_3DUP),
        "OP_2OVER" => Some(OP_2OVER),
        "OP_2ROT" => Some(OP_2ROT),
        "OP_2SWAP" => Some(OP_2SWAP),
        "OP_IFDUP" => Some(OP_IFDUP),
        "OP_DEPTH" => Some(OP_DEPTH),
        "OP_DROP" => Some(OP_DROP),
        "OP_DUP" => Some(OP_DUP),
        "OP_NIP" => Some(OP_NIP),
        "OP_OVER" => Some(OP_OVER),
        "OP_PICK" => Some(OP_PICK),
        "OP_ROLL" => Some(OP_ROLL),
        "OP_ROT" => Some(OP_ROT),
        "OP_SWAP" => Some(OP_SWAP),
        "OP_TUCK" => Some(OP_TUCK),
        "OP_CAT" => Some(OP_CAT),
        "OP_SPLIT" => Some(OP_SPLIT),
        "OP_NUM2BIN" | "OP_LEFT" => Some(OP_NUM2BIN),
        "OP_BIN2NUM" | "OP_RIGHT" => Some(OP_BIN2NUM),
        "OP_SIZE" => Some(OP_SIZE),
        "OP_INVERT" => Some(OP_INVERT),
        "OP_AND" => Some(OP_AND),
        "OP_OR" => Some(OP_OR),
        "OP_XOR" => Some(OP_XOR),
        "OP_EQUAL" => Some(OP_EQUAL),
        "OP_EQUALVERIFY" => Some(OP_EQUALVERIFY),
        "OP_RESERVED1" => Some(OP_RESERVED1),
        "OP_RESERVED2" => Some(OP_RESERVED2),
        "OP_1ADD" => Some(OP_1ADD),
        "OP_1SUB" => Some(OP_1SUB),
        "OP_2MUL" => Some(OP_2MUL),
        "OP_2DIV" => Some(OP_2DIV),
        "OP_NEGATE" => Some(OP_NEGATE),
        "OP_ABS" => Some(OP_ABS),
        "OP_NOT" => Some(OP_NOT),
        "OP_0NOTEQUAL" => Some(OP_0NOTEQUAL),
        "OP_ADD" => Some(OP_ADD),
        "OP_SUB" => Some(OP_SUB),
        "OP_MUL" => Some(OP_MUL),
        "OP_DIV" => Some(OP_DIV),
        "OP_MOD" => Some(OP_MOD),
        "OP_LSHIFT" => Some(OP_LSHIFT),
        "OP_RSHIFT" => Some(OP_RSHIFT),
        "OP_BOOLAND" => Some(OP_BOOLAND),
        "OP_BOOLOR" => Some(OP_BOOLOR),
        "OP_NUMEQUAL" => Some(OP_NUMEQUAL),
        "OP_NUMEQUALVERIFY" => Some(OP_NUMEQUALVERIFY),
        "OP_NUMNOTEQUAL" => Some(OP_NUMNOTEQUAL),
        "OP_LESSTHAN" => Some(OP_LESSTHAN),
        "OP_GREATERTHAN" => Some(OP_GREATERTHAN),
        "OP_LESSTHANOREQUAL" => Some(OP_LESSTHANOREQUAL),
        "OP_GREATERTHANOREQUAL" => Some(OP_GREATERTHANOREQUAL),
        "OP_MIN" => Some(OP_MIN),
        "OP_MAX" => Some(OP_MAX),
        "OP_WITHIN" => Some(OP_WITHIN),
        "OP_RIPEMD160" => Some(OP_RIPEMD160),
        "OP_SHA1" => Some(OP_SHA1),
        "OP_SHA256" => Some(OP_SHA256),
        "OP_HASH160" => Some(OP_HASH160),
        "OP_HASH256" => Some(OP_HASH256),
        "OP_CODESEPARATOR" => Some(OP_CODESEPARATOR),
        "OP_CHECKSIG" => Some(OP_CHECKSIG),
        "OP_CHECKSIGVERIFY" => Some(OP_CHECKSIGVERIFY),
        "OP_CHECKMULTISIG" => Some(OP_CHECKMULTISIG),
        "OP_CHECKMULTISIGVERIFY" => Some(OP_CHECKMULTISIGVERIFY),
        "OP_NOP1" => Some(OP_NOP1),
        "OP_NOP2" => Some(OP_NOP2),
        "OP_NOP3" => Some(OP_NOP3),
        "OP_NOP4" => Some(OP_NOP4),
        "OP_NOP5" => Some(OP_NOP5),
        "OP_NOP6" => Some(OP_NOP6),
        "OP_NOP7" => Some(OP_NOP7),
        "OP_NOP8" => Some(OP_NOP8),
        "OP_NOP9" => Some(OP_NOP9),
        "OP_NOP10" => Some(OP_NOP10),
        "OP_UNKNOWN186" => Some(OP_UNKNOWN186),
        "OP_UNKNOWN187" => Some(OP_UNKNOWN187),
        "OP_UNKNOWN188" => Some(OP_UNKNOWN188),
        "OP_UNKNOWN189" => Some(OP_UNKNOWN189),
        "OP_UNKNOWN190" => Some(OP_UNKNOWN190),
        "OP_UNKNOWN191" => Some(OP_UNKNOWN191),
        "OP_UNKNOWN192" => Some(OP_UNKNOWN192),
        "OP_UNKNOWN193" => Some(OP_UNKNOWN193),
        "OP_UNKNOWN194" => Some(OP_UNKNOWN194),
        "OP_UNKNOWN195" => Some(OP_UNKNOWN195),
        "OP_UNKNOWN196" => Some(OP_UNKNOWN196),
        "OP_UNKNOWN197" => Some(OP_UNKNOWN197),
        "OP_UNKNOWN198" => Some(OP_UNKNOWN198),
        "OP_UNKNOWN199" => Some(OP_UNKNOWN199),
        "OP_UNKNOWN200" => Some(OP_UNKNOWN200),
        "OP_UNKNOWN201" => Some(OP_UNKNOWN201),
        "OP_UNKNOWN202" => Some(OP_UNKNOWN202),
        "OP_UNKNOWN203" => Some(OP_UNKNOWN203),
        "OP_UNKNOWN204" => Some(OP_UNKNOWN204),
        "OP_UNKNOWN205" => Some(OP_UNKNOWN205),
        "OP_UNKNOWN206" => Some(OP_UNKNOWN206),
        "OP_UNKNOWN207" => Some(OP_UNKNOWN207),
        "OP_UNKNOWN208" => Some(OP_UNKNOWN208),
        "OP_UNKNOWN209" => Some(OP_UNKNOWN209),
        "OP_UNKNOWN210" => Some(OP_UNKNOWN210),
        "OP_UNKNOWN211" => Some(OP_UNKNOWN211),
        "OP_UNKNOWN212" => Some(OP_UNKNOWN212),
        "OP_UNKNOWN213" => Some(OP_UNKNOWN213),
        "OP_UNKNOWN214" => Some(OP_UNKNOWN214),
        "OP_UNKNOWN215" => Some(OP_UNKNOWN215),
        "OP_UNKNOWN216" => Some(OP_UNKNOWN216),
        "OP_UNKNOWN217" => Some(OP_UNKNOWN217),
        "OP_UNKNOWN218" => Some(OP_UNKNOWN218),
        "OP_UNKNOWN219" => Some(OP_UNKNOWN219),
        "OP_UNKNOWN220" => Some(OP_UNKNOWN220),
        "OP_UNKNOWN221" => Some(OP_UNKNOWN221),
        "OP_UNKNOWN222" => Some(OP_UNKNOWN222),
        "OP_UNKNOWN223" => Some(OP_UNKNOWN223),
        "OP_UNKNOWN224" => Some(OP_UNKNOWN224),
        "OP_UNKNOWN225" => Some(OP_UNKNOWN225),
        "OP_UNKNOWN226" => Some(OP_UNKNOWN226),
        "OP_UNKNOWN227" => Some(OP_UNKNOWN227),
        "OP_UNKNOWN228" => Some(OP_UNKNOWN228),
        "OP_UNKNOWN229" => Some(OP_UNKNOWN229),
        "OP_UNKNOWN230" => Some(OP_UNKNOWN230),
        "OP_UNKNOWN231" => Some(OP_UNKNOWN231),
        "OP_UNKNOWN232" => Some(OP_UNKNOWN232),
        "OP_UNKNOWN233" => Some(OP_UNKNOWN233),
        "OP_UNKNOWN234" => Some(OP_UNKNOWN234),
        "OP_UNKNOWN235" => Some(OP_UNKNOWN235),
        "OP_UNKNOWN236" => Some(OP_UNKNOWN236),
        "OP_UNKNOWN237" => Some(OP_UNKNOWN237),
        "OP_UNKNOWN238" => Some(OP_UNKNOWN238),
        "OP_UNKNOWN239" => Some(OP_UNKNOWN239),
        "OP_UNKNOWN240" => Some(OP_UNKNOWN240),
        "OP_UNKNOWN241" => Some(OP_UNKNOWN241),
        "OP_UNKNOWN242" => Some(OP_UNKNOWN242),
        "OP_UNKNOWN243" => Some(OP_UNKNOWN243),
        "OP_UNKNOWN244" => Some(OP_UNKNOWN244),
        "OP_UNKNOWN245" => Some(OP_UNKNOWN245),
        "OP_UNKNOWN246" => Some(OP_UNKNOWN246),
        "OP_UNKNOWN247" => Some(OP_UNKNOWN247),
        "OP_UNKNOWN248" => Some(OP_UNKNOWN248),
        "OP_UNKNOWN249" => Some(OP_UNKNOWN249),
        "OP_SMALLINTEGER" => Some(OP_SMALLINTEGER),
        "OP_PUBKEYS" => Some(OP_PUBKEYS),
        "OP_UNKNOWN252" => Some(OP_UNKNOWN252),
        "OP_PUBKEYHASH" => Some(OP_PUBKEYHASH),
        "OP_PUBKEY" => Some(OP_PUBKEY),
        "OP_INVALIDOPCODE" => Some(OP_INVALIDOPCODE),
        _ => None,
    }
}

/// Check if an opcode represents a small integer (OP_0 or OP_1..OP_16).
///
/// # Arguments
/// * `op` - The opcode byte value.
///
/// # Returns
/// `true` if the opcode pushes a small integer (0-16) onto the stack.
pub fn is_small_int_op(op: u8) -> bool {
    op == OP_0 || (op >= OP_1 && op <= OP_16)
}

/// Check if an opcode is a push data opcode (OP_DATA_1..OP_PUSHDATA4).
///
/// # Arguments
/// * `op` - The opcode byte value.
///
/// # Returns
/// `true` if the opcode pushes data onto the stack.
pub fn is_push_data(op: u8) -> bool {
    op >= OP_DATA_1 && op <= OP_PUSHDATA4
}