Skip to content

Commit

Permalink
0.3.2 (#75)
Browse files Browse the repository at this point in the history
* ignore fs & child_process in browser env

* use BigInt function over literals to allow third party using bable / uglifyjs etc.

Ref: bcoin-org/bcrypto#33

* add timeout option for compile function

* bump version to 0.3.2
  • Loading branch information
freedomhero authored and catdev2024 committed Mar 19, 2021
1 parent bbfdd12 commit 49b29e6
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
{
"name": "scryptlib",
"version": "0.3.1",
"version": "0.3.2",
"description": "Javascript SDK for integration of Bitcoin SV Smart Contracts written in sCrypt language.",
"engines": {
"node": ">=12.0.0"
},
"main": "dist/index.js",
"types": "dist",
"browser": {
"child_process": false,
"fs": false
},
"scripts": {
"compile": "tsc -b",
"watch": "tsc -b -w",
Expand Down
5 changes: 3 additions & 2 deletions src/compilerWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,25 +138,26 @@ export function compile(
cmdArgs?: string,
sourceMap?: boolean,
optimize?: boolean,
timeout?: number // in ms
} = {
asm: true,
debug: true,
optimize: false,
}
): CompileResult {
const st = Date.now();
const npxArg = settings.npxArgs || '--no-install';
const sourcePath = source.path;
const srcDir = dirname(sourcePath);
const curWorkingDir = settings.cwd || srcDir;
const sourceFileName = basename(sourcePath);
const outputDir = settings.outputDir || srcDir;
const timeout = settings.timeout || 1200000;
const outputFiles = {};
try {
const sourceContent = source.content !== undefined ? source.content : readFileSync(sourcePath, 'utf8');
const cmdPrefix = settings.cmdPrefix || getDefaultScryptc();
const cmd = `${cmdPrefix} compile ${settings.asm || settings.desc ? '--asm' : ''} ${settings.ast || settings.desc ? '--ast' : ''} ${settings.debug == false ? '' : '--debug'} ${settings.optimize ? '--opt' : ''} -r -o "${outputDir}" ${settings.cmdArgs ? settings.cmdArgs : ''}`;
let output = execSync(cmd, { input: sourceContent, cwd: curWorkingDir }).toString();
let output = execSync(cmd, { input: sourceContent, cwd: curWorkingDir, timeout }).toString();
// Because the output of the compiler on the win32 platform uses crlf as a newline, here we change \r\n to \n. make SYNTAX_ERR_REG、SEMANTIC_ERR_REG、IMPORT_ERR_REG work.
output = output.split(/\r?\n/g).join('\n');
if (output.startsWith('Error:')) {
Expand Down
8 changes: 4 additions & 4 deletions src/serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ class OpState {

toBigInt() : bigint {
if (this.op.opcodenum === Opcode.OP_1) {
return 1n;
return BigInt(1);
} else if (this.op.opcodenum === Opcode.OP_0) {
return 0n;
return BigInt(0);
} else if (this.op.opcodenum === Opcode.OP_1NEGATE) {
return -1n;
return BigInt(-1);
} else if (this.op.opcodenum >= Opcode.OP_2 && this.op.opcodenum <= Opcode.OP_16) {
return BigInt(this.op.opcodenum - Opcode.OP_2 + 2);
} else {
Expand All @@ -115,7 +115,7 @@ class OpState {
}

toBoolean() : boolean {
return this.toBigInt() !== 0n;
return this.toBigInt() !== BigInt(0);
}

toHex() : string {
Expand Down

0 comments on commit 49b29e6

Please sign in to comment.