mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-04-22 18:28:01 +00:00
Add web worker compatibility
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
|
||||
importScripts('./soljson.js');
|
||||
importScripts('./resolc.js');
|
||||
|
||||
// Handle messages from the main thread
|
||||
onmessage = async function (e) {
|
||||
const contractCode = e.data.contractCode
|
||||
const sourceCode = {
|
||||
language: 'Solidity',
|
||||
sources: {
|
||||
contract: {
|
||||
content: contractCode,
|
||||
}
|
||||
},
|
||||
settings: {
|
||||
optimizer: {
|
||||
enabled: true,
|
||||
runs: 200,
|
||||
},
|
||||
outputSelection: {
|
||||
'*': {
|
||||
'*': ['abi'],
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
const m = createRevive();
|
||||
|
||||
m.soljson = Module;
|
||||
|
||||
// Set input data for stdin
|
||||
m.setStdinData(JSON.stringify(sourceCode));
|
||||
|
||||
var stdoutString = "";
|
||||
m.setStdoutCallback(function(char) {
|
||||
if (char.charCodeAt(0) === '\n') {
|
||||
console.log("new line")
|
||||
exit
|
||||
}
|
||||
stdoutString += char;
|
||||
});
|
||||
|
||||
var stderrString = "";
|
||||
m.setStderrCallback(function(char) {
|
||||
stderrString += char;
|
||||
});
|
||||
|
||||
// Compile the Solidity source code
|
||||
m.callMain(['--standard-json']);
|
||||
|
||||
postMessage({output: stdoutString || stderrString});
|
||||
};
|
||||
Reference in New Issue
Block a user