From b16c06025b4a4b9c195fd6d53bc776bb2cc4c3bf Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Mon, 4 Jun 2018 13:12:51 -0400 Subject: [PATCH 01/12] use ipc for compiler --- lib/core/engine.js | 2 +- lib/modules/solidity/index.js | 5 +-- lib/modules/solidity/solcW.js | 48 ++++++++++++++++++++++++++ lib/tests/test.js | 3 +- package.json | 1 + test_apps/test_app/config/storage.json | 9 +---- 6 files changed, 56 insertions(+), 12 deletions(-) diff --git a/lib/core/engine.js b/lib/core/engine.js index efef0f3a..c167b5f8 100644 --- a/lib/core/engine.js +++ b/lib/core/engine.js @@ -182,7 +182,7 @@ class Engine { compiler.compile_contracts(contractFiles, cb); }); - this.registerModule('solidity'); + this.registerModule('solidity', {useIpc: options.useIpc}); this.registerModule('vyper'); this.registerModule('profiler'); this.registerModule('deploytracker'); diff --git a/lib/modules/solidity/index.js b/lib/modules/solidity/index.js index c0d77188..3bfc7583 100644 --- a/lib/modules/solidity/index.js +++ b/lib/modules/solidity/index.js @@ -3,12 +3,13 @@ let SolcW = require('./solcW.js'); class Solidity { - constructor(embark, _options) { + constructor(embark, options) { this.logger = embark.logger; this.events = embark.events; this.contractDirectories = embark.config.contractDirectories; this.solcAlreadyLoaded = false; this.solcW = null; + this.useIpc = options.useIpc; embark.registerCompiler(".sol", this.compile_solidity.bind(this)); } @@ -48,7 +49,7 @@ class Solidity { if (self.solcAlreadyLoaded) { return callback(); } - self.solcW = new SolcW({logger: self.logger, events: self.events}); + self.solcW = new SolcW({logger: self.logger, events: self.events, useIpc: self.useIpc}); self.logger.info(__("loading solc compiler") + ".."); self.solcW.load_compiler(function (err) { diff --git a/lib/modules/solidity/solcW.js b/lib/modules/solidity/solcW.js index f13d2490..95ca8f5c 100644 --- a/lib/modules/solidity/solcW.js +++ b/lib/modules/solidity/solcW.js @@ -3,18 +3,37 @@ let fs = require('../../core/fs.js'); let currentSolcVersion = require('../../../package.json').dependencies.solc; const ProcessLauncher = require('../../process/processLauncher'); const uuid = require('uuid/v1'); +let ipc = require('node-ipc') +let socketPath = "/tmp/embark.sock" class SolcW { constructor(options) { this.logger = options.logger; this.events = options.events; + this.useIpc = options.useIpc; this.compilerLoaded = false; this.solcProcess = null; } load_compiler(done) { const self = this; + if (self.useIpc) { + // try to connect, if it can't then continue + self.compilerLoaded = true; + + ipc.config.silent = true; + + function connecting(socket) { + ipc.of['embark'].on('connect',function() { + done(); + }); + } + + ipc.connectTo('embark', socketPath, connecting); + + return; + } if (this.compilerLoaded) { return done(); } @@ -30,6 +49,23 @@ class SolcW { done(); }); + ipc.config.silent = true; + + function _connecting() { + ipc.server.on( + 'message', + function(data, socket) { + self.compile(data.message, (result) => { + ipc.server.emit(socket, 'message', {action: 'compilation', message: result}); + }); + } + ); + } + + ipc.serve(socketPath, _connecting) + ipc.server.start() + this.logger.info(`pid ${process.pid} listening on ${socketPath}`); + this.events.request("version:get:solc", function(solcVersion) { if (solcVersion === currentSolcVersion) { self.solcProcess.send({action: 'loadCompiler', requirePath: 'solc'}); @@ -51,6 +87,18 @@ class SolcW { compile(jsonObj, done) { const id = uuid(); + let a = new Date(); + console.dir("doing compile"); + + if (this.useIpc) { + ipc.of['embark'].once('message', function(msg) { + done(msg.message); + }); + + ipc.of['embark'].emit('message', {action: 'compile', message: jsonObj}); + return; + } + this.solcProcess.once('result', 'compilation-' + id, (msg) => { done(JSON.parse(msg.output)); }); diff --git a/lib/tests/test.js b/lib/tests/test.js index a935327f..d75cddce 100644 --- a/lib/tests/test.js +++ b/lib/tests/test.js @@ -64,7 +64,8 @@ class Test { web3: this.web3 }); this.engine.startService("deployment", { - trackContracts: false + trackContracts: false, + useIpc: true }); this.engine.startService("codeGenerator"); } diff --git a/package.json b/package.json index 6d013652..cd660c0a 100644 --- a/package.json +++ b/package.json @@ -54,6 +54,7 @@ "ipfs-api": "17.2.4", "live-plugin-manager": "https://github.com/iurimatias/live-plugin-manager.git", "merge": "^1.2.0", + "node-ipc": "^9.1.1", "os-locale": "^2.1.0", "p-iteration": "^1.1.7", "parse-json": "^4.0.0", diff --git a/test_apps/test_app/config/storage.json b/test_apps/test_app/config/storage.json index 2209629d..51677b6c 100644 --- a/test_apps/test_app/config/storage.json +++ b/test_apps/test_app/config/storage.json @@ -3,7 +3,7 @@ "enabled": true, "ipfs_bin": "ipfs", - "available_providers": ["ipfs", "swarm"], + "available_providers": ["ipfs"], "upload": { "provider": "ipfs", @@ -18,13 +18,6 @@ ] }, "development": { - "enabled": true, - "upload": { - "provider": "swarm", - "host": "localhost", - "port": 8500, - "getUrl": "http://localhost:8500/bzzr:/" - } }, "livenet": { "enabled": true, From e96842f9da42937c4780c812ea7b66943a1b0d16 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Mon, 4 Jun 2018 13:26:25 -0400 Subject: [PATCH 02/12] use .embark instead of /tmp --- lib/modules/solidity/solcW.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/modules/solidity/solcW.js b/lib/modules/solidity/solcW.js index 95ca8f5c..f599f8b7 100644 --- a/lib/modules/solidity/solcW.js +++ b/lib/modules/solidity/solcW.js @@ -4,7 +4,6 @@ let currentSolcVersion = require('../../../package.json').dependencies.solc; const ProcessLauncher = require('../../process/processLauncher'); const uuid = require('uuid/v1'); let ipc = require('node-ipc') -let socketPath = "/tmp/embark.sock" class SolcW { @@ -30,7 +29,7 @@ class SolcW { }); } - ipc.connectTo('embark', socketPath, connecting); + ipc.connectTo('embark', fs.dappPath(".embark/embark.ipc"), connecting); return; } @@ -62,9 +61,9 @@ class SolcW { ); } - ipc.serve(socketPath, _connecting) + ipc.serve(fs.dappPath(".embark/embark.ipc"), _connecting) ipc.server.start() - this.logger.info(`pid ${process.pid} listening on ${socketPath}`); + this.logger.info(`pid ${process.pid} listening on ${fs.dappPath(".embark/embark.ipc")}`); this.events.request("version:get:solc", function(solcVersion) { if (solcVersion === currentSolcVersion) { @@ -88,7 +87,6 @@ class SolcW { compile(jsonObj, done) { const id = uuid(); let a = new Date(); - console.dir("doing compile"); if (this.useIpc) { ipc.of['embark'].once('message', function(msg) { From 6e37c2d91bfb728b7608f16ac260d9e8ecc77197 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Mon, 4 Jun 2018 13:33:07 -0400 Subject: [PATCH 03/12] only reply to compile action --- lib/modules/solidity/solcW.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/modules/solidity/solcW.js b/lib/modules/solidity/solcW.js index f599f8b7..2be126f0 100644 --- a/lib/modules/solidity/solcW.js +++ b/lib/modules/solidity/solcW.js @@ -54,9 +54,13 @@ class SolcW { ipc.server.on( 'message', function(data, socket) { - self.compile(data.message, (result) => { - ipc.server.emit(socket, 'message', {action: 'compilation', message: result}); - }); + if (data.action != 'compile') { + return; + } + + self.compile(data.message, (result) => { + ipc.server.emit(socket, 'message', {action: 'compilation', message: result}); + }); } ); } From 1821e8934699887cc3e740957b1e7c866b70e7df Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Mon, 4 Jun 2018 15:36:43 -0400 Subject: [PATCH 04/12] refactor ipc to a module --- lib/core/engine.js | 4 ++- lib/core/ipc.js | 57 +++++++++++++++++++++++++++++++++++ lib/modules/solidity/index.js | 3 +- lib/modules/solidity/solcW.js | 46 +++++++--------------------- 4 files changed, 73 insertions(+), 37 deletions(-) create mode 100644 lib/core/ipc.js diff --git a/lib/core/engine.js b/lib/core/engine.js index c167b5f8..f31d770d 100644 --- a/lib/core/engine.js +++ b/lib/core/engine.js @@ -1,6 +1,7 @@ const async = require('async'); const utils = require('../utils/utils'); +const IPC = require('./ipc'); class Engine { constructor(options) { @@ -182,7 +183,8 @@ class Engine { compiler.compile_contracts(contractFiles, cb); }); - this.registerModule('solidity', {useIpc: options.useIpc}); + this.ipc = new IPC({logger: this.logger}); + this.registerModule('solidity', {useIpc: options.useIpc, ipc: this.ipc}); this.registerModule('vyper'); this.registerModule('profiler'); this.registerModule('deploytracker'); diff --git a/lib/core/ipc.js b/lib/core/ipc.js new file mode 100644 index 00000000..efc3b977 --- /dev/null +++ b/lib/core/ipc.js @@ -0,0 +1,57 @@ +let fs = require('./fs.js'); +let ipc = require('node-ipc'); + +class IPC { + + constructor(options) { + this.logger = options.logger; + this.socketPath = options.socketPath || fs.dappPath(".embark/embark.ipc"); + ipc.config.silent = true; + } + + connect(done) { + function connecting(socket) { + ipc.of['embark'].on('connect',function() { + done(); + }); + } + + ipc.connectTo('embark', this.socketPath, connecting); + } + + serve() { + ipc.serve(this.socketPath, () => {}) + ipc.server.start() + + this.logger.info(`pid ${process.pid} listening on ${this.socketPath}`); + } + + on(action, done) { + ipc.server.on('message', function(data, socket) { + if (data.action !== action) { + return; + } + done(data.message, socket); + }); + } + + reply(client, action, data) { + ipc.server.emit(client, 'message', {action: action, message: data}); + } + + once(action, cb) { + ipc.of['embark'].once('message', function(msg) { + if (msg.action !== action) { + return; + } + cb(msg.message); + }); + } + + request(action, data) { + ipc.of['embark'].emit('message', {action: action, message: data}); + } + +} + +module.exports = IPC; diff --git a/lib/modules/solidity/index.js b/lib/modules/solidity/index.js index 3bfc7583..d7b53357 100644 --- a/lib/modules/solidity/index.js +++ b/lib/modules/solidity/index.js @@ -6,6 +6,7 @@ class Solidity { constructor(embark, options) { this.logger = embark.logger; this.events = embark.events; + this.ipc = options.ipc; this.contractDirectories = embark.config.contractDirectories; this.solcAlreadyLoaded = false; this.solcW = null; @@ -49,7 +50,7 @@ class Solidity { if (self.solcAlreadyLoaded) { return callback(); } - self.solcW = new SolcW({logger: self.logger, events: self.events, useIpc: self.useIpc}); + self.solcW = new SolcW({logger: self.logger, events: self.events, useIpc: self.useIpc, ipc: self.ipc}); self.logger.info(__("loading solc compiler") + ".."); self.solcW.load_compiler(function (err) { diff --git a/lib/modules/solidity/solcW.js b/lib/modules/solidity/solcW.js index 2be126f0..2e77e01c 100644 --- a/lib/modules/solidity/solcW.js +++ b/lib/modules/solidity/solcW.js @@ -11,6 +11,7 @@ class SolcW { this.logger = options.logger; this.events = options.events; this.useIpc = options.useIpc; + this.ipc = options.ipc; this.compilerLoaded = false; this.solcProcess = null; } @@ -18,20 +19,9 @@ class SolcW { load_compiler(done) { const self = this; if (self.useIpc) { - // try to connect, if it can't then continue self.compilerLoaded = true; - ipc.config.silent = true; - - function connecting(socket) { - ipc.of['embark'].on('connect',function() { - done(); - }); - } - - ipc.connectTo('embark', fs.dappPath(".embark/embark.ipc"), connecting); - - return; + return self.ipc.connect(done); } if (this.compilerLoaded) { return done(); @@ -48,26 +38,12 @@ class SolcW { done(); }); - ipc.config.silent = true; - - function _connecting() { - ipc.server.on( - 'message', - function(data, socket) { - if (data.action != 'compile') { - return; - } - - self.compile(data.message, (result) => { - ipc.server.emit(socket, 'message', {action: 'compilation', message: result}); - }); - } - ); - } - - ipc.serve(fs.dappPath(".embark/embark.ipc"), _connecting) - ipc.server.start() - this.logger.info(`pid ${process.pid} listening on ${fs.dappPath(".embark/embark.ipc")}`); + this.ipc.serve(); + this.ipc.on('compile', (data, client) => { + self.compile(data, (result) => { + self.ipc.reply(client, 'compilation', result); + }); + }); this.events.request("version:get:solc", function(solcVersion) { if (solcVersion === currentSolcVersion) { @@ -93,11 +69,11 @@ class SolcW { let a = new Date(); if (this.useIpc) { - ipc.of['embark'].once('message', function(msg) { - done(msg.message); + this.ipc.once('compilation', (data) => { + done(data); }); - ipc.of['embark'].emit('message', {action: 'compile', message: jsonObj}); + this.ipc.request('compile', jsonObj); return; } From 37ade68804dfd81f5c4c73873620efc453e47553 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Mon, 4 Jun 2018 15:44:17 -0400 Subject: [PATCH 05/12] debug console logs --- lib/core/ipc.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/core/ipc.js b/lib/core/ipc.js index efc3b977..e522eca7 100644 --- a/lib/core/ipc.js +++ b/lib/core/ipc.js @@ -28,6 +28,9 @@ class IPC { on(action, done) { ipc.server.on('message', function(data, socket) { + console.dir("received message"); + console.dir(action); + console.dir(data); if (data.action !== action) { return; } @@ -36,19 +39,29 @@ class IPC { } reply(client, action, data) { + console.dir("reply message"); + console.dir(action); + console.dir(data); ipc.server.emit(client, 'message', {action: action, message: data}); } once(action, cb) { ipc.of['embark'].once('message', function(msg) { + console.dir("once message"); + console.dir(action); + console.dir(msg); if (msg.action !== action) { return; } + console.dir('received'); cb(msg.message); }); } request(action, data) { + console.dir("request message"); + console.dir(action); + console.dir(data); ipc.of['embark'].emit('message', {action: action, message: data}); } From a57bce2a40872ead40f2909a8af974110f7c55a4 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Mon, 4 Jun 2018 16:39:31 -0400 Subject: [PATCH 06/12] refactor to use callbacks on ipc requests --- lib/core/ipc.js | 24 +++++++++--------------- lib/modules/solidity/solcW.js | 13 ++----------- 2 files changed, 11 insertions(+), 26 deletions(-) diff --git a/lib/core/ipc.js b/lib/core/ipc.js index e522eca7..00930f43 100644 --- a/lib/core/ipc.js +++ b/lib/core/ipc.js @@ -27,41 +27,35 @@ class IPC { } on(action, done) { + const self = this; ipc.server.on('message', function(data, socket) { - console.dir("received message"); - console.dir(action); - console.dir(data); if (data.action !== action) { return; } - done(data.message, socket); + let reply = function(replyData) { + self.reply(socket, 'compile', replyData); + } + done(data.message, reply, socket); }); } reply(client, action, data) { - console.dir("reply message"); - console.dir(action); - console.dir(data); ipc.server.emit(client, 'message', {action: action, message: data}); } once(action, cb) { ipc.of['embark'].once('message', function(msg) { - console.dir("once message"); - console.dir(action); - console.dir(msg); if (msg.action !== action) { return; } - console.dir('received'); cb(msg.message); }); } - request(action, data) { - console.dir("request message"); - console.dir(action); - console.dir(data); + request(action, data, cb) { + if (cb) { + this.once(action, cb); + } ipc.of['embark'].emit('message', {action: action, message: data}); } diff --git a/lib/modules/solidity/solcW.js b/lib/modules/solidity/solcW.js index 2e77e01c..3f40d62a 100644 --- a/lib/modules/solidity/solcW.js +++ b/lib/modules/solidity/solcW.js @@ -39,11 +39,7 @@ class SolcW { }); this.ipc.serve(); - this.ipc.on('compile', (data, client) => { - self.compile(data, (result) => { - self.ipc.reply(client, 'compilation', result); - }); - }); + this.ipc.on('compile', self.compile.bind(this)); this.events.request("version:get:solc", function(solcVersion) { if (solcVersion === currentSolcVersion) { @@ -69,12 +65,7 @@ class SolcW { let a = new Date(); if (this.useIpc) { - this.ipc.once('compilation', (data) => { - done(data); - }); - - this.ipc.request('compile', jsonObj); - return; + return this.ipc.request('compile', jsonObj, done); } this.solcProcess.once('result', 'compilation-' + id, (msg) => { From c0e559a7d9bdc1fdc4d29a5a0c90d5012a7c88a4 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Mon, 4 Jun 2018 18:15:27 -0400 Subject: [PATCH 07/12] assign roles so ipc connections don't conflict; fallback if can't connect to ipc --- lib/core/engine.js | 2 +- lib/core/ipc.js | 28 +++++++++++++++++++++++++++- lib/modules/solidity/solcW.js | 27 +++++++++++++++++++-------- lib/tests/test.js | 2 +- 4 files changed, 48 insertions(+), 11 deletions(-) diff --git a/lib/core/engine.js b/lib/core/engine.js index f31d770d..13f1c070 100644 --- a/lib/core/engine.js +++ b/lib/core/engine.js @@ -183,7 +183,7 @@ class Engine { compiler.compile_contracts(contractFiles, cb); }); - this.ipc = new IPC({logger: this.logger}); + this.ipc = new IPC({logger: this.logger, ipcRole: options.ipcRole}); this.registerModule('solidity', {useIpc: options.useIpc, ipc: this.ipc}); this.registerModule('vyper'); this.registerModule('profiler'); diff --git a/lib/core/ipc.js b/lib/core/ipc.js index 00930f43..9bae112e 100644 --- a/lib/core/ipc.js +++ b/lib/core/ipc.js @@ -6,13 +6,31 @@ class IPC { constructor(options) { this.logger = options.logger; this.socketPath = options.socketPath || fs.dappPath(".embark/embark.ipc"); + this.ipcRole = options.ipcRole || "server"; ipc.config.silent = true; + this.connected = false; } connect(done) { + const self = this; function connecting(socket) { + let connectedBefore = false, alreadyDisconnected = false;; ipc.of['embark'].on('connect',function() { - done(); + connectedBefore = true; + if (!alreadyDisconnected) { + self.connected = true; + done(); + } + }); + ipc.of['embark'].on('disconnect',function() { + self.connected = false; + ipc.disconnect('embark'); + + // we only want to trigger the error callback the first time + if (!connectedBefore && !alreadyDisconnected) { + alreadyDisconnected = true; + done(new Error("no connection found")); + } }); } @@ -59,6 +77,14 @@ class IPC { ipc.of['embark'].emit('message', {action: action, message: data}); } + isClient() { + return this.ipcRole === 'client'; + } + + isServer() { + return this.ipcRole === 'server'; + } + } module.exports = IPC; diff --git a/lib/modules/solidity/solcW.js b/lib/modules/solidity/solcW.js index 3f40d62a..93139f8a 100644 --- a/lib/modules/solidity/solcW.js +++ b/lib/modules/solidity/solcW.js @@ -10,7 +10,6 @@ class SolcW { constructor(options) { this.logger = options.logger; this.events = options.events; - this.useIpc = options.useIpc; this.ipc = options.ipc; this.compilerLoaded = false; this.solcProcess = null; @@ -18,11 +17,21 @@ class SolcW { load_compiler(done) { const self = this; - if (self.useIpc) { - self.compilerLoaded = true; - - return self.ipc.connect(done); + if (self.ipc.isClient()) { + return self.ipc.connect((err) => { + if (err) { + return self.load_compiler_internally(done); + } + self.compilerLoaded = true; + done(); + }); } + + self.load_compiler_internally(done); + } + + load_compiler_internally(done) { + const self = this; if (this.compilerLoaded) { return done(); } @@ -38,8 +47,10 @@ class SolcW { done(); }); - this.ipc.serve(); - this.ipc.on('compile', self.compile.bind(this)); + if (this.ipc.isServer()) { + this.ipc.serve(); + this.ipc.on('compile', self.compile.bind(this)); + } this.events.request("version:get:solc", function(solcVersion) { if (solcVersion === currentSolcVersion) { @@ -64,7 +75,7 @@ class SolcW { const id = uuid(); let a = new Date(); - if (this.useIpc) { + if (this.ipc.isClient() && this.ipc.connected) { return this.ipc.request('compile', jsonObj, done); } diff --git a/lib/tests/test.js b/lib/tests/test.js index d75cddce..eabb6812 100644 --- a/lib/tests/test.js +++ b/lib/tests/test.js @@ -65,7 +65,7 @@ class Test { }); this.engine.startService("deployment", { trackContracts: false, - useIpc: true + ipcRole: 'client' }); this.engine.startService("codeGenerator"); } From 85443959e0f4d9c6e1be3be72878c160b45b2f75 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 5 Jun 2018 08:04:27 -0400 Subject: [PATCH 08/12] remove unneded option --- lib/core/engine.js | 2 +- lib/modules/solidity/index.js | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/core/engine.js b/lib/core/engine.js index 13f1c070..618323fb 100644 --- a/lib/core/engine.js +++ b/lib/core/engine.js @@ -184,7 +184,7 @@ class Engine { }); this.ipc = new IPC({logger: this.logger, ipcRole: options.ipcRole}); - this.registerModule('solidity', {useIpc: options.useIpc, ipc: this.ipc}); + this.registerModule('solidity', {ipc: this.ipc}); this.registerModule('vyper'); this.registerModule('profiler'); this.registerModule('deploytracker'); diff --git a/lib/modules/solidity/index.js b/lib/modules/solidity/index.js index d7b53357..f665144b 100644 --- a/lib/modules/solidity/index.js +++ b/lib/modules/solidity/index.js @@ -10,7 +10,6 @@ class Solidity { this.contractDirectories = embark.config.contractDirectories; this.solcAlreadyLoaded = false; this.solcW = null; - this.useIpc = options.useIpc; embark.registerCompiler(".sol", this.compile_solidity.bind(this)); } @@ -50,7 +49,7 @@ class Solidity { if (self.solcAlreadyLoaded) { return callback(); } - self.solcW = new SolcW({logger: self.logger, events: self.events, useIpc: self.useIpc, ipc: self.ipc}); + self.solcW = new SolcW({logger: self.logger, events: self.events, ipc: self.ipc}); self.logger.info(__("loading solc compiler") + ".."); self.solcW.load_compiler(function (err) { From d9485477c80395c54ba57efd344c1c9955c6ff62 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 5 Jun 2018 08:07:11 -0400 Subject: [PATCH 09/12] restore storage.json --- test_apps/test_app/config/storage.json | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/test_apps/test_app/config/storage.json b/test_apps/test_app/config/storage.json index 51677b6c..2209629d 100644 --- a/test_apps/test_app/config/storage.json +++ b/test_apps/test_app/config/storage.json @@ -3,7 +3,7 @@ "enabled": true, "ipfs_bin": "ipfs", - "available_providers": ["ipfs"], + "available_providers": ["ipfs", "swarm"], "upload": { "provider": "ipfs", @@ -18,6 +18,13 @@ ] }, "development": { + "enabled": true, + "upload": { + "provider": "swarm", + "host": "localhost", + "port": 8500, + "getUrl": "http://localhost:8500/bzzr:/" + } }, "livenet": { "enabled": true, From 0e6d526ab447d746ed7a1c9df65f6e962dd36faa Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 5 Jun 2018 08:37:27 -0400 Subject: [PATCH 10/12] comply with linter --- lib/core/ipc.js | 10 +++++----- lib/modules/solidity/solcW.js | 2 -- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/core/ipc.js b/lib/core/ipc.js index 9bae112e..e84e88ab 100644 --- a/lib/core/ipc.js +++ b/lib/core/ipc.js @@ -13,8 +13,8 @@ class IPC { connect(done) { const self = this; - function connecting(socket) { - let connectedBefore = false, alreadyDisconnected = false;; + function connecting(_socket) { + let connectedBefore = false, alreadyDisconnected = false; ipc.of['embark'].on('connect',function() { connectedBefore = true; if (!alreadyDisconnected) { @@ -38,8 +38,8 @@ class IPC { } serve() { - ipc.serve(this.socketPath, () => {}) - ipc.server.start() + ipc.serve(this.socketPath, () => {}); + ipc.server.start(); this.logger.info(`pid ${process.pid} listening on ${this.socketPath}`); } @@ -52,7 +52,7 @@ class IPC { } let reply = function(replyData) { self.reply(socket, 'compile', replyData); - } + }; done(data.message, reply, socket); }); } diff --git a/lib/modules/solidity/solcW.js b/lib/modules/solidity/solcW.js index 93139f8a..617eabb6 100644 --- a/lib/modules/solidity/solcW.js +++ b/lib/modules/solidity/solcW.js @@ -3,7 +3,6 @@ let fs = require('../../core/fs.js'); let currentSolcVersion = require('../../../package.json').dependencies.solc; const ProcessLauncher = require('../../process/processLauncher'); const uuid = require('uuid/v1'); -let ipc = require('node-ipc') class SolcW { @@ -73,7 +72,6 @@ class SolcW { compile(jsonObj, done) { const id = uuid(); - let a = new Date(); if (this.ipc.isClient() && this.ipc.connected) { return this.ipc.request('compile', jsonObj, done); From a3bb4bc53b1727d0f30cd232d1e13c15f3ddd78e Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 5 Jun 2018 08:38:27 -0400 Subject: [PATCH 11/12] update tests --- test/compiler.js | 7 ++++++- test/contracts.js | 11 +++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/test/compiler.js b/test/compiler.js index 4bc48160..7f9a8649 100644 --- a/test/compiler.js +++ b/test/compiler.js @@ -2,6 +2,7 @@ let SolidityCompiler = require('../lib/modules/solidity'); let TestLogger = require('../lib/tests/test_logger.js'); let File = require('../lib/core/file.js'); +let Ipc = require('../lib/core/ipc.js'); let assert = require('assert'); let readFile = function(file) { @@ -16,6 +17,10 @@ var TestEvents = { } }; +let ipcObject = new Ipc({ + ipcRole: 'none' +}); + var apiObject = { registerCompiler: function() {}, logger: new TestLogger({}), @@ -27,7 +32,7 @@ var apiObject = { describe('embark.Compiler', function() { //let compiler = new Compiler({logger: new TestLogger({})}); - let compiler = new SolidityCompiler(apiObject); + let compiler = new SolidityCompiler(apiObject, {ipc: ipcObject}); describe('#compile_solidity', function() { this.timeout(0); diff --git a/test/contracts.js b/test/contracts.js index b8452b80..9662fa8b 100644 --- a/test/contracts.js +++ b/test/contracts.js @@ -5,6 +5,7 @@ let Logger = require('../lib/core/logger.js'); let File = require('../lib/core/file.js'); let TestLogger = require('../lib/tests/test_logger.js'); let Events = require('../lib/core/events'); +let Ipc = require('../lib/core/ipc.js'); let assert = require('assert'); //let SolidityCompiler = require('../lib/modules/solidity'); @@ -31,7 +32,10 @@ describe('embark.Contracts', function() { contractDirectories: ['app/contracts/'] } }); - plugins.loadInternalPlugin('solidity'); + let ipcObject = new Ipc({ + ipcRole: 'none' + }); + plugins.loadInternalPlugin('solidity', {ipc: ipcObject}); let compiler = new Compiler({plugins: plugins, logger: plugins.logger}); let events = new Events(); @@ -123,7 +127,10 @@ describe('embark.Contracts', function() { contractDirectories: ['app/contracts/'] } }); - plugins.loadInternalPlugin('solidity'); + let ipcObject = new Ipc({ + ipcRole: 'none' + }); + plugins.loadInternalPlugin('solidity', {ipc: ipcObject}); let compiler = new Compiler({plugins: plugins, logger: plugins.logger}); let events = new Events(); From a41cf99be08574185f9c66c4fdfc43764b257b09 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 5 Jun 2018 16:13:17 -0400 Subject: [PATCH 12/12] reverse condition --- lib/modules/solidity/solcW.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/modules/solidity/solcW.js b/lib/modules/solidity/solcW.js index 617eabb6..510ef98f 100644 --- a/lib/modules/solidity/solcW.js +++ b/lib/modules/solidity/solcW.js @@ -16,17 +16,17 @@ class SolcW { load_compiler(done) { const self = this; - if (self.ipc.isClient()) { - return self.ipc.connect((err) => { - if (err) { - return self.load_compiler_internally(done); - } - self.compilerLoaded = true; - done(); - }); + if (!self.ipc.isClient()) { + return self.load_compiler_internally(done); } - self.load_compiler_internally(done); + self.ipc.connect((err) => { + if (err) { + return self.load_compiler_internally(done); + } + self.compilerLoaded = true; + done(); + }); } load_compiler_internally(done) {