From 258fa1d0dfad905bb921501300bee8bff5311f4d Mon Sep 17 00:00:00 2001 From: Thomas Backlund Date: Fri, 7 Dec 2018 15:42:30 +0100 Subject: [PATCH] Add retry function when verifying code for when deploying contracts. (#266) --- src/deployer.js | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/deployer.js b/src/deployer.js index 0190a777..35bcdaf7 100644 --- a/src/deployer.js +++ b/src/deployer.js @@ -957,19 +957,28 @@ export default class DeployerRunner { this._stdout('Transaction mined, verifying code...'); obj.address2 = res.contractAddress; obj.deployMeta = { gasUsed: res.gasUsed }; - - obj.web3.eth.getCode(obj.address2, 'latest', (err, res) => { - if (res && res.length > 4) { + var counter = 10; + const waitCode = () => { + obj.web3.eth.getCode(obj.address2, 'latest', (err, res) => { + if (err || !res || res.length < 4) { + if (counter-- == 0) { + // Final timeout + this._stderr( + 'Contract code could not be verified on chain. The contract might not have been deployed. This is possibly a mismatch in the number/type of arguments given to the constructor or could also be a temporary issue in reading back the contract code from the chain.' + ); + cb(1); + return; + } + setTimeout(waitCode, 2000); + return; + } this._stdout('Contract deployed at address ' + obj.address2 + '.'); this._stdout('Done.'); cb(0); - return; - } else { - this._stderr('Contract did not get deployed. Wrong arguments to constructor?'); - cb(1); - return; - } - }); + }); + }; + + waitCode(); } }); }