EmbarkJS available

This commit is contained in:
Anthony Laibe 2018-08-28 11:47:40 +01:00
parent d772b4fdaf
commit 307b7dc8e7
7 changed files with 25 additions and 14 deletions

View File

@ -279,6 +279,7 @@ class EmbarkController {
engine.startService("storage"); engine.startService("storage");
engine.startService("codeGenerator"); engine.startService("codeGenerator");
engine.startService("webServer"); engine.startService("webServer");
engine.startService("namingSystem");
return callback(); return callback();
} }
@ -315,6 +316,7 @@ class EmbarkController {
if(engine.ipc.connected && engine.ipc.isClient()) { if(engine.ipc.connected && engine.ipc.isClient()) {
return callback(); return callback();
} }
engine.config.reloadConfig();
engine.events.request('deploy:contracts', function (err) { engine.events.request('deploy:contracts', function (err) {
callback(err); callback(err);
}); });

View File

@ -63,10 +63,7 @@ Config.prototype.loadConfigFiles = function(options) {
this.loadStorageConfigFile(); this.loadStorageConfigFile();
this.loadCommunicationConfigFile(); this.loadCommunicationConfigFile();
this.loadNameSystemConfigFile(); this.loadNameSystemConfigFile();
this.loadContractsConfigFile();
this.loadPipelineConfigFile(); this.loadPipelineConfigFile();
this.loadContractsConfigFile(); this.loadContractsConfigFile();
this.loadExternalContractsFiles(); this.loadExternalContractsFiles();
this.loadWebServerConfigFile(); this.loadWebServerConfigFile();
@ -82,7 +79,6 @@ Config.prototype.reloadConfig = function() {
this.loadStorageConfigFile(); this.loadStorageConfigFile();
this.loadCommunicationConfigFile(); this.loadCommunicationConfigFile();
this.loadNameSystemConfigFile(); this.loadNameSystemConfigFile();
this.loadContractsConfigFile();
this.loadPipelineConfigFile(); this.loadPipelineConfigFile();
this.loadContractsConfigFile(); this.loadContractsConfigFile();
this.loadExternalContractsFiles(); this.loadExternalContractsFiles();

View File

@ -1,5 +1,9 @@
const RunCode = require('./runCode.js'); const RunCode = require('./runCode.js');
const EmbarkJS = require('embarkjs'); const EmbarkJS = require('embarkjs');
const IpfsApi = require('ipfs-api');
const Web3 = require('web3');
const namehash = require('eth-ens-namehash');
class CodeRunner { class CodeRunner {
constructor(options) { constructor(options) {
this.plugins = options.plugins; this.plugins = options.plugins;
@ -26,6 +30,9 @@ class CodeRunner {
} }
}); });
} else { } else {
this.runCode.registerVar('IpfsApi', IpfsApi);
this.runCode.registerVar('Web3', Web3);
this.runCode.registerVar('namehash', namehash);
this.runCode.registerVar('EmbarkJS', EmbarkJS); this.runCode.registerVar('EmbarkJS', EmbarkJS);
this.events.on('code-generator-ready', () => { this.events.on('code-generator-ready', () => {
this.events.request('code-generator:embarkjs:initialization-code', (code) => { this.events.request('code-generator:embarkjs:initialization-code', (code) => {

View File

@ -9,7 +9,7 @@ class RunCode {
try { try {
return vm.runInNewContext(code, this.context); return vm.runInNewContext(code, this.context);
} catch(e) { } catch(e) {
console.log(e) console.log(e.message)
} }
} }
@ -19,6 +19,8 @@ class RunCode {
// /*global web3*/ // /*global web3*/
if (varName === 'web3') { if (varName === 'web3') {
global.web3 = code; global.web3 = code;
} else if (varName === 'namehash') {
global.namehash = code;
} }
this.context[varName] = code; this.context[varName] = code;
} }

View File

@ -350,17 +350,23 @@ class CodeGenerator {
code += plugin.embarkjs_code.join('\n'); code += plugin.embarkjs_code.join('\n');
} }
const codeTypes = {'communication': this.communicationConfig,
'names': this.namesystemConfig,
'storage': this.storageConfig};
let initCodes = this.plugins.getPluginsFor('initCode'); let initCodes = this.plugins.getPluginsFor('initCode');
for (let plugin of initCodes) { for (let plugin of initCodes) {
let initCodes = plugin.embarkjs_init_code['communication'] || []; for (let codeTypeName of Object.keys(codeTypes)) {
for (let initCode of initCodes) { let initCodes = plugin.embarkjs_init_code[codeTypeName] || [];
let [block, shouldInit] = initCode; for (let initCode of initCodes) {
if (shouldInit.call(plugin, this.communicationConfig)) { let [block, shouldInit] = initCode;
code += block; if (shouldInit.call(plugin, codeTypes[codeTypeName])) {
code += block;
}
} }
} }
} }
return code; return code;
} }

View File

@ -307,7 +307,6 @@ class ENS {
} }
addSetProvider(config) { addSetProvider(config) {
let code = "\nEmbarkJS.Names.setProvider('ens'," + JSON.stringify(config) + ");"; let code = "\nEmbarkJS.Names.setProvider('ens'," + JSON.stringify(config) + ");";
let shouldInit = (namesConfig) => { let shouldInit = (namesConfig) => {

View File

@ -1,5 +1,4 @@
/*global web3*/ /*global web3, namehash*/
const namehash = require('eth-ens-namehash');
function registerSubDomain(ens, registrar, resolver, defaultAccount, subdomain, rootDomain, reverseNode, address, logger, secureSend, callback) { function registerSubDomain(ens, registrar, resolver, defaultAccount, subdomain, rootDomain, reverseNode, address, logger, secureSend, callback) {
const subnode = namehash.hash(subdomain); const subnode = namehash.hash(subdomain);