mirror of
https://github.com/status-im/embark-area-51.git
synced 2025-01-11 06:25:57 +00:00
refactor run actions for events to a reduce; add initial plug for shouldDeploy using deployIf
This commit is contained in:
parent
3fe1cd4a2c
commit
a56431d19a
@ -138,15 +138,20 @@ Plugins.prototype.runActionsForEvent = function(eventName, args, cb) {
|
|||||||
let actionPlugins = this.getPluginsProperty('eventActions', 'eventActions', eventName);
|
let actionPlugins = this.getPluginsProperty('eventActions', 'eventActions', eventName);
|
||||||
|
|
||||||
if (actionPlugins.length === 0) {
|
if (actionPlugins.length === 0) {
|
||||||
return cb();
|
return cb(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
async.eachLimit(actionPlugins, 1, function(plugin, nextEach) {
|
//async.eachLimit(actionPlugins, 1, function(plugin, nextEach) {
|
||||||
|
async.reduce(actionPlugins, args, function(current_args, plugin, nextEach) {
|
||||||
if (typeof (args) === 'function') {
|
if (typeof (args) === 'function') {
|
||||||
plugin.call(plugin, nextEach);
|
plugin.call(plugin, (params) => {
|
||||||
|
nextEach(null, (params || current_args));
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
//plugin.call(plugin, ...args, nextEach);
|
//plugin.call(plugin, ...args, nextEach);
|
||||||
plugin.call(plugin, args, nextEach);
|
plugin.call(plugin, args, (params) => {
|
||||||
|
nextEach(null, (params || current_args));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}, cb);
|
}, cb);
|
||||||
};
|
};
|
||||||
|
@ -145,8 +145,15 @@ class ContractDeployer {
|
|||||||
return self.deployContract(contract, next);
|
return self.deployContract(contract, next);
|
||||||
}
|
}
|
||||||
// TODO: this should be a plugin API instead, if not existing, it should by default deploy the contract
|
// TODO: this should be a plugin API instead, if not existing, it should by default deploy the contract
|
||||||
self.events.request("deploy:contract:shouldDeploy", contract, function(trackedContract) {
|
//self.events.request("deploy:contract:shouldDeploy", contract, function(trackedContract) {
|
||||||
if (!trackedContract) {
|
self.plugins.emitAndRunActionsForEvent('deploy:contract:shouldDeploy', {contract: contract, shouldDeploy: true}, function(_err, params) {
|
||||||
|
console.dir(contract.className);
|
||||||
|
console.dir(arguments);
|
||||||
|
let trackedContract = params.contract;
|
||||||
|
if (!params.shouldDeploy) {
|
||||||
|
return next();
|
||||||
|
}
|
||||||
|
if (!trackedContract.address) {
|
||||||
return self.deployContract(contract, next);
|
return self.deployContract(contract, next);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -213,7 +220,9 @@ class ContractDeployer {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
function applyBeforeDeploy(next) {
|
function applyBeforeDeploy(next) {
|
||||||
self.plugins.emitAndRunActionsForEvent('deploy:contract:beforeDeploy', {contract: contract}, next);
|
self.plugins.emitAndRunActionsForEvent('deploy:contract:beforeDeploy', {contract: contract}, () => {
|
||||||
|
next();
|
||||||
|
});
|
||||||
},
|
},
|
||||||
function getGasPriceForNetwork(next) {
|
function getGasPriceForNetwork(next) {
|
||||||
self.events.request("blockchain:gasPrice", (gasPrice) => {
|
self.events.request("blockchain:gasPrice", (gasPrice) => {
|
||||||
|
@ -6,6 +6,7 @@ class DeployTracker {
|
|||||||
constructor(embark, options) {
|
constructor(embark, options) {
|
||||||
this.logger = embark.logger;
|
this.logger = embark.logger;
|
||||||
this.events = embark.events;
|
this.events = embark.events;
|
||||||
|
this.embark = embark;
|
||||||
|
|
||||||
// TODO: unclear where it comes from
|
// TODO: unclear where it comes from
|
||||||
this.env = options.env;
|
this.env = options.env;
|
||||||
@ -24,9 +25,17 @@ class DeployTracker {
|
|||||||
self.save();
|
self.save();
|
||||||
});
|
});
|
||||||
|
|
||||||
this.events.setCommandHandler("deploy:contract:shouldDeploy", (contract, cb) => {
|
//this.events.setCommandHandler("deploy:contract:shouldDeploy", (contract, cb) => {
|
||||||
|
self.embark.registerActionForEvent("deploy:contract:shouldDeploy", (params, cb) => {
|
||||||
|
let contract = params.contract;
|
||||||
let trackedContract = self.getContract(contract.className, contract.realRuntimeBytecode, contract.realArgs);
|
let trackedContract = self.getContract(contract.className, contract.realRuntimeBytecode, contract.realArgs);
|
||||||
cb(trackedContract);
|
if (trackedContract) {
|
||||||
|
params.contract.address = trackedContract.address;
|
||||||
|
}
|
||||||
|
if (params.shouldDeploy && trackedContract) {
|
||||||
|
params.shouldDeploy = true;
|
||||||
|
}
|
||||||
|
cb(params);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ class SpecialConfigs {
|
|||||||
|
|
||||||
this.registerAfterDeployAction();
|
this.registerAfterDeployAction();
|
||||||
this.registerOnDeployAction();
|
this.registerOnDeployAction();
|
||||||
|
this.registerDeployIfAction()
|
||||||
}
|
}
|
||||||
|
|
||||||
replaceWithAddresses(cmd, cb) {
|
replaceWithAddresses(cmd, cb) {
|
||||||
@ -104,6 +105,26 @@ class SpecialConfigs {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
registerDeployIfAction() {
|
||||||
|
const self = this;
|
||||||
|
|
||||||
|
self.embark.registerActionForEvent("deploy:contract:shouldDeploy", (params, cb) => {
|
||||||
|
console.dir(params.contract.className)
|
||||||
|
console.dir(params.contract.classNideployIf)
|
||||||
|
self.embark.logger.info("===applying shouldDeploy plugin...");
|
||||||
|
if (params.contract.deployIf === 'hello') {
|
||||||
|
console.dir("-------------")
|
||||||
|
console.dir("-------------")
|
||||||
|
console.dir("contract has the param")
|
||||||
|
console.dir("-------------")
|
||||||
|
console.dir("-------------")
|
||||||
|
}
|
||||||
|
params.shouldDeploy = (params.contract.deployIf !== 'hello');
|
||||||
|
//cb(true, contract);
|
||||||
|
cb(params);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = SpecialConfigs;
|
module.exports = SpecialConfigs;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user