implemet afterDeploy cmds

This commit is contained in:
Iuri Matias 2017-12-21 11:21:36 -05:00
parent 7cdba7e4e3
commit 16afb4e405
2 changed files with 48 additions and 3 deletions

View File

@ -1,12 +1,14 @@
let async = require('async');
let Deploy = require('./deploy.js');
let ContractsManager = require('./contracts.js');
let RunCode = require('../core/runCode.js');
class DeployManager {
constructor(options) {
this.config = options.config;
this.logger = options.logger;
this.blockchainConfig = this.config.blockchainConfig;
this.events = options.events;
this.plugins = options.plugins;
this.web3 = options.web3;
@ -76,9 +78,48 @@ class DeployManager {
if (!err) {
self.events.emit('contractsDeployed', contractsManager);
}
//callback(err, contractsManager);
callback(null, contractsManager);
callback(null, contractsManager, web3);
});
},
function runAfterDeployCommands(contractsManager, web3, callback) {
let afterDeployCmds = self.config.contractsConfig.afterDeploy || [];
let withErrors = false;
let regex = /\$\w+/g;
let onDeployCode = afterDeployCmds.map((cmd) => {
let realCmd = cmd.replace(regex, (match) => {
let referedContractName = match.slice(1);
let referedContract = contractsManager.getContract(referedContractName);
if (!referedContract) {
self.logger.error(referedContractName + ' does not exist');
self.logger.error("error running afterDeploy: " + cmd);
withErrors = true;
return;
}
if (referedContract && referedContract.deploy === false) {
self.logger.error(referedContractName + " exists but has been set to not deploy");
self.logger.error("error running afterDeploy: " + cmd);
withErrors = true;
return;
}
if (referedContract && !referedContract.deployedAddress) {
self.logger.error("couldn't find a valid address for " + referedContractName + ". has it been deployed?");
self.logger.error("error running afterDeploy: " + cmd);
withErrors = true;
return;
}
return referedContract.deployedAddress;
});
return realCmd;
});
if (withErrors) {
return callback(new Error("error running afterDeploy"));
}
RunCode.doEval(onDeployCode.join(';\n'), web3);
callback(null, contractsManager);
}
], function (err, result) {
if (err) {

View File

@ -53,7 +53,11 @@
"MyToken3": {
"instanceOf": "Tokn"
}
}
},
"afterDeploy": [
"Test.changeAddress('$MyToken')",
"Test.changeAddress(web3.eth.accounts[1])"
]
},
"development": {
"contracts": {