mirror of https://github.com/embarklabs/embark.git
add blockchain ws config support; fix whisper provider setting
This commit is contained in:
parent
460f78cc55
commit
e23e4bc417
|
@ -29,6 +29,10 @@ var Blockchain = function(options) {
|
||||||
maxpeers: ((this.blockchainConfig.maxpeers === 0) ? 0 : (this.blockchainConfig.maxpeers || 25)),
|
maxpeers: ((this.blockchainConfig.maxpeers === 0) ? 0 : (this.blockchainConfig.maxpeers || 25)),
|
||||||
bootnodes: this.blockchainConfig.bootnodes || "",
|
bootnodes: this.blockchainConfig.bootnodes || "",
|
||||||
rpcApi: (this.blockchainConfig.rpcApi || ['eth', 'web3', 'net']),
|
rpcApi: (this.blockchainConfig.rpcApi || ['eth', 'web3', 'net']),
|
||||||
|
wsHost: this.blockchainConfig.wsHost || 'localhost',
|
||||||
|
wsPort: this.blockchainConfig.wsPort || 8546,
|
||||||
|
wsOrigins: this.blockchainConfig.wsOrigins || false,
|
||||||
|
wsApi: (this.blockchainConfig.wsApi || ['eth', 'web3', 'net', 'shh']),
|
||||||
vmdebug: this.blockchainConfig.vmdebug || false
|
vmdebug: this.blockchainConfig.vmdebug || false
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -75,6 +75,7 @@ class GethCommands {
|
||||||
if (config.rpcCorsDomain) {
|
if (config.rpcCorsDomain) {
|
||||||
if (config.rpcCorsDomain === '*') {
|
if (config.rpcCorsDomain === '*') {
|
||||||
console.log('==================================');
|
console.log('==================================');
|
||||||
|
console.log('rpcCorsDomain set to *');
|
||||||
console.log('make sure you know what you are doing');
|
console.log('make sure you know what you are doing');
|
||||||
console.log('==================================');
|
console.log('==================================');
|
||||||
}
|
}
|
||||||
|
@ -88,10 +89,34 @@ class GethCommands {
|
||||||
return cmd;
|
return cmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
determineWsOptions(config) {
|
||||||
|
let cmd = "";
|
||||||
|
|
||||||
|
cmd += "--ws ";
|
||||||
|
cmd += "--wsport " + config.wsPort + " ";
|
||||||
|
cmd += "--wsaddr " + config.wsHost + " ";
|
||||||
|
if (config.wsOrigins) {
|
||||||
|
if (config.wsOrigins === '*') {
|
||||||
|
console.log('==================================');
|
||||||
|
console.log('rpcCorsDomain set to *');
|
||||||
|
console.log('make sure you know what you are doing');
|
||||||
|
console.log('==================================');
|
||||||
|
}
|
||||||
|
cmd += "--wsorigins \"" + config.wsOrigins + "\" ";
|
||||||
|
} else {
|
||||||
|
console.log('==================================');
|
||||||
|
console.log('warning: cors is not set');
|
||||||
|
console.log('==================================');
|
||||||
|
}
|
||||||
|
|
||||||
|
return cmd;
|
||||||
|
}
|
||||||
|
|
||||||
mainCommand(address, done) {
|
mainCommand(address, done) {
|
||||||
let self = this;
|
let self = this;
|
||||||
let config = this.config;
|
let config = this.config;
|
||||||
let rpc_api = (this.config.rpcApi || ['eth', 'web3', 'net']);
|
let rpc_api = (this.config.rpcApi || ['eth', 'web3', 'net']);
|
||||||
|
let ws_api = (this.config.wsApi || ['eth', 'web3', 'net']);
|
||||||
|
|
||||||
async.series([
|
async.series([
|
||||||
function commonOptions(callback) {
|
function commonOptions(callback) {
|
||||||
|
@ -102,6 +127,10 @@ class GethCommands {
|
||||||
let cmd = self.determineRpcOptions(self.config);
|
let cmd = self.determineRpcOptions(self.config);
|
||||||
callback(null, cmd);
|
callback(null, cmd);
|
||||||
},
|
},
|
||||||
|
function wsOptions(callback) {
|
||||||
|
let cmd = self.determineWsOptions(self.config);
|
||||||
|
callback(null, cmd);
|
||||||
|
},
|
||||||
function dontGetPeers(callback) {
|
function dontGetPeers(callback) {
|
||||||
if (config.nodiscover) {
|
if (config.nodiscover) {
|
||||||
return callback(null, "--nodiscover");
|
return callback(null, "--nodiscover");
|
||||||
|
@ -133,6 +162,7 @@ class GethCommands {
|
||||||
function whisper(callback) {
|
function whisper(callback) {
|
||||||
if (config.whisper) {
|
if (config.whisper) {
|
||||||
rpc_api.push('shh');
|
rpc_api.push('shh');
|
||||||
|
ws_api.push('shh');
|
||||||
return callback(null, "--shh ");
|
return callback(null, "--shh ");
|
||||||
}
|
}
|
||||||
callback("");
|
callback("");
|
||||||
|
@ -140,6 +170,9 @@ class GethCommands {
|
||||||
function rpcApi(callback) {
|
function rpcApi(callback) {
|
||||||
callback(null, '--rpcapi "' + rpc_api.join(',') + '"');
|
callback(null, '--rpcapi "' + rpc_api.join(',') + '"');
|
||||||
},
|
},
|
||||||
|
function wsApi(callback) {
|
||||||
|
callback(null, '--wsapi "' + ws_api.join(',') + '"');
|
||||||
|
},
|
||||||
function accountToUnlock(callback) {
|
function accountToUnlock(callback) {
|
||||||
let accountAddress = "";
|
let accountAddress = "";
|
||||||
if(config.hasOwnProperty('address') && config.account.hasOwnProperty('address')) {
|
if(config.hasOwnProperty('address') && config.account.hasOwnProperty('address')) {
|
||||||
|
|
|
@ -185,9 +185,11 @@ class CodeGenerator {
|
||||||
|
|
||||||
if (!useEmbarkJS || self.storageConfig === {}) return "";
|
if (!useEmbarkJS || self.storageConfig === {}) return "";
|
||||||
|
|
||||||
|
result += Templates.define_when_env_loaded();
|
||||||
|
|
||||||
if (self.storageConfig.provider === 'ipfs' && self.storageConfig.enabled === true) {
|
if (self.storageConfig.provider === 'ipfs' && self.storageConfig.enabled === true) {
|
||||||
let block = "\nEmbarkJS.Storage.setProvider('" + self.storageConfig.provider + "', {server: '" + self.storageConfig.host + "', port: '" + self.storageConfig.port + "', getUrl: '" + self.storageConfig.getUrl + "'});";
|
let block = "\nEmbarkJS.Storage.setProvider('" + self.storageConfig.provider + "', {server: '" + self.storageConfig.host + "', port: '" + self.storageConfig.port + "', getUrl: '" + self.storageConfig.getUrl + "'});";
|
||||||
result += Templates.define_when_env_loaded({block: block});
|
result += Templates.exec_when_env_loaded({block: block});
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -203,17 +205,24 @@ class CodeGenerator {
|
||||||
result += Templates.define_when_env_loaded();
|
result += Templates.define_when_env_loaded();
|
||||||
|
|
||||||
let block;
|
let block;
|
||||||
|
// TODO: refactor this
|
||||||
if (self.communicationConfig.provider === 'whisper' && self.communicationConfig.enabled === true) {
|
if (self.communicationConfig.provider === 'whisper' && self.communicationConfig.enabled === true) {
|
||||||
block = "\nEmbarkJS.Messages.setProvider('" + self.communicationConfig.provider + "');";
|
if (self.communicationConfig.connection === undefined) {
|
||||||
result += Templates.define_when_env_loaded({block: block});
|
|
||||||
} else if (self.communicationConfig.provider === 'orbit' && self.communicationConfig.enabled === true) {
|
|
||||||
if (self.communicationConfig.host === undefined && self.communicationConfig.port === undefined) {
|
|
||||||
block = "\nEmbarkJS.Messages.setProvider('" + self.communicationConfig.provider + "');";
|
block = "\nEmbarkJS.Messages.setProvider('" + self.communicationConfig.provider + "');";
|
||||||
} else {
|
} else {
|
||||||
block = "\nEmbarkJS.Messages.setProvider('" + self.communicationConfig.provider + "', {server: '" + self.communicationConfig.host + "', port: '" + self.communicationConfig.port + "'});";
|
block = "\nEmbarkJS.Messages.setProvider('" + self.communicationConfig.provider + "', {server: '" + self.communicationConfig.connection.host + "', port: '" + self.communicationConfig.connection.port + "', type: '" + self.communicationConfig.connection.type + "'});";
|
||||||
}
|
}
|
||||||
result += Templates.define_when_env_loaded({block: block});
|
result += Templates.exec_when_env_loaded({block: block});
|
||||||
|
} else if (self.communicationConfig.provider === 'orbit' && self.communicationConfig.enabled === true) {
|
||||||
|
if (self.communicationConfig.connection === undefined) {
|
||||||
|
block = "\nEmbarkJS.Messages.setProvider('" + self.communicationConfig.provider + "');";
|
||||||
|
} else {
|
||||||
|
block = "\nEmbarkJS.Messages.setProvider('" + self.communicationConfig.provider + "', {server: '" + self.communicationConfig.connection.host + "', port: '" + self.communicationConfig.connection.port + "', type: '" + self.communicationConfig.connection.type + "'});";
|
||||||
}
|
}
|
||||||
|
result += Templates.exec_when_env_loaded({block: block});
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(result);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -160,7 +160,12 @@ Config.prototype.loadCommunicationConfigFile = function() {
|
||||||
"default": {
|
"default": {
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
"provider": "whisper",
|
"provider": "whisper",
|
||||||
"available_providers": ["whisper", "orbit"]
|
"available_providers": ["whisper", "orbit"],
|
||||||
|
"connection": {
|
||||||
|
"host": "localhost",
|
||||||
|
"port": 8546,
|
||||||
|
"type": "ws"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,8 @@
|
||||||
"rpcCorsDomain": "http://localhost:8000",
|
"rpcCorsDomain": "http://localhost:8000",
|
||||||
"account": {
|
"account": {
|
||||||
"password": "config/development/password"
|
"password": "config/development/password"
|
||||||
}
|
},
|
||||||
|
"wsOrigins": "http://localhost:8000"
|
||||||
},
|
},
|
||||||
"testnet": {
|
"testnet": {
|
||||||
"networkType": "testnet",
|
"networkType": "testnet",
|
||||||
|
|
|
@ -2,6 +2,11 @@
|
||||||
"default": {
|
"default": {
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
"provider": "whisper",
|
"provider": "whisper",
|
||||||
"available_providers": ["whisper", "orbit"]
|
"available_providers": ["whisper", "orbit"],
|
||||||
|
"connection": {
|
||||||
|
"host": "localhost",
|
||||||
|
"port": 8546,
|
||||||
|
"type": "ws"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue