Merge pull request #822 from embark-framework/bugfix/circular-json
Fix circular JSON and swarm api require
This commit is contained in:
commit
9b2fa9402b
|
@ -296,20 +296,31 @@ class EmbarkController {
|
||||||
if(!engine.ipc.connected || engine.ipc.isServer()) {
|
if(!engine.ipc.connected || engine.ipc.isServer()) {
|
||||||
return callback();
|
return callback();
|
||||||
}
|
}
|
||||||
|
const Provider = require('../lib/modules/blockchain_connector/provider');
|
||||||
const Web3 = require('web3');
|
const Web3 = require('web3');
|
||||||
let web3 = new Web3();
|
let web3 = new Web3();
|
||||||
engine.ipc.request("runcode:getCommands", null, (_, {web3Config, commands}) => {
|
engine.ipc.request("runcode:getCommands", null, (_, {web3Config, commands}) => {
|
||||||
web3.setProvider(web3Config.provider.host);
|
const providerOptions = {
|
||||||
web3.eth.defaultAccount = web3Config.defaultAccount;
|
web3: web3,
|
||||||
engine.events.emit("runcode:register", "web3", web3);
|
accountsConfig: engine.config.contractsConfig.deployment.accounts,
|
||||||
async.each(commands, ({varName, code}, next) => {
|
blockchainConfig: engine.config.blockchainConfig,
|
||||||
if (varName) {
|
logger: engine.logger,
|
||||||
engine.events.emit("runcode:register", varName, code);
|
isDev: engine.isDev,
|
||||||
} else {
|
type: engine.config.contractsConfig.deployment.type,
|
||||||
engine.events.request("runcode:eval", code);
|
web3Endpoint: web3Config.providerUrl
|
||||||
}
|
};
|
||||||
next();
|
const provider = new Provider(providerOptions);
|
||||||
}, callback);
|
provider.startWeb3Provider(() => {
|
||||||
|
engine.events.emit("runcode:register", "web3", web3);
|
||||||
|
async.each(commands, ({varName, code}, next) => {
|
||||||
|
if (varName) {
|
||||||
|
engine.events.emit("runcode:register", varName, code);
|
||||||
|
} else {
|
||||||
|
engine.events.request("runcode:eval", code);
|
||||||
|
}
|
||||||
|
next();
|
||||||
|
}, callback);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
function deploy(callback) {
|
function deploy(callback) {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
let fs = require('./fs.js');
|
const fs = require('./fs.js');
|
||||||
let ipc = require('node-ipc');
|
const ipc = require('node-ipc');
|
||||||
|
const {parse, stringify} = require('flatted/cjs');
|
||||||
|
|
||||||
class IPC {
|
class IPC {
|
||||||
|
|
||||||
|
@ -47,35 +48,40 @@ class IPC {
|
||||||
|
|
||||||
on(action, done) {
|
on(action, done) {
|
||||||
const self = this;
|
const self = this;
|
||||||
ipc.server.on('message', function(data, socket) {
|
ipc.server.on('message', function(messageString, socket) {
|
||||||
if (data.action !== action) {
|
const message = parse(messageString);
|
||||||
|
if (message.action !== action) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let reply = function(error, replyData) {
|
let reply = function(error, replyData) {
|
||||||
self.reply(socket, action, error, replyData);
|
self.reply(socket, action, error, replyData);
|
||||||
};
|
};
|
||||||
done(data.message, reply, socket);
|
done(message.data, reply, socket);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
reply(client, action, error, data) {
|
reply(client, action, error, data) {
|
||||||
ipc.server.emit(client, 'message', {action: action, message: data, error: (error && error.stack)});
|
const message = stringify({action, data, error: (error && error.stack)});
|
||||||
|
ipc.server.emit(client, 'message', message);
|
||||||
}
|
}
|
||||||
|
|
||||||
listenTo(action, callback) {
|
listenTo(action, callback) {
|
||||||
ipc.of['embark'].on(action, callback);
|
ipc.of['embark'].on(action, (messageString) => {
|
||||||
|
callback(parse(messageString));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
broadcast(action, data) {
|
broadcast(action, data) {
|
||||||
ipc.server.broadcast(action, data);
|
ipc.server.broadcast(action, stringify(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
once(action, cb) {
|
once(action, cb) {
|
||||||
ipc.of['embark'].once('message', function(msg) {
|
ipc.of['embark'].once('message', function(messageString) {
|
||||||
if (msg.action !== action) {
|
const message = parse(messageString);
|
||||||
|
if (message.action !== action) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
cb(msg.error, msg.message);
|
cb(message.error, message.data);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,7 +89,7 @@ class IPC {
|
||||||
if (cb) {
|
if (cb) {
|
||||||
this.once(action, cb);
|
this.once(action, cb);
|
||||||
}
|
}
|
||||||
ipc.of['embark'].emit('message', {action: action, message: data});
|
ipc.of['embark'].emit('message', stringify({action: action, data: data}));
|
||||||
}
|
}
|
||||||
|
|
||||||
isClient() {
|
isClient() {
|
||||||
|
|
|
@ -29,7 +29,7 @@ class RunCode {
|
||||||
}
|
}
|
||||||
|
|
||||||
getWeb3Config() {
|
getWeb3Config() {
|
||||||
return {defaultAccount: this.context.web3.eth.defaultAccount, provider: this.context.web3.currentProvider};
|
return {defaultAccount: this.context.web3.eth.defaultAccount, providerUrl: this.context.web3.currentProvider.connection._url};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
/*global web3 */
|
/*global web3 */
|
||||||
let __embarkSwarm = {_swarmConnection: undefined};
|
let __embarkSwarm = {_swarmConnection: undefined};
|
||||||
import SwarmAPI from 'swarm-api';
|
let SwarmAPI = require('swarm-api');
|
||||||
|
if (SwarmAPI.default) {
|
||||||
|
SwarmAPI = SwarmAPI.default;
|
||||||
|
}
|
||||||
|
|
||||||
__embarkSwarm.setProvider = function (options) {
|
__embarkSwarm.setProvider = function (options) {
|
||||||
let protocol = options.protocol || 'http';
|
let protocol = options.protocol || 'http';
|
||||||
|
|
|
@ -3719,6 +3719,11 @@
|
||||||
"resolved": "https://registry.npmjs.org/flatmap/-/flatmap-0.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/flatmap/-/flatmap-0.0.3.tgz",
|
||||||
"integrity": "sha1-Hxik2TgVLUlZZfnJWNkjqy3WabQ="
|
"integrity": "sha1-Hxik2TgVLUlZZfnJWNkjqy3WabQ="
|
||||||
},
|
},
|
||||||
|
"flatted": {
|
||||||
|
"version": "0.2.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/flatted/-/flatted-0.2.3.tgz",
|
||||||
|
"integrity": "sha512-C4B5UtK3kOrLAyZ1ftqEWprxCfLmCIqEcNufZrtsJhiZ/fcI5mvCgtAtC3pu7BC9KE7aUIrPXwTgcT1fiI7QhA=="
|
||||||
|
},
|
||||||
"flatten": {
|
"flatten": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/flatten/-/flatten-1.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/flatten/-/flatten-1.0.2.tgz",
|
||||||
|
|
|
@ -47,6 +47,7 @@
|
||||||
"ethereumjs-wallet": "0.6.0",
|
"ethereumjs-wallet": "0.6.0",
|
||||||
"file-loader": "^1.1.5",
|
"file-loader": "^1.1.5",
|
||||||
"finalhandler": "^1.1.1",
|
"finalhandler": "^1.1.1",
|
||||||
|
"flatted": "^0.2.3",
|
||||||
"follow-redirects": "^1.2.4",
|
"follow-redirects": "^1.2.4",
|
||||||
"fs-extra": "^2.0.0",
|
"fs-extra": "^2.0.0",
|
||||||
"ganache-cli": "^6.1.6",
|
"ganache-cli": "^6.1.6",
|
||||||
|
|
Loading…
Reference in New Issue