add deployIf directive support

This commit is contained in:
Iuri Matias 2018-08-23 18:00:52 -04:00
parent a56431d19a
commit 8f5b47adf4
6 changed files with 21 additions and 20 deletions

View File

@ -141,14 +141,12 @@ Plugins.prototype.runActionsForEvent = function(eventName, args, cb) {
return cb(args); return cb(args);
} }
//async.eachLimit(actionPlugins, 1, function(plugin, nextEach) {
async.reduce(actionPlugins, args, function(current_args, plugin, nextEach) { async.reduce(actionPlugins, args, function(current_args, plugin, nextEach) {
if (typeof (args) === 'function') { if (typeof (args) === 'function') {
plugin.call(plugin, (params) => { plugin.call(plugin, (params) => {
nextEach(null, (params || current_args)); nextEach(null, (params || current_args));
}); });
} else { } else {
//plugin.call(plugin, ...args, nextEach);
plugin.call(plugin, args, (params) => { plugin.call(plugin, args, (params) => {
nextEach(null, (params || current_args)); nextEach(null, (params || current_args));
}); });

View File

@ -144,11 +144,7 @@ class ContractDeployer {
if (process.env.isTest) { if (process.env.isTest) {
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
//self.events.request("deploy:contract:shouldDeploy", contract, function(trackedContract) {
self.plugins.emitAndRunActionsForEvent('deploy:contract:shouldDeploy', {contract: contract, shouldDeploy: true}, function(_err, params) { self.plugins.emitAndRunActionsForEvent('deploy:contract:shouldDeploy', {contract: contract, shouldDeploy: true}, function(_err, params) {
console.dir(contract.className);
console.dir(arguments);
let trackedContract = params.contract; let trackedContract = params.contract;
if (!params.shouldDeploy) { if (!params.shouldDeploy) {
return next(); return next();

View File

@ -25,7 +25,6 @@ class DeployTracker {
self.save(); self.save();
}); });
//this.events.setCommandHandler("deploy:contract:shouldDeploy", (contract, cb) => {
self.embark.registerActionForEvent("deploy:contract:shouldDeploy", (params, cb) => { self.embark.registerActionForEvent("deploy:contract:shouldDeploy", (params, cb) => {
let contract = params.contract; let contract = params.contract;
let trackedContract = self.getContract(contract.className, contract.realRuntimeBytecode, contract.realArgs); let trackedContract = self.getContract(contract.className, contract.realRuntimeBytecode, contract.realArgs);

View File

@ -12,7 +12,7 @@ class SpecialConfigs {
this.registerAfterDeployAction(); this.registerAfterDeployAction();
this.registerOnDeployAction(); this.registerOnDeployAction();
this.registerDeployIfAction() this.registerDeployIfAction();
} }
replaceWithAddresses(cmd, cb) { replaceWithAddresses(cmd, cb) {
@ -109,20 +109,24 @@ class SpecialConfigs {
const self = this; const self = this;
self.embark.registerActionForEvent("deploy:contract:shouldDeploy", (params, cb) => { self.embark.registerActionForEvent("deploy:contract:shouldDeploy", (params, cb) => {
console.dir(params.contract.className) let cmd = params.contract.deployIf;
console.dir(params.contract.classNideployIf) if (!cmd) {
self.embark.logger.info("===applying shouldDeploy plugin..."); return cb(params);
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); self.events.request('runcode:eval', cmd, (err, result) => {
if (err) {
self.logger.error(params.contract.className + ' deployIf directive has an error; contract will not deploy');
self.logger.error(err);
params.shouldDeploy = false;
} else if (!result) {
self.logger.info(params.contract.className + ' deployIf directive returned false; contract will not deploy');
params.shouldDeploy = false;
}
cb(params); cb(params);
}); });
});
} }
} }

View File

@ -53,6 +53,7 @@ module.exports = {
} }
}, },
SomeContract: { SomeContract: {
deployIf: 'MyToken.methods.isAvailable().call()',
args: [ args: [
["$MyToken2", "$SimpleStorage"], ["$MyToken2", "$SimpleStorage"],
100 100

View File

@ -63,4 +63,7 @@ contract Token {
function safeToAdd(uint a, uint b) internal pure returns (bool) { function safeToAdd(uint a, uint b) internal pure returns (bool) {
return (a + b >= a); return (a + b >= a);
} }
function isAvailable() public constant returns (bool) {
return true;
}
} }