mirror of https://github.com/embarklabs/embark.git
fix(blockchain): check if node is synched after connection
This commit is contained in:
parent
217357640a
commit
0639717d0c
|
@ -174,23 +174,39 @@ class BlockchainConnector {
|
||||||
if (err) {
|
if (err) {
|
||||||
return self.logger.error(err);
|
return self.logger.error(err);
|
||||||
}
|
}
|
||||||
self.provider.startWeb3Provider(() => {
|
self.provider.startWeb3Provider(async () => {
|
||||||
this.getNetworkId()
|
try {
|
||||||
.then(id => {
|
const blockNumber = await self.web3.eth.getBlockNumber();
|
||||||
let networkId = self.config.blockchainConfig.networkId;
|
await self.web3.eth.getBlock(blockNumber);
|
||||||
if (!networkId && constants.blockchain.networkIds[self.config.blockchainConfig.networkType]) {
|
self.provider.fundAccounts(() => {
|
||||||
networkId = constants.blockchain.networkIds[self.config.blockchainConfig.networkType];
|
self._emitWeb3Ready();
|
||||||
}
|
cb();
|
||||||
if (networkId && id.toString() !== networkId.toString()) {
|
});
|
||||||
self.logger.warn(__('Connected to a blockchain node on network {{realId}} while your config specifies {{configId}}', {realId: id, configId: networkId}));
|
} catch (e) {
|
||||||
self.logger.warn(__('Make sure you started the right blockchain node'));
|
const errorMessage = e.message || e;
|
||||||
}
|
if (errorMessage.indexOf('no suitable peers available') > 0) {
|
||||||
})
|
self.logger.warn(errorMessage);
|
||||||
.catch(console.error);
|
self.logger.warn(__('Your node is probably not synchronized. Wait until your node is synchronized before deploying'));
|
||||||
self.provider.fundAccounts(() => {
|
process.exit(1);
|
||||||
self._emitWeb3Ready();
|
}
|
||||||
cb();
|
self.logger.error(errorMessage);
|
||||||
});
|
cb(errorMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const id = await this.getNetworkId();
|
||||||
|
let networkId = self.config.blockchainConfig.networkId;
|
||||||
|
if (!networkId &&
|
||||||
|
constants.blockchain.networkIds[self.config.blockchainConfig.networkType]) {
|
||||||
|
networkId = constants.blockchain.networkIds[self.config.blockchainConfig.networkType];
|
||||||
|
}
|
||||||
|
if (networkId && id.toString() !== networkId.toString()) {
|
||||||
|
self.logger.warn(__('Connected to a blockchain node on network {{realId}} while your config specifies {{configId}}', {realId: id, configId: networkId}));
|
||||||
|
self.logger.warn(__('Make sure you started the right blockchain node'));
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -185,7 +185,10 @@ class ContractDeployer {
|
||||||
return self.deployContract(contract, next);
|
return self.deployContract(contract, next);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.blockchain.getCode(trackedContract.address, function(_getCodeErr, codeInChain) {
|
self.blockchain.getCode(trackedContract.address, function(getCodeErr, codeInChain) {
|
||||||
|
if (getCodeErr) {
|
||||||
|
return next(getCodeErr);
|
||||||
|
}
|
||||||
if (codeInChain.length > 3 || skipBytecodeCheck) { // it is "0x" or "0x0" for empty code, depending on web3 version
|
if (codeInChain.length > 3 || skipBytecodeCheck) { // it is "0x" or "0x0" for empty code, depending on web3 version
|
||||||
self.contractAlreadyDeployed(contract, trackedContract, next);
|
self.contractAlreadyDeployed(contract, trackedContract, next);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue