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)),
|
||||
bootnodes: this.blockchainConfig.bootnodes || "",
|
||||
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
|
||||
};
|
||||
|
||||
|
|
|
@ -75,6 +75,7 @@ class GethCommands {
|
|||
if (config.rpcCorsDomain) {
|
||||
if (config.rpcCorsDomain === '*') {
|
||||
console.log('==================================');
|
||||
console.log('rpcCorsDomain set to *');
|
||||
console.log('make sure you know what you are doing');
|
||||
console.log('==================================');
|
||||
}
|
||||
|
@ -88,10 +89,34 @@ class GethCommands {
|
|||
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) {
|
||||
let self = this;
|
||||
let config = this.config;
|
||||
let rpc_api = (this.config.rpcApi || ['eth', 'web3', 'net']);
|
||||
let ws_api = (this.config.wsApi || ['eth', 'web3', 'net']);
|
||||
|
||||
async.series([
|
||||
function commonOptions(callback) {
|
||||
|
@ -102,6 +127,10 @@ class GethCommands {
|
|||
let cmd = self.determineRpcOptions(self.config);
|
||||
callback(null, cmd);
|
||||
},
|
||||
function wsOptions(callback) {
|
||||
let cmd = self.determineWsOptions(self.config);
|
||||
callback(null, cmd);
|
||||
},
|
||||
function dontGetPeers(callback) {
|
||||
if (config.nodiscover) {
|
||||
return callback(null, "--nodiscover");
|
||||
|
@ -133,6 +162,7 @@ class GethCommands {
|
|||
function whisper(callback) {
|
||||
if (config.whisper) {
|
||||
rpc_api.push('shh');
|
||||
ws_api.push('shh');
|
||||
return callback(null, "--shh ");
|
||||
}
|
||||
callback("");
|
||||
|
@ -140,6 +170,9 @@ class GethCommands {
|
|||
function rpcApi(callback) {
|
||||
callback(null, '--rpcapi "' + rpc_api.join(',') + '"');
|
||||
},
|
||||
function wsApi(callback) {
|
||||
callback(null, '--wsapi "' + ws_api.join(',') + '"');
|
||||
},
|
||||
function accountToUnlock(callback) {
|
||||
let accountAddress = "";
|
||||
if(config.hasOwnProperty('address') && config.account.hasOwnProperty('address')) {
|
||||
|
|
|
@ -185,9 +185,11 @@ class CodeGenerator {
|
|||
|
||||
if (!useEmbarkJS || self.storageConfig === {}) return "";
|
||||
|
||||
result += Templates.define_when_env_loaded();
|
||||
|
||||
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 + "'});";
|
||||
result += Templates.define_when_env_loaded({block: block});
|
||||
result += Templates.exec_when_env_loaded({block: block});
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -203,18 +205,25 @@ class CodeGenerator {
|
|||
result += Templates.define_when_env_loaded();
|
||||
|
||||
let block;
|
||||
// TODO: refactor this
|
||||
if (self.communicationConfig.provider === 'whisper' && self.communicationConfig.enabled === true) {
|
||||
block = "\nEmbarkJS.Messages.setProvider('" + self.communicationConfig.provider + "');";
|
||||
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) {
|
||||
if (self.communicationConfig.connection === undefined) {
|
||||
block = "\nEmbarkJS.Messages.setProvider('" + self.communicationConfig.provider + "');";
|
||||
} 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -160,7 +160,12 @@ Config.prototype.loadCommunicationConfigFile = function() {
|
|||
"default": {
|
||||
"enabled": true,
|
||||
"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",
|
||||
"account": {
|
||||
"password": "config/development/password"
|
||||
}
|
||||
},
|
||||
"wsOrigins": "http://localhost:8000"
|
||||
},
|
||||
"testnet": {
|
||||
"networkType": "testnet",
|
||||
|
|
|
@ -2,6 +2,11 @@
|
|||
"default": {
|
||||
"enabled": true,
|
||||
"provider": "whisper",
|
||||
"available_providers": ["whisper", "orbit"]
|
||||
"available_providers": ["whisper", "orbit"],
|
||||
"connection": {
|
||||
"host": "localhost",
|
||||
"port": 8546,
|
||||
"type": "ws"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue