From f6d7a541955a458d7eaab53f8061f544a32ac5de Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Thu, 27 Jun 2019 13:28:18 -0400 Subject: [PATCH] fix(@embark/deploy-tracker): fix getting the block 0 with sim --fork --- packages/embark-deploy-tracker/src/index.js | 39 +++++++++++++-------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/packages/embark-deploy-tracker/src/index.js b/packages/embark-deploy-tracker/src/index.js index b79ad0a21..82e0dd56e 100644 --- a/packages/embark-deploy-tracker/src/index.js +++ b/packages/embark-deploy-tracker/src/index.js @@ -58,26 +58,37 @@ class DeployTracker { }); } - setCurrentChain(cb) { + setCurrentChain(callback) { const self = this; if (this.chainConfig === false) { this.currentChain = {contracts: []}; - return cb(); + return callback(); } - this.events.request("blockchain:block:byNumber", 0, function(err, block) { + + function getBlock(blockNum, cb) { + self.events.request("blockchain:block:byNumber", blockNum, (err, block) => { + if (err) { + return cb(err); + } + let chainId = block.hash; + + if (self.chainConfig[chainId] === undefined) { + self.chainConfig[chainId] = {contracts: {}}; + } + + self.currentChain = self.chainConfig[chainId]; + + self.currentChain.name = self.env; + cb(); + }); + } + + getBlock(0, (err) => { if (err) { - return cb(err); + // Retry with block 1 (Block 0 fails with Ganache-cli using the --fork option) + return getBlock(1, callback); } - let chainId = block.hash; - - if (self.chainConfig[chainId] === undefined) { - self.chainConfig[chainId] = {contracts: {}}; - } - - self.currentChain = self.chainConfig[chainId]; - - self.currentChain.name = self.env; - cb(); + callback(); }); }