Skip to content

Commit c624582

Browse files
0x-r4bbitiurimatias
authored andcommitted
feat(stack/blockchain): expose networkId in generated artifact
Closes #2220
1 parent 34f4b0c commit c624582

File tree

3 files changed

+39
-32
lines changed

3 files changed

+39
-32
lines changed

packages/plugins/ethereum-blockchain-client/src/api.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,8 @@ export default class EthereumAPI {
293293
this.requestManager.send({method: 'web3_clientVersion', params: []}, cb);
294294
}
295295

296-
getNetworkId() {
297-
return this.web3.eth.net.getId();
296+
getNetworkId(cb) {
297+
return this.web3.eth.net.getId(cb);
298298
}
299299

300300
getTransaction(hash, cb) {

packages/stack/blockchain/src/api.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ export default class BlockchainAPI {
109109
getGasPrice(cb);
110110
});
111111

112-
this.events.setCommandHandler("blockchain:networkId", async (cb) => {
113-
const getNetworkId = await this.getRequestForBlockchain(blockchainName, "getNetworkId");
114-
cb(getNetworkId);
112+
this.events.setCommandHandler("blockchain:networkId", (cb) => {
113+
const getNetworkId = this.getRequestForBlockchain(blockchainName, "getNetworkId");
114+
getNetworkId(cb);
115115
});
116116

117117
this.events.setCommandHandler("blockchain:getTransaction", async (txId, cb) => {

packages/stack/blockchain/src/index.js

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -178,38 +178,45 @@ export default class Blockchain {
178178
return web3.currentProvider;
179179
}
180180

181-
addArtifactFile(_params, cb) {
181+
async addArtifactFile(_params, cb) {
182182
if (!this.blockchainConfig.enabled) {
183183
cb();
184184
}
185-
this.events.request("config:contractsConfig", (_err, contractsConfig) => {
186-
async.map(contractsConfig.dappConnection, (conn, mapCb) => {
187-
if (conn === '$EMBARK') {
188-
// Connect to Embark's endpoint (proxy)
189-
return this.events.request("proxy:endpoint:get", mapCb);
190-
}
191-
mapCb(null, conn);
192-
}, (err, results) => {
193-
if (err) {
194-
this.logger.error(__('Error getting dapp connection'));
195-
return cb(err);
196-
}
197-
const config = {
198-
provider: contractsConfig.library || 'web3',
199-
dappConnection: results,
200-
dappAutoEnable: contractsConfig.dappAutoEnable,
201-
warnIfMetamask: this.blockchainConfig.isDev,
202-
blockchainClient: this.blockchainConfig.client
203-
};
204185

205-
this.events.request("pipeline:register", {
206-
path: [this.embarkConfig.generationDir, 'config'],
207-
file: 'blockchain.json',
208-
format: 'json',
209-
content: config
210-
}, cb);
186+
try {
187+
const networkId = await this.events.request2('blockchain:networkId');
188+
this.events.request("config:contractsConfig", (_err, contractsConfig) => {
189+
async.map(contractsConfig.dappConnection, (conn, mapCb) => {
190+
if (conn === '$EMBARK') {
191+
// Connect to Embark's endpoint (proxy)
192+
return this.events.request("proxy:endpoint:get", mapCb);
193+
}
194+
mapCb(null, conn);
195+
}, (err, results) => {
196+
if (err) {
197+
this.logger.error(__('Error getting dapp connection'));
198+
return cb(err);
199+
}
200+
const config = {
201+
provider: contractsConfig.library || 'web3',
202+
dappConnection: results,
203+
dappAutoEnable: contractsConfig.dappAutoEnable,
204+
warnIfMetamask: this.blockchainConfig.isDev,
205+
blockchainClient: this.blockchainConfig.client,
206+
networkId
207+
};
208+
209+
this.events.request("pipeline:register", {
210+
path: [this.embarkConfig.generationDir, 'config'],
211+
file: 'blockchain.json',
212+
format: 'json',
213+
content: config
214+
}, cb);
215+
});
211216
});
212-
});
217+
} catch (e) {
218+
cb(e);
219+
}
213220
}
214221

215222
registerConsoleCommands() {

0 commit comments

Comments
 (0)