separate the different functions in deployContracts

This commit is contained in:
Iuri Matias 2017-03-04 20:14:47 -05:00
parent 5ec38694e4
commit a527573796

View File

@ -38,11 +38,7 @@ DeployManager.prototype.deployContracts = function(done) {
});
contractsManager.build(callback);
},
function deployContracts2(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
// TODO: should come from the config object
function connectWithWeb3(contractsManager, callback) {
var web3;
if (self.web3) {
web3 = self.web3;
@ -50,32 +46,35 @@ DeployManager.prototype.deployContracts = function(done) {
web3 = new Web3();
var web3Endpoint = 'http://' + self.config.blockchainConfig.rpcHost + ':' + self.config.blockchainConfig.rpcPort;
web3.setProvider(new web3.providers.HttpProvider(web3Endpoint));
if (!web3.isConnected()) {
self.logger.error(("Couldn't connect to " + web3Endpoint.underline + " are you sure it's on?").red);
self.logger.info("make sure you have an ethereum node or simulator running. e.g 'embark blockchain'".magenta);
return callback(Error("error connecting to blockchain node"));
}
}
callback(null, contractsManager, web3);
},
function setDefaultAccount(contractsManager, web3, callback) {
web3.eth.getAccounts(function(err, accounts) {
if (err) {
return callback(new Error(err));
}
var selectedAccount = self.config.blockchainConfig.account.address;
web3.eth.defaultAccount = (selectedAccount || accounts[0]);
var deploy = new Deploy({
web3: web3,
contractsManager: contractsManager,
logger: self.logger,
chainConfig: self.chainConfig,
env: self.config.env
});
deploy.deployAll(function() {
self.events.emit('contractsDeployed', contractsManager);
callback(null, contractsManager);
});
callback(null, contractsManager, web3);
});
},
function deployAllContracts(contractsManager, web3, callback) {
var deploy = new Deploy({
web3: web3,
contractsManager: contractsManager,
logger: self.logger,
chainConfig: self.chainConfig,
env: self.config.env
});
deploy.deployAll(function() {
self.events.emit('contractsDeployed', contractsManager);
callback(null, contractsManager);
});
}
], function(err, result) {