From f38d0e886cddc413d30bae306f0891eff3c3ff82 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Fri, 26 Aug 2016 07:51:58 -0400 Subject: [PATCH] use blockchain config to determine rpc host and port --- lib/abi.js | 7 ++++--- lib/blockchain.js | 11 ++++++----- lib/index.js | 11 ++++++++--- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/lib/abi.js b/lib/abi.js index 5b45951bb..06783221f 100644 --- a/lib/abi.js +++ b/lib/abi.js @@ -1,8 +1,9 @@ -var ABIGenerator = function(contractsManager) { +var ABIGenerator = function(blockchainConfig, contractsManager) { + this.blockchainConfig = blockchainConfig; this.contractsManager = contractsManager; - this.rpcHost = 'localhost'; - this.rpcPort = '8545'; + this.rpcHost = blockchainConfig.rpcHost; + this.rpcPort = blockchainConfig.rpcPort; }; ABIGenerator.prototype.generateProvider = function() { diff --git a/lib/blockchain.js b/lib/blockchain.js index 7def6c252..2d7867ef6 100644 --- a/lib/blockchain.js +++ b/lib/blockchain.js @@ -1,7 +1,8 @@ var mkdirp = require('mkdirp'); var wrench = require('wrench'); -var Blockchain = function() { +var Blockchain = function(blockchainConfig) { + this.blockchainConfig = blockchainConfig; }; Blockchain.prototype.run = function(options) { @@ -101,8 +102,8 @@ Blockchain.prototype.generate_basic_command = function() { cmd += "--port " + "30303" + " "; cmd += "--rpc "; - cmd += "--rpcport " + 8545 + " "; - cmd += "--rpcaddr " + "localhost" + " "; + cmd += "--rpcport " + this.blockchainConfig.rpcPort + " "; + cmd += "--rpcaddr " + this.blockchainConfig.rpcHost + " "; cmd += "--networkid " + "12301" + " "; cmd += "--rpccorsdomain=\"" + "*" + "\" "; @@ -170,9 +171,9 @@ Blockchain.prototype.getStartChainCommand = function(use_tmp) { }; -var BlockchainClient = function(client) { +var BlockchainClient = function(blockchainConfig, client) { if (client === 'geth') { - return new Blockchain(); + return new Blockchain(blockchainConfig); } else { throw new Error('unknown client'); } diff --git a/lib/index.js b/lib/index.js index f26659400..c4e697fb2 100644 --- a/lib/index.js +++ b/lib/index.js @@ -90,7 +90,7 @@ var Embark = { }, blockchain: function(env, client) { - var blockchain = Blockchain(client); + var blockchain = Blockchain(this.config.blockchainConfig, client); blockchain.run({env: env}); }, @@ -107,15 +107,20 @@ var Embark = { callback(null, contractsManager); }, function deployContracts(contractsManager, callback) { + + //TODO: figure out where to put this since the web3 can be passed along if needed + // perhaps it should go into the deploy object itself var web3 = new Web3(); - web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545')); + var web3Endpoint = 'http://' + self.config.blockchainConfig.rpcHost + ':' + self.config.blockchainConfig.rpcPort; + web3.setProvider(new web3.providers.HttpProvider(web3Endpoint)); + var deploy = new Deploy(web3, contractsManager); deploy.deployAll(function() { callback(null, contractsManager); }); }, function generateABI(contractsManager, callback) { - var abiGenerator = new ABIGenerator(contractsManager); + var abiGenerator = new ABIGenerator(self.config.blockchainConfig, contractsManager); callback(null, abiGenerator.generateABI()); }, ], function(err, result) {