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,10 +178,13 @@ export default class Blockchain {
return web3.currentProvider;
}
addArtifactFile(_params, cb) {
async addArtifactFile(_params, cb) {
if (!this.blockchainConfig.enabled) {
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') {
@ -199,7 +202,8 @@ export default class Blockchain {
dappConnection: results,
dappAutoEnable: contractsConfig.dappAutoEnable,
warnIfMetamask: this.blockchainConfig.isDev,
blockchainClient: this.blockchainConfig.client
blockchainClient: this.blockchainConfig.client,
networkId
};
this.events.request("pipeline:register", {
@ -210,6 +214,9 @@ export default class Blockchain {
}, cb);
});
});
} catch (e) {
cb(e);
}
}
registerConsoleCommands() {