Skip to content

Commit

Permalink
feat(stack/blockchain): expose networkId in generated artifact
Browse files Browse the repository at this point in the history
Closes #2220
  • Loading branch information
0x-r4bbit authored and iurimatias committed Mar 10, 2020
1 parent 34f4b0c commit c624582
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 32 deletions.
4 changes: 2 additions & 2 deletions packages/plugins/ethereum-blockchain-client/src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions packages/stack/blockchain/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
61 changes: 34 additions & 27 deletions packages/stack/blockchain/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit c624582

Please sign in to comment.