Merge pull request #822 from embark-framework/bugfix/circular-json

Fix circular JSON and swarm api require
This commit is contained in:
Iuri Matias 2018-09-14 18:11:34 -04:00 committed by GitHub
commit 9b2fa9402b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 51 additions and 25 deletions

View File

@ -296,11 +296,21 @@ class EmbarkController {
if(!engine.ipc.connected || engine.ipc.isServer()) {
return callback();
}
const Provider = require('../lib/modules/blockchain_connector/provider');
const Web3 = require('web3');
let web3 = new Web3();
engine.ipc.request("runcode:getCommands", null, (_, {web3Config, commands}) => {
web3.setProvider(web3Config.provider.host);
web3.eth.defaultAccount = web3Config.defaultAccount;
const providerOptions = {
web3: web3,
accountsConfig: engine.config.contractsConfig.deployment.accounts,
blockchainConfig: engine.config.blockchainConfig,
logger: engine.logger,
isDev: engine.isDev,
type: engine.config.contractsConfig.deployment.type,
web3Endpoint: web3Config.providerUrl
};
const provider = new Provider(providerOptions);
provider.startWeb3Provider(() => {
engine.events.emit("runcode:register", "web3", web3);
async.each(commands, ({varName, code}, next) => {
if (varName) {
@ -311,6 +321,7 @@ class EmbarkController {
next();
}, callback);
});
});
},
function deploy(callback) {
// Skip if we are connected to a websocket, the server will do it

View File

@ -1,5 +1,6 @@
let fs = require('./fs.js');
let ipc = require('node-ipc');
const fs = require('./fs.js');
const ipc = require('node-ipc');
const {parse, stringify} = require('flatted/cjs');
class IPC {
@ -47,35 +48,40 @@ class IPC {
on(action, done) {
const self = this;
ipc.server.on('message', function(data, socket) {
if (data.action !== action) {
ipc.server.on('message', function(messageString, socket) {
const message = parse(messageString);
if (message.action !== action) {
return;
}
let reply = function(error, replyData) {
self.reply(socket, action, error, replyData);
};
done(data.message, reply, socket);
done(message.data, reply, socket);
});
}
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) {
ipc.of['embark'].on(action, callback);
ipc.of['embark'].on(action, (messageString) => {
callback(parse(messageString));
});
}
broadcast(action, data) {
ipc.server.broadcast(action, data);
ipc.server.broadcast(action, stringify(data));
}
once(action, cb) {
ipc.of['embark'].once('message', function(msg) {
if (msg.action !== action) {
ipc.of['embark'].once('message', function(messageString) {
const message = parse(messageString);
if (message.action !== action) {
return;
}
cb(msg.error, msg.message);
cb(message.error, message.data);
});
}
@ -83,7 +89,7 @@ class IPC {
if (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() {

View File

@ -29,7 +29,7 @@ class RunCode {
}
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};
}
}

View File

@ -1,6 +1,9 @@
/*global web3 */
let __embarkSwarm = {_swarmConnection: undefined};
import SwarmAPI from 'swarm-api';
let SwarmAPI = require('swarm-api');
if (SwarmAPI.default) {
SwarmAPI = SwarmAPI.default;
}
__embarkSwarm.setProvider = function (options) {
let protocol = options.protocol || 'http';

5
package-lock.json generated
View File

@ -3719,6 +3719,11 @@
"resolved": "https://registry.npmjs.org/flatmap/-/flatmap-0.0.3.tgz",
"integrity": "sha1-Hxik2TgVLUlZZfnJWNkjqy3WabQ="
},
"flatted": {
"version": "0.2.3",
"resolved": "https://registry.npmjs.org/flatted/-/flatted-0.2.3.tgz",
"integrity": "sha512-C4B5UtK3kOrLAyZ1ftqEWprxCfLmCIqEcNufZrtsJhiZ/fcI5mvCgtAtC3pu7BC9KE7aUIrPXwTgcT1fiI7QhA=="
},
"flatten": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/flatten/-/flatten-1.0.2.tgz",

View File

@ -47,6 +47,7 @@
"ethereumjs-wallet": "0.6.0",
"file-loader": "^1.1.5",
"finalhandler": "^1.1.1",
"flatted": "^0.2.3",
"follow-redirects": "^1.2.4",
"fs-extra": "^2.0.0",
"ganache-cli": "^6.1.6",