Skip to content

Commit a18fb65

Browse files
committed
Merge branch 'next' into develop
2 parents dd81354 + cd72a66 commit a18fb65

File tree

7 files changed

+76
-11
lines changed

7 files changed

+76
-11
lines changed

lib/cmds/blockchain/blockchain.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ var Blockchain = function(options) {
2828
maxpeers: ((this.blockchainConfig.maxpeers === 0) ? 0 : (this.blockchainConfig.maxpeers || 25)),
2929
bootnodes: this.blockchainConfig.bootnodes || "",
3030
rpcApi: (this.blockchainConfig.rpcApi || ['eth', 'web3', 'net']),
31+
wsHost: this.blockchainConfig.wsHost || 'localhost',
32+
wsPort: this.blockchainConfig.wsPort || 8546,
33+
wsOrigins: this.blockchainConfig.wsOrigins || false,
34+
wsApi: (this.blockchainConfig.wsApi || ['eth', 'web3', 'net', 'shh']),
3135
vmdebug: this.blockchainConfig.vmdebug || false
3236
};
3337

lib/cmds/blockchain/geth_commands.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class GethCommands {
7575
if (config.rpcCorsDomain) {
7676
if (config.rpcCorsDomain === '*') {
7777
console.log('==================================');
78+
console.log('rpcCorsDomain set to *');
7879
console.log('make sure you know what you are doing');
7980
console.log('==================================');
8081
}
@@ -88,10 +89,34 @@ class GethCommands {
8889
return cmd;
8990
}
9091

92+
determineWsOptions(config) {
93+
let cmd = "";
94+
95+
cmd += "--ws ";
96+
cmd += "--wsport " + config.wsPort + " ";
97+
cmd += "--wsaddr " + config.wsHost + " ";
98+
if (config.wsOrigins) {
99+
if (config.wsOrigins === '*') {
100+
console.log('==================================');
101+
console.log('rpcCorsDomain set to *');
102+
console.log('make sure you know what you are doing');
103+
console.log('==================================');
104+
}
105+
cmd += "--wsorigins \"" + config.wsOrigins + "\" ";
106+
} else {
107+
console.log('==================================');
108+
console.log('warning: cors is not set');
109+
console.log('==================================');
110+
}
111+
112+
return cmd;
113+
}
114+
91115
mainCommand(address, done) {
92116
let self = this;
93117
let config = this.config;
94118
let rpc_api = (this.config.rpcApi || ['eth', 'web3', 'net']);
119+
let ws_api = (this.config.wsApi || ['eth', 'web3', 'net']);
95120

96121
async.series([
97122
function commonOptions(callback) {
@@ -102,6 +127,10 @@ class GethCommands {
102127
let cmd = self.determineRpcOptions(self.config);
103128
callback(null, cmd);
104129
},
130+
function wsOptions(callback) {
131+
let cmd = self.determineWsOptions(self.config);
132+
callback(null, cmd);
133+
},
105134
function dontGetPeers(callback) {
106135
if (config.nodiscover) {
107136
return callback(null, "--nodiscover");
@@ -133,13 +162,17 @@ class GethCommands {
133162
function whisper(callback) {
134163
if (config.whisper) {
135164
rpc_api.push('shh');
165+
ws_api.push('shh');
136166
return callback(null, "--shh ");
137167
}
138168
callback("");
139169
},
140170
function rpcApi(callback) {
141171
callback(null, '--rpcapi "' + rpc_api.join(',') + '"');
142172
},
173+
function wsApi(callback) {
174+
callback(null, '--wsapi "' + ws_api.join(',') + '"');
175+
},
143176
function accountToUnlock(callback) {
144177
let accountAddress = "";
145178
if(config.hasOwnProperty('address') && config.account.hasOwnProperty('address')) {

lib/contracts/code_generator.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,11 @@ class CodeGenerator {
185185

186186
if (!useEmbarkJS || self.storageConfig === {}) return "";
187187

188+
result += Templates.define_when_env_loaded();
189+
188190
if (self.storageConfig.provider === 'ipfs' && self.storageConfig.enabled === true) {
189191
let block = "\nEmbarkJS.Storage.setProvider('" + self.storageConfig.provider + "', {server: '" + self.storageConfig.host + "', port: '" + self.storageConfig.port + "', getUrl: '" + self.storageConfig.getUrl + "'});";
190-
result += Templates.define_when_env_loaded({block: block});
192+
result += Templates.exec_when_env_loaded({block: block});
191193
}
192194

193195
return result;
@@ -203,18 +205,25 @@ class CodeGenerator {
203205
result += Templates.define_when_env_loaded();
204206

205207
let block;
208+
// TODO: refactor this
206209
if (self.communicationConfig.provider === 'whisper' && self.communicationConfig.enabled === true) {
207-
block = "\nEmbarkJS.Messages.setProvider('" + self.communicationConfig.provider + "');";
208-
result += Templates.define_when_env_loaded({block: block});
210+
if (self.communicationConfig.connection === undefined) {
211+
block = "\nEmbarkJS.Messages.setProvider('" + self.communicationConfig.provider + "');";
212+
} else {
213+
block = "\nEmbarkJS.Messages.setProvider('" + self.communicationConfig.provider + "', {server: '" + self.communicationConfig.connection.host + "', port: '" + self.communicationConfig.connection.port + "', type: '" + self.communicationConfig.connection.type + "'});";
214+
}
215+
result += Templates.exec_when_env_loaded({block: block});
209216
} else if (self.communicationConfig.provider === 'orbit' && self.communicationConfig.enabled === true) {
210-
if (self.communicationConfig.host === undefined && self.communicationConfig.port === undefined) {
217+
if (self.communicationConfig.connection === undefined) {
211218
block = "\nEmbarkJS.Messages.setProvider('" + self.communicationConfig.provider + "');";
212219
} else {
213-
block = "\nEmbarkJS.Messages.setProvider('" + self.communicationConfig.provider + "', {server: '" + self.communicationConfig.host + "', port: '" + self.communicationConfig.port + "'});";
220+
block = "\nEmbarkJS.Messages.setProvider('" + self.communicationConfig.provider + "', {server: '" + self.communicationConfig.connection.host + "', port: '" + self.communicationConfig.connection.port + "', type: '" + self.communicationConfig.connection.type + "'});";
214221
}
215-
result += Templates.define_when_env_loaded({block: block});
222+
result += Templates.exec_when_env_loaded({block: block});
216223
}
217224

225+
console.log(result);
226+
218227
return result;
219228
}
220229

lib/core/config.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,12 @@ Config.prototype.loadCommunicationConfigFile = function() {
160160
"default": {
161161
"enabled": true,
162162
"provider": "whisper",
163-
"available_providers": ["whisper", "orbit"]
163+
"available_providers": ["whisper", "orbit"],
164+
"connection": {
165+
"host": "localhost",
166+
"port": 8546,
167+
"type": "ws"
168+
}
164169
}
165170
};
166171

test/blockchain.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ describe('embark.Blockchain', function () {
3030
vmdebug: false,
3131
whisper: true,
3232
account: {},
33-
bootnodes: ""
33+
bootnodes: "",
34+
wsApi: [ "eth", "web3", "net", "shh" ],
35+
wsHost: "localhost",
36+
wsOrigins: false,
37+
wsPort: 8546
3438
};
3539
let blockchain = new Blockchain(config, 'geth');
3640

@@ -59,7 +63,11 @@ describe('embark.Blockchain', function () {
5963
vmdebug: false,
6064
whisper: false,
6165
account: {},
62-
bootnodes: ""
66+
bootnodes: "",
67+
wsApi: [ "eth", "web3", "net", "shh" ],
68+
wsHost: "localhost",
69+
wsOrigins: false,
70+
wsPort: 8546
6371
};
6472
let blockchain = new Blockchain(config, 'geth');
6573

test_app/config/blockchain.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"rpcCorsDomain": "http://localhost:8000",
1313
"account": {
1414
"password": "config/development/password"
15-
}
15+
},
16+
"wsOrigins": "http://localhost:8000"
1617
},
1718
"testnet": {
1819
"networkType": "testnet",

test_app/config/communication.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
"default": {
33
"enabled": true,
44
"provider": "whisper",
5-
"available_providers": ["whisper", "orbit"]
5+
"available_providers": ["whisper", "orbit"],
6+
"connection": {
7+
"host": "localhost",
8+
"port": 8546,
9+
"type": "ws"
10+
}
611
}
712
}

0 commit comments

Comments
 (0)