mirror of
https://github.com/embarklabs/embark.git
synced 2025-01-23 20:19:33 +00:00
feat(stack/blockchain): expose networkId in generated artifact
Closes #2220
This commit is contained in:
parent
34f4b0cf1a
commit
c624582d12
@ -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) {
|
||||
|
@ -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) => {
|
||||
|
@ -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() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user