From ba66d763fec4940be5d4e804355a9f3026229c1a Mon Sep 17 00:00:00 2001 From: emizzle Date: Tue, 19 Jun 2018 15:14:37 +1000 Subject: [PATCH] Add support for infura network hosts with api key. Fix bug with non-development code generation. --- lib/contracts/blockchain.js | 15 +++++++++++---- lib/contracts/code_generator.js | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/contracts/blockchain.js b/lib/contracts/blockchain.js index 0474cec9..6f6e4e15 100644 --- a/lib/contracts/blockchain.js +++ b/lib/contracts/blockchain.js @@ -1,7 +1,6 @@ const Web3 = require('web3'); const async = require('async'); const Provider = require('./provider.js'); -const http = require('http'); const BlockchainProcessLauncher = require('../processes/blockchainProcessLauncher'); const utils = require('../utils/utils'); const constants = require('../constants'); @@ -274,9 +273,17 @@ class Blockchain { Origin: origin }; } - - const req = http.get(options); - + let req; + // remove trailing api key from infura, ie rinkeby.infura.io/nmY8WtT4QfEwz2S7wTbl + if(options.host.indexOf('/') > -1){ + options.host = options.host.split('/')[0]; + } + if((self.contractsConfig.deployment.protocol || 'http') === 'https'){ + req = require('https').get(options); + }else{ + req = require('http').get(options); + } + req.on('error', (err) => { next(err); }); diff --git a/lib/contracts/code_generator.js b/lib/contracts/code_generator.js index 9a02f519..ef9fb651 100644 --- a/lib/contracts/code_generator.js +++ b/lib/contracts/code_generator.js @@ -137,7 +137,7 @@ class CodeGenerator { if (self.env === 'development') { web3Load = Templates.web3_connector({connectionList: connectionList, done: 'done();', warnAboutMetamask: true}); } else { - web3Load = Templates.web3_connector({connectionList: connectionList, done: 'done();'}); + web3Load = Templates.web3_connector({connectionList: connectionList, done: 'done();', warnAboutMetamask: true}); } }