refactor deploy method
This commit is contained in:
parent
f4010bd66e
commit
cf13f098ac
|
@ -102,14 +102,14 @@ class Deploy {
|
|||
// 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) {
|
||||
if (!trackedContract) {
|
||||
return self.contractToDeploy(contract, params, next);
|
||||
return self.deployContract(contract, next);
|
||||
}
|
||||
|
||||
self.blockchain.getCode(trackedContract.address, function(_getCodeErr, codeInChain) {
|
||||
if (codeInChain !== "0x") {
|
||||
self.contractAlreadyDeployed(contract, trackedContract, next);
|
||||
} else {
|
||||
self.contractToDeploy(contract, params, next);
|
||||
self.deployContract(contract, next);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -131,38 +131,10 @@ class Deploy {
|
|||
});
|
||||
}
|
||||
|
||||
contractToDeploy(contract, params, callback) {
|
||||
const self = this;
|
||||
|
||||
// TODO: this whole callback is almost pointless and should be moved to deployContract
|
||||
this.deployContract(contract, contract.realArgs, function (err, address) {
|
||||
if (err) {
|
||||
self.events.emit("deploy:contract:error", contract);
|
||||
return callback(new Error(err));
|
||||
}
|
||||
contract.address = address;
|
||||
self.events.emit("deploy:contract:deployed", contract);
|
||||
|
||||
// TODO: can be moved into a afterDeploy event
|
||||
// just need to figure out the gasLimit coupling issue
|
||||
self.events.request('code-generator:contract:vanilla', contract, self.gasLimit, (contractCode) => {
|
||||
self.events.request('runcode:eval', contractCode);
|
||||
|
||||
let onDeployPlugins = self.plugins.getPluginsProperty('onDeployActions', 'onDeployActions');
|
||||
|
||||
async.eachLimit(onDeployPlugins, 1, function(plugin, nextEach) {
|
||||
plugin.call(plugin, contract, nextEach);
|
||||
}, () => {
|
||||
callback();
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
deployContract(contract, params, callback) {
|
||||
deployContract(contract, callback) {
|
||||
let self = this;
|
||||
let accounts = [];
|
||||
let contractParams = (params || contract.args).slice();
|
||||
let contractParams = (contract.realArgs || contract.args).slice();
|
||||
let contractCode = contract.code;
|
||||
let deploymentAccount = self.blockchain.defaultAccount();
|
||||
let deployObject;
|
||||
|
@ -284,12 +256,29 @@ class Deploy {
|
|||
gasPrice: contract.gasPrice
|
||||
}, function(error, receipt) {
|
||||
if (error) {
|
||||
contract.error = error.message;
|
||||
self.events.emit("deploy:contract:error", contract);
|
||||
return next(new Error("error deploying =" + contract.className + "= due to error: " + error.message));
|
||||
}
|
||||
self.logger.info(contract.className.bold.cyan + " " + __("deployed at").green + " " + receipt.contractAddress.bold.cyan);
|
||||
contract.deployedAddress = receipt.contractAddress;
|
||||
contract.transactionHash = receipt.transactionHash;
|
||||
return next(null, receipt.contractAddress);
|
||||
self.events.emit("deploy:contract:receipt", receipt);
|
||||
self.events.emit("deploy:contract:deployed", contract);
|
||||
|
||||
// TODO: can be moved into a afterDeploy event
|
||||
// just need to figure out the gasLimit coupling issue
|
||||
self.events.request('code-generator:contract:vanilla', contract, self.gasLimit, (contractCode) => {
|
||||
self.events.request('runcode:eval', contractCode);
|
||||
|
||||
let onDeployPlugins = self.plugins.getPluginsProperty('onDeployActions', 'onDeployActions');
|
||||
|
||||
async.eachLimit(onDeployPlugins, 1, function(plugin, nextEach) {
|
||||
plugin.call(plugin, contract, nextEach);
|
||||
}, () => {
|
||||
return next(null, receipt);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
], callback);
|
||||
|
|
Loading…
Reference in New Issue