refactor generateContractsJson

This commit is contained in:
Iuri Matias 2018-05-22 14:31:21 -04:00
parent cf999ce997
commit 5f64376c84
1 changed files with 39 additions and 30 deletions

View File

@ -46,68 +46,78 @@ class CodeGenerator {
// deprecated events; to remove in embark 2.7.0
this.events.setCommandHandlerOnce('abi-vanila', function(cb) {
let vanillaABI = self.generateABI({useEmbarkJS: false});
let contractsJSON = self.generateContractsJSON();
this.events.request("contracts:list", (contractsList) => {
let contractsJSON = self.generateContractsJSON(contractsList);
cb(vanillaABI, contractsJSON);
});
});
this.events.setCommandHandlerOnce('abi', function(cb) {
let embarkJSABI = self.generateABI({useEmbarkJS: true});
let contractsJSON = self.generateContractsJSON();
this.events.request("contracts:list", (contractsList) => {
let contractsJSON = self.generateContractsJSON(contractsList);
cb(embarkJSABI, contractsJSON);
});
});
this.events.setCommandHandlerOnce('abi-contracts-vanila', function(cb) {
let vanillaContractsABI = self.generateContracts(false, true, false);
let contractsJSON = self.generateContractsJSON();
self.events.request("contracts:list", (contractsList) => {
let contractsJSON = self.generateContractsJSON(contractsList);
cb(vanillaContractsABI, contractsJSON);
});
});
this.events.setCommandHandlerOnce('abi-vanila-deployment', function(cb) {
let vanillaABI = self.generateABI({useEmbarkJS: false, deployment: true});
let contractsJSON = self.generateContractsJSON();
self.events.request("contracts:list", (contractsList) => {
let contractsJSON = self.generateContractsJSON(contractsList);
cb(vanillaABI, contractsJSON);
});
});
// new events
this.events.setCommandHandlerOnce('code-vanila', function(cb) {
let vanillaABI = self.generateABI({useEmbarkJS: false});
let contractsJSON = self.generateContractsJSON();
self.events.request("contracts:list", (contractsList) => {
let contractsJSON = self.generateContractsJSON(contractsList);
cb(vanillaABI, contractsJSON);
});
});
this.events.setCommandHandlerOnce('code', function(cb) {
let embarkJSABI = self.generateABI({useEmbarkJS: true});
let contractsJSON = self.generateContractsJSON();
self.events.request("contracts:list", (contractsList) => {
let contractsJSON = self.generateContractsJSON(contractsList);
cb(embarkJSABI, contractsJSON);
});
});
this.events.setCommandHandlerOnce('code-contracts-vanila', function(cb) {
let vanillaContractsABI = self.generateContracts(false, true, false);
let contractsJSON = self.generateContractsJSON();
self.events.request("contracts:list", (contractsList) => {
let contractsJSON = self.generateContractsJSON(contractsList);
cb(vanillaContractsABI, contractsJSON);
});
});
this.events.setCommandHandlerOnce('code-vanila-deployment', function(cb) {
let vanillaABI = self.generateABI({useEmbarkJS: false, deployment: true});
let contractsJSON = self.generateContractsJSON();
self.events.request("contracts:list", (contractsList) => {
let contractsJSON = self.generateContractsJSON(contractsList);
cb(vanillaABI, contractsJSON);
});
});
this.events.setCommandHandlerOnce('code-generator:web3js', function(cb) {
self.buildWeb3JS(cb);
});
this.events.setCommandHandler('code-generator:contract', (contractName, cb) => {
let contract = self.contractsManager.contracts[contractName];
self.buildContractJS(contractName, self.generateContractJSON(contractName, contract), cb);
self.events.setCommandHandler('code-generator:contract', (contractName, cb) => {
self.events.setCommandHandler('contracts:contract', contractName, (contract) => {
self.buildContractJS(contractName, self.generateContractJSON(contract, contract), cb);
});
});
self.events.setCommandHandler('code-generator:contract:vanilla', (contract, gasLimit, cb) => {
@ -304,12 +314,11 @@ class CodeGenerator {
return contractJSON;
}
generateContractsJSON() {
generateContractsJSON(contractsList) {
let contracts = {};
for (let className in this.contractsManager.contracts) {
let contract = this.contractsManager.contracts[className];
contracts[className] = this.generateContractJSON(className, contract);
for (let contract of contractsList) {
contracts[contract.className] = this.generateContractJSON(contract.className, contract);
}
return contracts;