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", "eth",
"xyz" "xyz"
] ]
},
"dappConfig": {
"dir": "config",
"blockchain": "blockchain.json"
} }
} }

View File

@ -20,6 +20,9 @@ const Templates = {
class CodeGenerator { class CodeGenerator {
constructor(embark, options) { constructor(embark, options) {
this.blockchainConfig = embark.config.blockchainConfig || {}; this.blockchainConfig = embark.config.blockchainConfig || {};
this.embarkConfig = embark.config.embarkConfig;
this.dappConfigs = {};
this.logger = embark.logger;
this.rpcHost = this.blockchainConfig.rpcHost || ''; this.rpcHost = this.blockchainConfig.rpcHost || '';
this.rpcPort = this.blockchainConfig.rpcPort || ''; this.rpcPort = this.blockchainConfig.rpcPort || '';
this.contractsConfig = embark.config.contractsConfig || {}; this.contractsConfig = embark.config.contractsConfig || {};
@ -42,6 +45,10 @@ class CodeGenerator {
listenToCommands() { listenToCommands() {
let self = this; let self = this;
this.events.on('config:load:contracts', (contractConfig) => {
this.generateConfigs(contractConfig);
});
this.events.setCommandHandler('provider-code', function(cb) { this.events.setCommandHandler('provider-code', function(cb) {
let providerCode = self.generateProvider(false); let providerCode = self.generateProvider(false);
@ -186,6 +193,23 @@ class CodeGenerator {
return result; 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) { generateContractCode(contract, gasLimit) {
let abi = JSON.stringify(contract.abiDefinition); let abi = JSON.stringify(contract.abiDefinition);

View File

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