diff --git a/cmd/cmd_controller.js b/cmd/cmd_controller.js index b9819b78e..305d6ea28 100644 --- a/cmd/cmd_controller.js +++ b/cmd/cmd_controller.js @@ -279,6 +279,7 @@ class EmbarkController { engine.startService("storage"); engine.startService("codeGenerator"); engine.startService("webServer"); + engine.startService("namingSystem"); return callback(); } @@ -315,6 +316,7 @@ class EmbarkController { if(engine.ipc.connected && engine.ipc.isClient()) { return callback(); } + engine.config.reloadConfig(); engine.events.request('deploy:contracts', function (err) { callback(err); }); diff --git a/lib/core/config.js b/lib/core/config.js index eacff5268..fb95558e4 100644 --- a/lib/core/config.js +++ b/lib/core/config.js @@ -63,10 +63,7 @@ Config.prototype.loadConfigFiles = function(options) { this.loadStorageConfigFile(); this.loadCommunicationConfigFile(); this.loadNameSystemConfigFile(); - - this.loadContractsConfigFile(); this.loadPipelineConfigFile(); - this.loadContractsConfigFile(); this.loadExternalContractsFiles(); this.loadWebServerConfigFile(); @@ -82,7 +79,6 @@ Config.prototype.reloadConfig = function() { this.loadStorageConfigFile(); this.loadCommunicationConfigFile(); this.loadNameSystemConfigFile(); - this.loadContractsConfigFile(); this.loadPipelineConfigFile(); this.loadContractsConfigFile(); this.loadExternalContractsFiles(); diff --git a/lib/core/modules/coderunner/codeRunner.js b/lib/core/modules/coderunner/codeRunner.js index 728918b61..951e6c541 100644 --- a/lib/core/modules/coderunner/codeRunner.js +++ b/lib/core/modules/coderunner/codeRunner.js @@ -1,5 +1,9 @@ const RunCode = require('./runCode.js'); const EmbarkJS = require('embarkjs'); +const IpfsApi = require('ipfs-api'); +const Web3 = require('web3'); +const namehash = require('eth-ens-namehash'); + class CodeRunner { constructor(options) { this.plugins = options.plugins; @@ -26,6 +30,9 @@ class CodeRunner { } }); } else { + this.runCode.registerVar('IpfsApi', IpfsApi); + this.runCode.registerVar('Web3', Web3); + this.runCode.registerVar('namehash', namehash); this.runCode.registerVar('EmbarkJS', EmbarkJS); this.events.on('code-generator-ready', () => { this.events.request('code-generator:embarkjs:initialization-code', (code) => { diff --git a/lib/core/modules/coderunner/runCode.js b/lib/core/modules/coderunner/runCode.js index 0ce3fd1f4..d3c422a28 100644 --- a/lib/core/modules/coderunner/runCode.js +++ b/lib/core/modules/coderunner/runCode.js @@ -9,7 +9,7 @@ class RunCode { try { return vm.runInNewContext(code, this.context); } catch(e) { - console.log(e) + console.log(e.message) } } @@ -19,6 +19,8 @@ class RunCode { // /*global web3*/ if (varName === 'web3') { global.web3 = code; + } else if (varName === 'namehash') { + global.namehash = code; } this.context[varName] = code; } diff --git a/lib/modules/code_generator/index.js b/lib/modules/code_generator/index.js index 3dfe8d61a..3e01c1f64 100644 --- a/lib/modules/code_generator/index.js +++ b/lib/modules/code_generator/index.js @@ -350,17 +350,23 @@ class CodeGenerator { code += plugin.embarkjs_code.join('\n'); } + const codeTypes = {'communication': this.communicationConfig, + 'names': this.namesystemConfig, + 'storage': this.storageConfig}; + let initCodes = this.plugins.getPluginsFor('initCode'); for (let plugin of initCodes) { - let initCodes = plugin.embarkjs_init_code['communication'] || []; - for (let initCode of initCodes) { - let [block, shouldInit] = initCode; - if (shouldInit.call(plugin, this.communicationConfig)) { - code += block; + for (let codeTypeName of Object.keys(codeTypes)) { + let initCodes = plugin.embarkjs_init_code[codeTypeName] || []; + for (let initCode of initCodes) { + let [block, shouldInit] = initCode; + if (shouldInit.call(plugin, codeTypes[codeTypeName])) { + code += block; + } } } } - + return code; } diff --git a/lib/modules/ens/index.js b/lib/modules/ens/index.js index 9455e2a73..1cae88a3f 100644 --- a/lib/modules/ens/index.js +++ b/lib/modules/ens/index.js @@ -307,7 +307,6 @@ class ENS { } addSetProvider(config) { - let code = "\nEmbarkJS.Names.setProvider('ens'," + JSON.stringify(config) + ");"; let shouldInit = (namesConfig) => { diff --git a/lib/modules/ens/register.js b/lib/modules/ens/register.js index 1ebf34783..5a34e71e2 100644 --- a/lib/modules/ens/register.js +++ b/lib/modules/ens/register.js @@ -1,5 +1,4 @@ -/*global web3*/ -const namehash = require('eth-ens-namehash'); +/*global web3, namehash*/ function registerSubDomain(ens, registrar, resolver, defaultAccount, subdomain, rootDomain, reverseNode, address, logger, secureSend, callback) { const subnode = namehash.hash(subdomain);