conflict in en.json

This commit is contained in:
Jonathan Rainville 2018-05-23 11:16:56 -04:00
parent 3e9376138b
commit 5f3361d030
10 changed files with 59 additions and 51 deletions

View File

@ -1,23 +1,25 @@
let __mainContext; // still needs to be run on a separate file due to the global context
var RunCode = require('./runCode.js');
class CodeRunner { class CodeRunner {
constructor(options) { constructor(options) {
this.plugins = options.plugins; this.plugins = options.plugins;
this.logger = options.logger; this.logger = options.logger;
this.events = options.events; this.events = options.events;
}
registerVar(varName, code) { // necessary to init the context
__mainContext[varName] = code; RunCode.initContext();
}
doEval(code) { this.events.on("runcode:register", (varName, code) => {
try { RunCode.registerVar(varName, code);
// TODO: add trace log here });
return eval(code);
} catch(e) { this.events.setCommandHandler('runcode:eval', (code, cb) => {
throw new Error(e + "\n" + code); let result = RunCode.doEval(code);
} if (cb) {
cb(null, result);
}
});
} }
} }

View File

@ -1,22 +1,16 @@
/*eslint no-unused-vars: off*/ /*eslint no-unused-vars: off*/
let Web3 = require('web3'); let __mainContext = this;
let web3;
let ipfs; function initContext() {
let __mainContext; doEval("__mainContext = this");
}
// ====================== // ======================
// the eval is used for evaluating some of the contact calls for different purposes // the eval is used for evaluating some of the contact calls for different purposes
// this should be at least moved to a different process and scope // this should be at least moved to a different process and scope
// for now it is defined here // for now it is defined here
// ====================== // ======================
function doEval(code, opts) { function doEval(code) {
if (opts && opts.web3) {
web3 = opts.web3;
}
if (opts && opts.ipfs) {
ipfs = opts.ipfs;
}
try { try {
// TODO: add trace log here // TODO: add trace log here
return eval(code); return eval(code);
@ -25,6 +19,12 @@ function doEval(code, opts) {
} }
} }
function registerVar(varName, code) {
__mainContext[varName] = code;
}
module.exports = { module.exports = {
doEval: doEval doEval: doEval,
registerVar: registerVar,
initContext: initContext
}; };

View File

@ -15,6 +15,7 @@ class Blockchain {
} }
this.registerServiceCheck(); this.registerServiceCheck();
this.registerRequests(); this.registerRequests();
this.registerWeb3Object();
} }
initWeb3() { initWeb3() {
@ -156,6 +157,11 @@ class Blockchain {
}); });
} }
registerWeb3Object() {
// doesn't feel quite right, should be a cmd or plugin method
// can just be a command without a callback
this.events.emit("runcode:register", "web3", this.web3);
}
} }
module.exports = Blockchain; module.exports = Blockchain;

View File

@ -2,8 +2,6 @@ let async = require('async');
//require("../utils/debug_util.js")(__filename, async); //require("../utils/debug_util.js")(__filename, async);
let utils = require('../utils/utils.js'); let utils = require('../utils/utils.js');
let RunCode = require('../coderunner/runCode.js');
class Deploy { class Deploy {
constructor(options) { constructor(options) {
this.blockchain = options.blockchain; this.blockchain = options.blockchain;
@ -129,7 +127,7 @@ class Deploy {
// TODO: can be moved into a afterDeploy event // TODO: can be moved into a afterDeploy event
// just need to figure out the gasLimit coupling issue // just need to figure out the gasLimit coupling issue
self.events.request('code-generator:contract:vanilla', contract, self.gasLimit, (contractCode) => { self.events.request('code-generator:contract:vanilla', contract, self.gasLimit, (contractCode) => {
RunCode.doEval(contractCode, {web3: self.web3}); self.events.request('runcode:eval', contractCode);
return callback(); return callback();
}); });
} }
@ -152,8 +150,7 @@ class Deploy {
// TODO: can be moved into a afterDeploy event // TODO: can be moved into a afterDeploy event
// just need to figure out the gasLimit coupling issue // just need to figure out the gasLimit coupling issue
self.events.request('code-generator:contract:vanilla', contract, self.gasLimit, (contractCode) => { self.events.request('code-generator:contract:vanilla', contract, self.gasLimit, (contractCode) => {
RunCode.doEval(contractCode, self.web3); self.events.request('runcode:eval', contractCode);
RunCode.doEval(contractCode, {web3: self.web3});
let onDeployPlugins = self.plugins.getPluginsProperty('onDeployActions', 'onDeployActions'); let onDeployPlugins = self.plugins.getPluginsProperty('onDeployActions', 'onDeployActions');

View File

@ -114,6 +114,7 @@ class Engine {
let services = { let services = {
"pipeline": this.pipelineService, "pipeline": this.pipelineService,
"codeRunner": this.codeRunnerService,
"codeGenerator": this.codeGeneratorService, "codeGenerator": this.codeGeneratorService,
"deployment": this.deploymentService, "deployment": this.deploymentService,
"fileWatcher": this.fileWatchService, "fileWatcher": this.fileWatchService,
@ -160,15 +161,17 @@ class Engine {
}); });
} }
codeRunnerService(_options) {
this.codeRunner = new CodeRunner({
plugins: this.plugins,
events: this.events,
logger: this.logger
});
}
codeGeneratorService(_options) { codeGeneratorService(_options) {
let self = this; let self = this;
this.codeRunner = new CodeRunner({
plugins: self.plugins,
events: self.events,
logger: self.logger
});
this.codeGenerator = new CodeGenerator({ this.codeGenerator = new CodeGenerator({
blockchainConfig: self.config.blockchainConfig, blockchainConfig: self.config.blockchainConfig,
contractsConfig: self.config.contractsConfig, contractsConfig: self.config.contractsConfig,

View File

@ -1,5 +1,4 @@
let utils = require('../utils/utils.js'); let utils = require('../utils/utils.js');
let RunCode = require('../coderunner/runCode.js');
class Console { class Console {
constructor(options) { constructor(options) {
@ -10,7 +9,7 @@ class Console {
} }
runCode(code) { runCode(code) {
RunCode.doEval(code); this.events.request('runcode:eval', code);
} }
processEmbarkCmd (cmd) { processEmbarkCmd (cmd) {
@ -48,8 +47,9 @@ class Console {
} }
try { try {
let result = RunCode.doEval(cmd); this.events.request('runcode:eval', cmd, (err, result) => {
return callback(result); callback(result);
});
} }
catch (e) { catch (e) {
if (e.message.indexOf('not defined') > 0) { if (e.message.indexOf('not defined') > 0) {

View File

@ -114,5 +114,7 @@
"Couldn't connect to an Ethereum node are you sure it's on?": "Couldn't connect to an Ethereum node are you sure it's on?", "Couldn't connect to an Ethereum node are you sure it's on?": "Couldn't connect to an Ethereum node are you sure it's on?",
"make sure you have an Ethereum node or simulator running. e.g '%s'": "make sure you have an Ethereum node or simulator running. e.g '%s'", "make sure you have an Ethereum node or simulator running. e.g '%s'": "make sure you have an Ethereum node or simulator running. e.g '%s'",
"Embark is building, please wait...": "Embark is building, please wait...", "Embark is building, please wait...": "Embark is building, please wait...",
"finished building DApp and deploying to": "finished building DApp and deploying to" "finished building DApp and deploying to": "finished building DApp and deploying to",
} "Type": "Type",
"to see the list of available commands": "to see the list of available commands"
}

View File

@ -128,6 +128,7 @@ class Embark {
engine.startMonitor(); engine.startMonitor();
engine.startService("libraryManager"); engine.startService("libraryManager");
engine.startService("codeRunner");
engine.startService("web3"); engine.startService("web3");
engine.startService("pipeline"); engine.startService("pipeline");
engine.startService("deployment"); engine.startService("deployment");
@ -202,6 +203,7 @@ class Embark {
} }
engine.startService("libraryManager"); engine.startService("libraryManager");
engine.startService("codeRunner");
engine.startService("web3"); engine.startService("web3");
engine.startService("pipeline"); engine.startService("pipeline");
engine.startService("deployment", {onlyCompile: options.onlyCompile}); engine.startService("deployment", {onlyCompile: options.onlyCompile});
@ -317,6 +319,7 @@ class Embark {
function startServices(callback) { function startServices(callback) {
engine.startService("libraryManager"); engine.startService("libraryManager");
engine.startService("codeRunner");
engine.startService("web3"); engine.startService("web3");
engine.startService("pipeline"); engine.startService("pipeline");
engine.startService("deployment"); engine.startService("deployment");

View File

@ -1,4 +1,3 @@
let RunCode = require('../../coderunner/runCode.js');
const stringReplaceAsync = require('string-replace-async'); const stringReplaceAsync = require('string-replace-async');
const async = require('async'); const async = require('async');
@ -64,9 +63,7 @@ class SpecialConfigs {
for(let cmd of onDeployCode) { for(let cmd of onDeployCode) {
self.logger.info("==== executing: " + cmd); self.logger.info("==== executing: " + cmd);
try { try {
// TODO: request and re-add web3 object if necessary self.events.request('runcode:eval', cmd);
//RunCode.doEval(cmd, self.blockchain.web3);
RunCode.doEval(cmd);
} catch(e) { } catch(e) {
if (e.message.indexOf("invalid opcode") >= 0) { if (e.message.indexOf("invalid opcode") >= 0) {
self.logger.error('the transaction was rejected; this usually happens due to a throw or a require, it can also happen due to an invalid operation'); self.logger.error('the transaction was rejected; this usually happens due to a throw or a require, it can also happen due to an invalid operation');
@ -103,9 +100,7 @@ class SpecialConfigs {
for(let cmd of onDeployCode) { for(let cmd of onDeployCode) {
self.logger.info("==== executing: " + cmd); self.logger.info("==== executing: " + cmd);
try { try {
// TODO: request and re-add web3 object if necessary self.events.request('runcode:eval', cmd);
//RunCode.doEval(cmd, self.blockchain.web3);
RunCode.doEval(cmd);
} catch(e) { } catch(e) {
if (e.message.indexOf("invalid opcode") >= 0) { if (e.message.indexOf("invalid opcode") >= 0) {
self.logger.error('the transaction was rejected; this usually happens due to a throw or a require, it can also happen due to an invalid operation'); self.logger.error('the transaction was rejected; this usually happens due to a throw or a require, it can also happen due to an invalid operation');

View File

@ -2,7 +2,6 @@ var async = require('async');
//require("../utils/debug_util.js")(__filename, async); //require("../utils/debug_util.js")(__filename, async);
var Web3 = require('web3'); var Web3 = require('web3');
var Engine = require('../core/engine.js'); var Engine = require('../core/engine.js');
var RunCode = require('../coderunner/runCode.js');
var TestLogger = require('./test_logger.js'); var TestLogger = require('./test_logger.js');
var getSimulator = function() { var getSimulator = function() {
@ -68,6 +67,7 @@ Test.prototype.deployAll = function(contractsConfig, cb) {
function startServices(callback) { function startServices(callback) {
//{abiType: 'contracts', embarkJS: false} //{abiType: 'contracts', embarkJS: false}
self.engine.startService("libraryManager"); self.engine.startService("libraryManager");
self.engine.startService("codeRunner");
self.engine.startService("web3", { self.engine.startService("web3", {
web3: self.web3 web3: self.web3
}); });
@ -106,7 +106,7 @@ Test.prototype.deployAll = function(contractsConfig, cb) {
throw new Error(err); throw new Error(err);
} }
self.web3.eth.defaultAccount = accounts[0]; self.web3.eth.defaultAccount = accounts[0];
RunCode.doEval(result, {web3: self.web3}); self.engine.events.request('runcode:eval', result);
//cb(); //cb();
cb(accounts); cb(accounts);
}); });