refactor contracts deployment

This commit is contained in:
Iuri Matias 2019-07-23 17:24:11 -04:00
parent d4f9fd2e58
commit d80f04850a
3 changed files with 121 additions and 113 deletions

View File

@ -1,18 +1,17 @@
import { __ } from 'embark-i18n';
const async = require('async');
async._waterfall = async.waterfall;
let filename = "index.js";
async.waterfall = function (_tasks, callback) {
let tasks = _tasks.map(function (t) {
let fn = function () {
console.log("async " + (new Error()).stack.split("\n")[1] + ": " + t.name);
t.apply(t, arguments);
};
return fn;
});
async._waterfall(tasks, callback);
};
// async._waterfall = async.waterfall;
// let filename = "index.js";
// async.waterfall = function (_tasks, callback) {
// let tasks = _tasks.map(function (t) {
// let fn = function () {
// console.log("async " + (new Error()).stack.split("\n")[1] + ": " + t.name);
// t.apply(t, arguments);
// };
// return fn;
// });
// async._waterfall(tasks, callback);
// };
const ContractDeployer = require('./contract_deployer.js');
const cloneDeep = require('clone-deep');
@ -39,29 +38,33 @@ class DeployManager {
plugins: this.plugins
});
this.events.setCommandHandler('deploy:setGasLimit', (gasLimit) => {
self.gasLimit = gasLimit;
this.events.setCommandHandler('deployment:contracts:deploy', (contractsList, contractDependencies, cb) => {
self.deployContracts(contractsList, contractDependencies, cb);
});
this.events.setCommandHandler('deploy:contracts', (cb) => {
self.deployContracts(cb);
});
// this.events.setCommandHandler('deploy:setGasLimit', (gasLimit) => {
// self.gasLimit = gasLimit;
// });
this.events.setCommandHandler('deploy:contracts:test', (cb) => {
self.fatalErrors = true;
self.deployOnlyOnConfig = true;
self.deployContracts(cb);
});
// this.events.setCommandHandler('deploy:contracts', (cb) => {
// self.deployContracts(cb);
// });
// this.events.setCommandHandler('deploy:contracts:test', (cb) => {
// self.fatalErrors = true;
// self.deployOnlyOnConfig = true;
// self.deployContracts(cb);
// });
}
deployAll(done) {
deployAll(contracts, contractDependencies, done) {
let self = this;
self.events.request('contracts:dependencies', (err, contractDependencies) => {
self.events.request('contracts:list', (err, contracts) => {
if (err) {
return done(err);
}
// self.events.request('contracts:dependencies', (err, contractDependencies) => {
// self.events.request('contracts:list', (err, contracts) => {
// if (err) {
// return done(err);
// }
self.logger.info(__("deploying contracts"));
async.waterfall([
@ -118,7 +121,7 @@ class DeployManager {
console.dir("== async.auto");
console.dir(Object.keys(contractDeploys));
console.dir(contractDeploys);
async.auto(contractDeploys, function(_err, _results) {
async.auto(contractDeploys, function (_err, _results) {
if (_err) {
console.dir("error deploying contracts")
console.dir(_err)
@ -144,11 +147,11 @@ class DeployManager {
}
done(err);
});
});
});
// });
// });
}
deployContracts(done) {
deployContracts(contractsList, contractDependencies, done) {
let self = this;
if (self.blockchainConfig === {} || self.blockchainConfig.enabled === false) {
@ -195,7 +198,7 @@ class DeployManager {
},
function deployAllContracts(callback) {
self.deployAll(function (err) {
self.deployAll(contractsList, contractDependencies, function (err) {
if (!err) {
self.events.emit('contractsDeployed');
}

View File

@ -218,8 +218,12 @@ class EmbarkController {
console.dir(_contractsConfig);
let contractsConfig = cloneDeep(_contractsConfig);
engine.events.request("contracts:build", contractsConfig, compiledContracts, () => {
engine.events.request("contracts:build", contractsConfig, compiledContracts, (err, contractsList, contractDependencies) => {
console.dir("contracts config build done")
engine.events.request("deployment:contracts:deploy", contractsList, contractDependencies, () => {
console.dir("deployment done")
})
})
})
})

View File

@ -154,6 +154,7 @@ class Engine {
contractsComponents(options) {
this.registerModulePackage('embark-contracts-manager', {plugins: this.plugins, compileOnceOnly: options.compileOnceOnly});
this.registerModulePackage('embark-deployment', {plugins: this.plugins, onlyCompile: options.onlyCompile});
}
startService(serviceName, _options) {