feat(dapp-config): add dapp connection to dapp config (artifact)

This commit is contained in:
Jonathan Rainville 2019-01-23 15:37:53 -05:00 committed by Iuri Matias
parent 1543f6ad41
commit 52aebebf9e
3 changed files with 31 additions and 2 deletions

View File

@ -83,5 +83,9 @@
"eth",
"xyz"
]
},
"dappConfig": {
"dir": "config",
"blockchain": "blockchain.json"
}
}

View File

@ -20,6 +20,9 @@ const Templates = {
class CodeGenerator {
constructor(embark, options) {
this.blockchainConfig = embark.config.blockchainConfig || {};
this.embarkConfig = embark.config.embarkConfig;
this.dappConfigs = {};
this.logger = embark.logger;
this.rpcHost = this.blockchainConfig.rpcHost || '';
this.rpcPort = this.blockchainConfig.rpcPort || '';
this.contractsConfig = embark.config.contractsConfig || {};
@ -42,6 +45,10 @@ class CodeGenerator {
listenToCommands() {
let self = this;
this.events.on('config:load:contracts', (contractConfig) => {
this.generateConfigs(contractConfig);
});
this.events.setCommandHandler('provider-code', function(cb) {
let providerCode = self.generateProvider(false);
@ -186,6 +193,23 @@ class CodeGenerator {
return result;
}
generateConfigs(contractConfig) {
this.dappConfigs.blockchain = {dappConnection: contractConfig.dappConnection};
async.waterfall([
(next) => {
fs.mkdirp(utils.joinPath(this.embarkConfig.buildDir, constants.dappConfig.dir), next);
},
(_dir, next) => {
fs.writeFile(utils.joinPath(this.embarkConfig.buildDir, constants.dappConfig.dir, constants.dappConfig.blockchain),
JSON.stringify(this.dappConfigs.blockchain, null, 2), next);
}
], (err) => {
if (err) {
this.logger.error(err.message || err);
}
});
}
generateContractCode(contract, gasLimit) {
let abi = JSON.stringify(contract.abiDefinition);

View File

@ -27,14 +27,15 @@ describe('embark.CodeGenerator', function() {
deployedAddress: "0x124",
code: '123456'
}
]
];
const TestEvents = {
request: (cmd, cb) => {
cb(currentSolcVersion);
},
setCommandHandler: () => {
}
},
on: () => {}
};
let generator = new CodeGenerator({config: {blockchainConfig: {}}, events: TestEvents}, {});