generate json files
This commit is contained in:
parent
3c1ca7f457
commit
47f313b12c
|
@ -113,6 +113,31 @@ class ABIGenerator {
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
generateContractsJSON() {
|
||||||
|
let contracts = {};
|
||||||
|
|
||||||
|
for (let className in this.contractsManager.contracts) {
|
||||||
|
let contract = this.contractsManager.contracts[className];
|
||||||
|
let contractJSON = {};
|
||||||
|
|
||||||
|
let abi = JSON.stringify(contract.abiDefinition);
|
||||||
|
let gasEstimates = JSON.stringify(contract.gasEstimates);
|
||||||
|
|
||||||
|
contractJSON.contract_name = className;
|
||||||
|
contractJSON.code = contract.code;
|
||||||
|
contractJSON.runtime_bytecode = contract.runtimeBytecode;
|
||||||
|
contractJSON.real_runtime_bytecode = contract.realRuntimeBytecode;
|
||||||
|
contractJSON.swarm_hash = contract.swarmHash;
|
||||||
|
contractJSON.gas_estimates = contract.gasEstimates;
|
||||||
|
contractJSON.function_hashes = contract.functionHashes;
|
||||||
|
contractJSON.abi = contract.abiDefinition;
|
||||||
|
|
||||||
|
contracts[className] = contractJSON;
|
||||||
|
}
|
||||||
|
|
||||||
|
return contracts;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = ABIGenerator;
|
module.exports = ABIGenerator;
|
||||||
|
|
|
@ -54,7 +54,7 @@ class DeployTracker {
|
||||||
if (this.chainConfig === false) {
|
if (this.chainConfig === false) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
fs.writeJSONSync("./chains.json", this.chainConfig);
|
fs.writeJSONSync("./chains.json", this.chainConfig, {spaces: 2});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -80,9 +80,10 @@ class Engine {
|
||||||
logger: this.logger,
|
logger: this.logger,
|
||||||
plugins: this.plugins
|
plugins: this.plugins
|
||||||
});
|
});
|
||||||
this.events.on('abi', function (abi) {
|
this.events.on('abi', function (abi, contractsJSON) {
|
||||||
self.currentAbi = abi;
|
self.currentAbi = abi;
|
||||||
pipeline.build(abi);
|
self.contractsJSON = contractsJSON;
|
||||||
|
pipeline.build(abi, contractsJSON);
|
||||||
self.events.emit('outputDone');
|
self.events.emit('outputDone');
|
||||||
});
|
});
|
||||||
// TODO: still need to redeploy contracts because the original contracts
|
// TODO: still need to redeploy contracts because the original contracts
|
||||||
|
@ -90,7 +91,7 @@ class Engine {
|
||||||
//this.events.on('file-event', function(fileType, path) {
|
//this.events.on('file-event', function(fileType, path) {
|
||||||
// if (fileType === 'asset') {
|
// if (fileType === 'asset') {
|
||||||
// self.config.reloadConfig();
|
// self.config.reloadConfig();
|
||||||
// pipeline.build(self.abi, path);
|
// pipeline.build(self.abi, self.contractsJSON, path);
|
||||||
// self.events.emit('outputDone');
|
// self.events.emit('outputDone');
|
||||||
// }
|
// }
|
||||||
//});
|
//});
|
||||||
|
@ -109,10 +110,11 @@ class Engine {
|
||||||
let embarkJSABI = abiGenerator.generateABI({useEmbarkJS: true});
|
let embarkJSABI = abiGenerator.generateABI({useEmbarkJS: true});
|
||||||
let vanillaABI = abiGenerator.generateABI({useEmbarkJS: false});
|
let vanillaABI = abiGenerator.generateABI({useEmbarkJS: false});
|
||||||
let vanillaContractsABI = abiGenerator.generateContracts(false);
|
let vanillaContractsABI = abiGenerator.generateContracts(false);
|
||||||
|
let contractsJSON = abiGenerator.generateContractsJSON();
|
||||||
|
|
||||||
self.events.emit('abi-contracts-vanila', vanillaContractsABI);
|
self.events.emit('abi-contracts-vanila', vanillaContractsABI, contractsJSON);
|
||||||
self.events.emit('abi-vanila', vanillaABI);
|
self.events.emit('abi-vanila', vanillaABI, contractsJSON);
|
||||||
self.events.emit('abi', embarkJSABI);
|
self.events.emit('abi', embarkJSABI, contractsJSON);
|
||||||
};
|
};
|
||||||
this.events.on('contractsDeployed', generateABICode);
|
this.events.on('contractsDeployed', generateABICode);
|
||||||
this.events.on('blockchainDisabled', generateABICode);
|
this.events.on('blockchainDisabled', generateABICode);
|
||||||
|
|
|
@ -11,7 +11,7 @@ class Pipeline {
|
||||||
this.plugins = options.plugins;
|
this.plugins = options.plugins;
|
||||||
}
|
}
|
||||||
|
|
||||||
build(abi, path) {
|
build(abi, contractsJSON, path) {
|
||||||
let self = this;
|
let self = this;
|
||||||
for (let targetFile in this.assetFiles) {
|
for (let targetFile in this.assetFiles) {
|
||||||
|
|
||||||
|
@ -76,6 +76,17 @@ class Pipeline {
|
||||||
fs.writeFileSync(this.buildDir + targetFile, content);
|
fs.writeFileSync(this.buildDir + targetFile, content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.buildContracts(contractsJSON);
|
||||||
|
}
|
||||||
|
|
||||||
|
buildContracts(contractsJSON) {
|
||||||
|
fs.mkdirpSync(this.buildDir + 'contracts');
|
||||||
|
|
||||||
|
for (let className in contractsJSON) {
|
||||||
|
let contract = contractsJSON[className];
|
||||||
|
fs.writeJSONSync(this.buildDir + 'contracts/' + className + ".json", contract, {spaces: 2});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue