-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathScriptOpCodes.java
More file actions
278 lines (272 loc) · 11.1 KB
/
ScriptOpCodes.java
File metadata and controls
278 lines (272 loc) · 11.1 KB
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
/*
* Copyright 2013 Google Inc.
* Copyright 2013 Ronald W Hoffman
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package JavaBitcoin;
import java.util.HashMap;
import java.util.Map;
/**
* Various constants that define the assembly-like scripting language that forms part of the Bitcoin protocol.
*/
public class ScriptOpCodes {
// push value
public static final int OP_0 = 0x00;
public static final int OP_FALSE = OP_0;
public static final int OP_PUSHDATA1 = 0x4c;
public static final int OP_PUSHDATA2 = 0x4d;
public static final int OP_PUSHDATA4 = 0x4e;
public static final int OP_1NEGATE = 0x4f;
public static final int OP_RESERVED = 0x50;
public static final int OP_1 = 0x51;
public static final int OP_TRUE = OP_1;
public static final int OP_2 = 0x52;
public static final int OP_3 = 0x53;
public static final int OP_4 = 0x54;
public static final int OP_5 = 0x55;
public static final int OP_6 = 0x56;
public static final int OP_7 = 0x57;
public static final int OP_8 = 0x58;
public static final int OP_9 = 0x59;
public static final int OP_10 = 0x5a;
public static final int OP_11 = 0x5b;
public static final int OP_12 = 0x5c;
public static final int OP_13 = 0x5d;
public static final int OP_14 = 0x5e;
public static final int OP_15 = 0x5f;
public static final int OP_16 = 0x60;
// control
public static final int OP_NOP = 0x61;
public static final int OP_VER = 0x62;
public static final int OP_IF = 0x63;
public static final int OP_NOTIF = 0x64;
public static final int OP_VERIF = 0x65;
public static final int OP_VERNOTIF = 0x66;
public static final int OP_ELSE = 0x67;
public static final int OP_ENDIF = 0x68;
public static final int OP_VERIFY = 0x69;
public static final int OP_RETURN = 0x6a;
// stack ops
public static final int OP_TOALTSTACK = 0x6b;
public static final int OP_FROMALTSTACK = 0x6c;
public static final int OP_2DROP = 0x6d;
public static final int OP_2DUP = 0x6e;
public static final int OP_3DUP = 0x6f;
public static final int OP_2OVER = 0x70;
public static final int OP_2ROT = 0x71;
public static final int OP_2SWAP = 0x72;
public static final int OP_IFDUP = 0x73;
public static final int OP_DEPTH = 0x74;
public static final int OP_DROP = 0x75;
public static final int OP_DUP = 0x76;
public static final int OP_NIP = 0x77;
public static final int OP_OVER = 0x78;
public static final int OP_PICK = 0x79;
public static final int OP_ROLL = 0x7a;
public static final int OP_ROT = 0x7b;
public static final int OP_SWAP = 0x7c;
public static final int OP_TUCK = 0x7d;
// splice ops
public static final int OP_CAT = 0x7e;
public static final int OP_SUBSTR = 0x7f;
public static final int OP_LEFT = 0x80;
public static final int OP_RIGHT = 0x81;
public static final int OP_SIZE = 0x82;
// bit logic
public static final int OP_INVERT = 0x83;
public static final int OP_AND = 0x84;
public static final int OP_OR = 0x85;
public static final int OP_XOR = 0x86;
public static final int OP_EQUAL = 0x87;
public static final int OP_EQUALVERIFY = 0x88;
public static final int OP_RESERVED1 = 0x89;
public static final int OP_RESERVED2 = 0x8a;
// numeric
public static final int OP_1ADD = 0x8b;
public static final int OP_1SUB = 0x8c;
public static final int OP_2MUL = 0x8d;
public static final int OP_2DIV = 0x8e;
public static final int OP_NEGATE = 0x8f;
public static final int OP_ABS = 0x90;
public static final int OP_NOT = 0x91;
public static final int OP_0NOTEQUAL = 0x92;
public static final int OP_ADD = 0x93;
public static final int OP_SUB = 0x94;
public static final int OP_MUL = 0x95;
public static final int OP_DIV = 0x96;
public static final int OP_MOD = 0x97;
public static final int OP_LSHIFT = 0x98;
public static final int OP_RSHIFT = 0x99;
public static final int OP_BOOLAND = 0x9a;
public static final int OP_BOOLOR = 0x9b;
public static final int OP_NUMEQUAL = 0x9c;
public static final int OP_NUMEQUALVERIFY = 0x9d;
public static final int OP_NUMNOTEQUAL = 0x9e;
public static final int OP_LESSTHAN = 0x9f;
public static final int OP_GREATERTHAN = 0xa0;
public static final int OP_LESSTHANOREQUAL = 0xa1;
public static final int OP_GREATERTHANOREQUAL = 0xa2;
public static final int OP_MIN = 0xa3;
public static final int OP_MAX = 0xa4;
public static final int OP_WITHIN = 0xa5;
// crypto
public static final int OP_RIPEMD160 = 0xa6;
public static final int OP_SHA1 = 0xa7;
public static final int OP_SHA256 = 0xa8;
public static final int OP_HASH160 = 0xa9;
public static final int OP_HASH256 = 0xaa;
public static final int OP_CODESEPARATOR = 0xab;
public static final int OP_CHECKSIG = 0xac;
public static final int OP_CHECKSIGVERIFY = 0xad;
public static final int OP_CHECKMULTISIG = 0xae;
public static final int OP_CHECKMULTISIGVERIFY = 0xaf;
// expansion
public static final int OP_NOP1 = 0xb0;
public static final int OP_NOP2 = 0xb1;
public static final int OP_NOP3 = 0xb2;
public static final int OP_NOP4 = 0xb3;
public static final int OP_NOP5 = 0xb4;
public static final int OP_NOP6 = 0xb5;
public static final int OP_NOP7 = 0xb6;
public static final int OP_NOP8 = 0xb7;
public static final int OP_NOP9 = 0xb8;
public static final int OP_NOP10 = 0xb9;
public static final int OP_INVALIDOPCODE = 0xff;
private static final Map<Integer, String> opCodeMap = new HashMap<>(125);
static {
opCodeMap.put(OP_0, "0");
opCodeMap.put(OP_PUSHDATA1, "PUSHDATA1");
opCodeMap.put(OP_PUSHDATA2, "PUSHDATA2");
opCodeMap.put(OP_PUSHDATA4, "PUSHDATA4");
opCodeMap.put(OP_1NEGATE, "1NEGATE");
opCodeMap.put(OP_RESERVED, "RESERVED");
opCodeMap.put(OP_1, "1");
opCodeMap.put(OP_2, "2");
opCodeMap.put(OP_3, "3");
opCodeMap.put(OP_4, "4");
opCodeMap.put(OP_5, "5");
opCodeMap.put(OP_6, "6");
opCodeMap.put(OP_7, "7");
opCodeMap.put(OP_8, "8");
opCodeMap.put(OP_9, "9");
opCodeMap.put(OP_10, "10");
opCodeMap.put(OP_11, "11");
opCodeMap.put(OP_12, "12");
opCodeMap.put(OP_13, "13");
opCodeMap.put(OP_14, "14");
opCodeMap.put(OP_15, "15");
opCodeMap.put(OP_16, "16");
opCodeMap.put(OP_NOP, "NOP");
opCodeMap.put(OP_VER, "VER");
opCodeMap.put(OP_IF, "IF");
opCodeMap.put(OP_NOTIF, "NOTIF");
opCodeMap.put(OP_VERIF, "VERIF");
opCodeMap.put(OP_VERNOTIF, "VERNOTIF");
opCodeMap.put(OP_ELSE, "ELSE");
opCodeMap.put(OP_ENDIF, "ENDIF");
opCodeMap.put(OP_VERIFY, "VERIFY");
opCodeMap.put(OP_RETURN, "RETURN");
opCodeMap.put(OP_TOALTSTACK, "TOALTSTACK");
opCodeMap.put(OP_FROMALTSTACK, "FROMALTSTACK");
opCodeMap.put(OP_2DROP, "2DROP");
opCodeMap.put(OP_2DUP, "2DUP");
opCodeMap.put(OP_3DUP, "3DUP");
opCodeMap.put(OP_2OVER, "2OVER");
opCodeMap.put(OP_2ROT, "2ROT");
opCodeMap.put(OP_2SWAP, "2SWAP");
opCodeMap.put(OP_IFDUP, "IFDUP");
opCodeMap.put(OP_DEPTH, "DEPTH");
opCodeMap.put(OP_DROP, "DROP");
opCodeMap.put(OP_DUP, "DUP");
opCodeMap.put(OP_NIP, "NIP");
opCodeMap.put(OP_OVER, "OVER");
opCodeMap.put(OP_PICK, "PICK");
opCodeMap.put(OP_ROLL, "ROLL");
opCodeMap.put(OP_ROT, "ROT");
opCodeMap.put(OP_SWAP, "SWAP");
opCodeMap.put(OP_TUCK, "TUCK");
opCodeMap.put(OP_CAT, "CAT");
opCodeMap.put(OP_SUBSTR, "SUBSTR");
opCodeMap.put(OP_LEFT, "LEFT");
opCodeMap.put(OP_RIGHT, "RIGHT");
opCodeMap.put(OP_SIZE, "SIZE");
opCodeMap.put(OP_INVERT, "INVERT");
opCodeMap.put(OP_AND, "AND");
opCodeMap.put(OP_OR, "OR");
opCodeMap.put(OP_XOR, "XOR");
opCodeMap.put(OP_EQUAL, "EQUAL");
opCodeMap.put(OP_EQUALVERIFY, "EQUALVERIFY");
opCodeMap.put(OP_RESERVED1, "RESERVED1");
opCodeMap.put(OP_RESERVED2, "RESERVED2");
opCodeMap.put(OP_1ADD, "1ADD");
opCodeMap.put(OP_1SUB, "1SUB");
opCodeMap.put(OP_2MUL, "2MUL");
opCodeMap.put(OP_2DIV, "2DIV");
opCodeMap.put(OP_NEGATE, "NEGATE");
opCodeMap.put(OP_ABS, "ABS");
opCodeMap.put(OP_NOT, "NOT");
opCodeMap.put(OP_0NOTEQUAL, "0NOTEQUAL");
opCodeMap.put(OP_ADD, "ADD");
opCodeMap.put(OP_SUB, "SUB");
opCodeMap.put(OP_MUL, "MUL");
opCodeMap.put(OP_DIV, "DIV");
opCodeMap.put(OP_MOD, "MOD");
opCodeMap.put(OP_LSHIFT, "LSHIFT");
opCodeMap.put(OP_RSHIFT, "RSHIFT");
opCodeMap.put(OP_BOOLAND, "BOOLAND");
opCodeMap.put(OP_BOOLOR, "BOOLOR");
opCodeMap.put(OP_NUMEQUAL, "NUMEQUAL");
opCodeMap.put(OP_NUMEQUALVERIFY, "NUMEQUALVERIFY");
opCodeMap.put(OP_NUMNOTEQUAL, "NUMNOTEQUAL");
opCodeMap.put(OP_LESSTHAN, "LESSTHAN");
opCodeMap.put(OP_GREATERTHAN, "GREATERTHAN");
opCodeMap.put(OP_LESSTHANOREQUAL, "LESSTHANOREQUAL");
opCodeMap.put(OP_GREATERTHANOREQUAL, "GREATERTHANOREQUAL");
opCodeMap.put(OP_MIN, "MIN");
opCodeMap.put(OP_MAX, "MAX");
opCodeMap.put(OP_WITHIN, "WITHIN");
opCodeMap.put(OP_RIPEMD160, "RIPEMD160");
opCodeMap.put(OP_SHA1, "SHA1");
opCodeMap.put(OP_SHA256, "SHA256");
opCodeMap.put(OP_HASH160, "HASH160");
opCodeMap.put(OP_HASH256, "HASH256");
opCodeMap.put(OP_CODESEPARATOR, "CODESEPARATOR");
opCodeMap.put(OP_CHECKSIG, "CHECKSIG");
opCodeMap.put(OP_CHECKSIGVERIFY, "CHECKSIGVERIFY");
opCodeMap.put(OP_CHECKMULTISIG, "CHECKMULTISIG");
opCodeMap.put(OP_CHECKMULTISIGVERIFY, "CHECKMULTISIGVERIFY");
opCodeMap.put(OP_NOP1, "NOP1");
opCodeMap.put(OP_NOP2, "NOP2");
opCodeMap.put(OP_NOP3, "NOP3");
opCodeMap.put(OP_NOP4, "NOP4");
opCodeMap.put(OP_NOP5, "NOP5");
opCodeMap.put(OP_NOP6, "NOP6");
opCodeMap.put(OP_NOP7, "NOP7");
opCodeMap.put(OP_NOP8, "NOP8");
opCodeMap.put(OP_NOP9, "NOP9");
opCodeMap.put(OP_NOP10, "NOP10");
}
/**
* Converts the given OpCode into a string (eg "0", "PUSHDATA", or "NON_OP(10)")
*
* @param opCode OpCode
* @return String result
*/
public static String getOpCodeName(byte opCode) {
int opcode = opCode & 0xff;
if (opCodeMap.containsKey(opcode))
return opCodeMap.get(opcode);
return "NON_OP(" + opcode + ")";
}
}