diff --git a/lib/cmds/blockchain/blockchain.js b/lib/cmds/blockchain/blockchain.js index 45daa575..8226a4a4 100644 --- a/lib/cmds/blockchain/blockchain.js +++ b/lib/cmds/blockchain/blockchain.js @@ -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 }; diff --git a/lib/cmds/blockchain/geth_commands.js b/lib/cmds/blockchain/geth_commands.js index 8712a30f..57d87dc2 100644 --- a/lib/cmds/blockchain/geth_commands.js +++ b/lib/cmds/blockchain/geth_commands.js @@ -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')) { diff --git a/lib/contracts/code_generator.js b/lib/contracts/code_generator.js index 54850098..16a58a59 100644 --- a/lib/contracts/code_generator.js +++ b/lib/contracts/code_generator.js @@ -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; } diff --git a/lib/core/config.js b/lib/core/config.js index a4a4f3d3..9ea787ee 100644 --- a/lib/core/config.js +++ b/lib/core/config.js @@ -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" + } } }; diff --git a/test_app/config/blockchain.json b/test_app/config/blockchain.json index 1dcf4256..816d82c3 100644 --- a/test_app/config/blockchain.json +++ b/test_app/config/blockchain.json @@ -12,7 +12,8 @@ "rpcCorsDomain": "http://localhost:8000", "account": { "password": "config/development/password" - } + }, + "wsOrigins": "http://localhost:8000" }, "testnet": { "networkType": "testnet", diff --git a/test_app/config/communication.json b/test_app/config/communication.json index 07c7851a..80ec2f80 100644 --- a/test_app/config/communication.json +++ b/test_app/config/communication.json @@ -2,6 +2,11 @@ "default": { "enabled": true, "provider": "whisper", - "available_providers": ["whisper", "orbit"] + "available_providers": ["whisper", "orbit"], + "connection": { + "host": "localhost", + "port": 8546, + "type": "ws" + } } }