28 lines
635 B
JavaScript
28 lines
635 B
JavaScript
const vm = require('vm');
|
|
|
|
class RunCode {
|
|
constructor() {
|
|
this.context = Object.assign({}, global.this);
|
|
}
|
|
|
|
doEval(code) {
|
|
return vm.runInNewContext(code, this.context);
|
|
}
|
|
|
|
registerVar(varName, code) {
|
|
// TODO: Update all the code being dependent of web3
|
|
// To identify, look at the top of the file for something like:
|
|
// /*global web3*/
|
|
if (varName === 'web3') {
|
|
global.web3 = code;
|
|
}
|
|
this.context[varName] = code;
|
|
}
|
|
|
|
getWeb3Config() {
|
|
return {defaultAccount: this.context.web3.eth.defaultAccount, provider: this.context.web3.currentProvider};
|
|
}
|
|
}
|
|
|
|
module.exports = RunCode;
|