feat(stack/blockchain): expose networkId in generated artifact

Closes #2220
This commit is contained in:
Pascal Precht 2020-03-10 12:38:21 +01:00 committed by Iuri Matias
parent 34f4b0cf1a
commit c624582d12
3 changed files with 39 additions and 32 deletions

View File

@ -293,8 +293,8 @@ export default class EthereumAPI {
this.requestManager.send({method: 'web3_clientVersion', params: []}, cb);
}
getNetworkId() {
return this.web3.eth.net.getId();
getNetworkId(cb) {
return this.web3.eth.net.getId(cb);
}
getTransaction(hash, cb) {

View File

@ -109,9 +109,9 @@ export default class BlockchainAPI {
getGasPrice(cb);
});
this.events.setCommandHandler("blockchain:networkId", async (cb) => {
const getNetworkId = await this.getRequestForBlockchain(blockchainName, "getNetworkId");
cb(getNetworkId);
this.events.setCommandHandler("blockchain:networkId", (cb) => {
const getNetworkId = this.getRequestForBlockchain(blockchainName, "getNetworkId");
getNetworkId(cb);
});
this.events.setCommandHandler("blockchain:getTransaction", async (txId, cb) => {

View File

@ -178,38 +178,45 @@ export default class Blockchain {
return web3.currentProvider;
}
addArtifactFile(_params, cb) {
async addArtifactFile(_params, cb) {
if (!this.blockchainConfig.enabled) {
cb();
}
this.events.request("config:contractsConfig", (_err, contractsConfig) => {
async.map(contractsConfig.dappConnection, (conn, mapCb) => {
if (conn === '$EMBARK') {
// Connect to Embark's endpoint (proxy)
return this.events.request("proxy:endpoint:get", mapCb);
}
mapCb(null, conn);
}, (err, results) => {
if (err) {
this.logger.error(__('Error getting dapp connection'));
return cb(err);
}
const config = {
provider: contractsConfig.library || 'web3',
dappConnection: results,
dappAutoEnable: contractsConfig.dappAutoEnable,
warnIfMetamask: this.blockchainConfig.isDev,
blockchainClient: this.blockchainConfig.client
};
this.events.request("pipeline:register", {
path: [this.embarkConfig.generationDir, 'config'],
file: 'blockchain.json',
format: 'json',
content: config
}, cb);
try {
const networkId = await this.events.request2('blockchain:networkId');
this.events.request("config:contractsConfig", (_err, contractsConfig) => {
async.map(contractsConfig.dappConnection, (conn, mapCb) => {
if (conn === '$EMBARK') {
// Connect to Embark's endpoint (proxy)
return this.events.request("proxy:endpoint:get", mapCb);
}
mapCb(null, conn);
}, (err, results) => {
if (err) {
this.logger.error(__('Error getting dapp connection'));
return cb(err);
}
const config = {
provider: contractsConfig.library || 'web3',
dappConnection: results,
dappAutoEnable: contractsConfig.dappAutoEnable,
warnIfMetamask: this.blockchainConfig.isDev,
blockchainClient: this.blockchainConfig.client,
networkId
};
this.events.request("pipeline:register", {
path: [this.embarkConfig.generationDir, 'config'],
file: 'blockchain.json',
format: 'json',
content: config
}, cb);
});
});
});
} catch (e) {
cb(e);
}
}
registerConsoleCommands() {