Skip to content

Commit 305cab5

Browse files
committed
wip: remove REVERSE_OPS and add check if the chunk is a valid opcode string in OPS
1 parent 13089db commit 305cab5

File tree

7 files changed

+13
-13
lines changed

7 files changed

+13
-13
lines changed

src/cjs/ops.cjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22
Object.defineProperty(exports, '__esModule', { value: true });
3-
exports.REVERSE_OPS = exports.OPS = void 0;
3+
exports.OPS = void 0;
44
// Define OPS enum
55
var OPS;
66
(function (OPS) {
@@ -123,4 +123,4 @@ var OPS;
123123
OPS[(OPS['OP_PUBKEYHASH'] = 253)] = 'OP_PUBKEYHASH';
124124
OPS[(OPS['OP_PUBKEY'] = 254)] = 'OP_PUBKEY';
125125
OPS[(OPS['OP_INVALIDOPCODE'] = 255)] = 'OP_INVALIDOPCODE';
126-
})(OPS || (exports.REVERSE_OPS = exports.OPS = OPS = {}));
126+
})(OPS || (exports.OPS = OPS = {}));

src/cjs/ops.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,4 @@ declare enum OPS {
119119
OP_PUBKEY = 254,
120120
OP_INVALIDOPCODE = 255
121121
}
122-
export { OPS, OPS as REVERSE_OPS };
122+
export { OPS };

src/cjs/script.cjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ function toASM(chunks) {
209209
chunk = op;
210210
}
211211
// opcode!
212-
return ops_js_1.REVERSE_OPS[chunk];
212+
return ops_js_1.OPS[chunk];
213213
})
214214
.join(' ');
215215
}
@@ -224,7 +224,7 @@ function fromASM(asm) {
224224
return compile(
225225
asm.split(' ').map(chunk => {
226226
// Check if the chunk is an opcode
227-
if (chunk in ops_js_1.OPS) {
227+
if (isNaN(Number(chunk)) && chunk in ops_js_1.OPS) {
228228
return ops_js_1.OPS[chunk];
229229
}
230230
// Validate if the chunk is a hexadecimal string

src/esm/ops.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,4 @@ var OPS;
122122
OPS[(OPS['OP_INVALIDOPCODE'] = 255)] = 'OP_INVALIDOPCODE';
123123
})(OPS || (OPS = {}));
124124
// Export modules
125-
export { OPS, OPS as REVERSE_OPS };
125+
export { OPS };

src/esm/script.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @packageDocumentation
44
*/
55
import * as bip66 from './bip66.js';
6-
import { OPS, REVERSE_OPS } from './ops.js';
6+
import { OPS } from './ops.js';
77
import * as pushdata from './push_data.js';
88
import * as scriptNumber from './script_number.js';
99
import * as scriptSignature from './script_signature.js';
@@ -147,7 +147,7 @@ export function toASM(chunks) {
147147
chunk = op;
148148
}
149149
// opcode!
150-
return REVERSE_OPS[chunk];
150+
return OPS[chunk];
151151
})
152152
.join(' ');
153153
}
@@ -162,7 +162,7 @@ export function fromASM(asm) {
162162
return compile(
163163
asm.split(' ').map(chunk => {
164164
// Check if the chunk is an opcode
165-
if (chunk in OPS) {
165+
if (isNaN(Number(chunk)) && chunk in OPS) {
166166
return OPS[chunk];
167167
}
168168
// Validate if the chunk is a hexadecimal string

ts_src/ops.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,4 @@ enum OPS {
136136
}
137137

138138
// Export modules
139-
export { OPS, OPS as REVERSE_OPS };
139+
export { OPS };

ts_src/script.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @packageDocumentation
44
*/
55
import * as bip66 from './bip66.js';
6-
import { OPS, REVERSE_OPS } from './ops.js';
6+
import { OPS } from './ops.js';
77
import { Stack } from './payments/index.js';
88
import * as pushdata from './push_data.js';
99
import * as scriptNumber from './script_number.js';
@@ -187,7 +187,7 @@ export function toASM(chunks: Uint8Array | Array<number | Uint8Array>): string {
187187
}
188188

189189
// opcode!
190-
return REVERSE_OPS[chunk];
190+
return OPS[chunk];
191191
})
192192
.join(' ');
193193
}
@@ -204,7 +204,7 @@ export function fromASM(asm: string): Uint8Array {
204204
return compile(
205205
asm.split(' ').map((chunk: string): number | Uint8Array => {
206206
// Check if the chunk is an opcode
207-
if (chunk in OPS) {
207+
if (isNaN(Number(chunk)) && chunk in OPS) {
208208
return OPS[chunk as keyof typeof OPS];
209209
}
210210

0 commit comments

Comments
 (0)