mirror of
https://github.com/status-im/embark-area-51.git
synced 2025-02-15 08:47:05 +00:00
move code runner to core modules
This commit is contained in:
parent
34061a6b44
commit
78db7bba1c
@ -5,6 +5,7 @@ const utils = require('../utils/utils');
|
|||||||
|
|
||||||
const WEB3_READY = 'web3Ready';
|
const WEB3_READY = 'web3Ready';
|
||||||
|
|
||||||
|
// TODO: consider another name, this is the blockchain connector
|
||||||
class Blockchain {
|
class Blockchain {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
const self = this;
|
const self = this;
|
||||||
|
@ -6,50 +6,27 @@ class CodeRunner {
|
|||||||
this.plugins = options.plugins;
|
this.plugins = options.plugins;
|
||||||
this.logger = options.logger;
|
this.logger = options.logger;
|
||||||
this.events = options.events;
|
this.events = options.events;
|
||||||
this.ipc = options.ipc;
|
|
||||||
this.commands = [];
|
|
||||||
let self = this;
|
|
||||||
// necessary to init the context
|
// necessary to init the context
|
||||||
RunCode.initContext();
|
RunCode.initContext();
|
||||||
|
|
||||||
if (this.ipc.isServer()) {
|
|
||||||
this.ipc.on('runcode:getCommands', (_err, callback) => {
|
|
||||||
let result = {web3Config: RunCode.getWeb3Config(), commands: self.commands};
|
|
||||||
callback(null, result);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.ipc.isClient() && this.ipc.connected) {
|
|
||||||
this.ipc.listenTo('runcode:newCommand', function (command) {
|
|
||||||
if (command.varName) {
|
|
||||||
self.events.emit("runcode:register", command.varName, command.code);
|
|
||||||
} else {
|
|
||||||
self.events.request("runcode:eval", command.code);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
this.events.on("runcode:register", (varName, code) => {
|
this.events.on("runcode:register", (varName, code) => {
|
||||||
if (self.ipc.isServer() && varName !== 'web3') {
|
|
||||||
self.commands.push({varName, code});
|
|
||||||
self.ipc.broadcast("runcode:newCommand", {varName, code});
|
|
||||||
}
|
|
||||||
RunCode.registerVar(varName, code);
|
RunCode.registerVar(varName, code);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.events.setCommandHandler('runcode:eval', (code, cb, forConsoleOnly = false) => {
|
this.events.setCommandHandler('runcode:eval', (code, cb) => {
|
||||||
if (!cb) {
|
if (!cb) {
|
||||||
cb = function() {};
|
cb = function() {};
|
||||||
}
|
}
|
||||||
let result = RunCode.doEval(code);
|
try {
|
||||||
if (forConsoleOnly && self.ipc.isServer()) {
|
let result = RunCode.doEval(code);
|
||||||
self.commands.push({code});
|
cb(null, result);
|
||||||
self.ipc.broadcast("runcode:newCommand", {code});
|
} catch (e) {
|
||||||
|
cb(e);
|
||||||
}
|
}
|
||||||
cb(null, result);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = CodeRunner;
|
module.exports = CodeRunner;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user