mirror of
https://github.com/status-im/embark-area-51.git
synced 2025-02-18 18:26:50 +00:00
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
|
// 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) {
|
if (!trackedContract) {
|
||||||
return self.contractToDeploy(contract, params, next);
|
return self.deployContract(contract, next);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.blockchain.getCode(trackedContract.address, function(_getCodeErr, codeInChain) {
|
self.blockchain.getCode(trackedContract.address, function(_getCodeErr, codeInChain) {
|
||||||
if (codeInChain !== "0x") {
|
if (codeInChain !== "0x") {
|
||||||
self.contractAlreadyDeployed(contract, trackedContract, next);
|
self.contractAlreadyDeployed(contract, trackedContract, next);
|
||||||
} else {
|
} else {
|
||||||
self.contractToDeploy(contract, params, next);
|
self.deployContract(contract, next);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -131,38 +131,10 @@ class Deploy {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
contractToDeploy(contract, params, callback) {
|
deployContract(contract, 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) {
|
|
||||||
let self = this;
|
let self = this;
|
||||||
let accounts = [];
|
let accounts = [];
|
||||||
let contractParams = (params || contract.args).slice();
|
let contractParams = (contract.realArgs || contract.args).slice();
|
||||||
let contractCode = contract.code;
|
let contractCode = contract.code;
|
||||||
let deploymentAccount = self.blockchain.defaultAccount();
|
let deploymentAccount = self.blockchain.defaultAccount();
|
||||||
let deployObject;
|
let deployObject;
|
||||||
@ -284,12 +256,29 @@ class Deploy {
|
|||||||
gasPrice: contract.gasPrice
|
gasPrice: contract.gasPrice
|
||||||
}, function(error, receipt) {
|
}, function(error, receipt) {
|
||||||
if (error) {
|
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));
|
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);
|
self.logger.info(contract.className.bold.cyan + " " + __("deployed at").green + " " + receipt.contractAddress.bold.cyan);
|
||||||
contract.deployedAddress = receipt.contractAddress;
|
contract.deployedAddress = receipt.contractAddress;
|
||||||
contract.transactionHash = receipt.transactionHash;
|
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);
|
], callback);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user