From 72278aad72ac34fd075ccba4e7895334ef581906 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Tue, 29 Oct 2019 12:14:26 -0400 Subject: [PATCH] fix(@embark/deploy-tracker): fix not storing different chains --- .../deploy-tracker/src/deploymentChecks.js | 2 +- packages/plugins/deploy-tracker/src/index.js | 7 ++----- .../deploy-tracker/src/trackingFunctions.js | 15 ++++++++++++--- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/packages/plugins/deploy-tracker/src/deploymentChecks.js b/packages/plugins/deploy-tracker/src/deploymentChecks.js index 3a590e32a..6ffdf6e09 100644 --- a/packages/plugins/deploy-tracker/src/deploymentChecks.js +++ b/packages/plugins/deploy-tracker/src/deploymentChecks.js @@ -98,7 +98,7 @@ export default class DeploymentChecks { return this.trackingFunctions.trackAndSaveContract(params, () => { // no need to wait for this function to finish as it has no impact on operation // past this point - this.logger.trace(__("Contract tracking setting has been updatred in chains.json")); + this.logger.trace(__("Contract tracking setting has been updated in chains.json")); cb(null, params); }); } diff --git a/packages/plugins/deploy-tracker/src/index.js b/packages/plugins/deploy-tracker/src/index.js index 248c912dd..aaa416b41 100644 --- a/packages/plugins/deploy-tracker/src/index.js +++ b/packages/plugins/deploy-tracker/src/index.js @@ -3,14 +3,11 @@ import TrackingFunctions from "./trackingFunctions"; class DeployTracker { - constructor(embark, {trackContracts, env, plugins}) { + constructor(embark, {trackContracts, plugins}) { const {logger, events, fs, config} = embark; this.embark = embark; - // TODO: unclear where env comes from - // TODO: we should be getting the env from a request to the config - - const trackingFunctions = new TrackingFunctions({config, fs, logger, events, env, trackContracts}); + const trackingFunctions = new TrackingFunctions({config, fs, logger, events, trackContracts}); const deploymentChecks = new DeploymentChecks({trackingFunctions, logger, events, plugins}); this.embark.registerActionForEvent("deployment:contract:deployed", trackingFunctions.trackAndSaveContract.bind(trackingFunctions)); diff --git a/packages/plugins/deploy-tracker/src/trackingFunctions.js b/packages/plugins/deploy-tracker/src/trackingFunctions.js index fc5ab80d3..4fe6c2123 100644 --- a/packages/plugins/deploy-tracker/src/trackingFunctions.js +++ b/packages/plugins/deploy-tracker/src/trackingFunctions.js @@ -3,11 +3,11 @@ import {dappPath} from 'embark-utils'; import Web3 from 'web3'; export default class TrackingFunctions { - constructor({config, env, fs, events, logger, trackContracts}) { + constructor({config, fs, events, logger, trackContracts}) { this.config = config; this.enabled = (config.contractsConfig.tracking !== false) && (trackContracts !== false); this.chainsFilePath = dappPath(config.contractsConfig.tracking || ".embark/chains.json"); - this.env = env; + this.env = config.env; this.fs = fs; this.events = events; this.logger = logger; @@ -69,7 +69,10 @@ export default class TrackingFunctions { const chains = (await this.chains) || {}; const {hash} = await this.block; - this._currentChain = chains[hash]; + this._currentChain = chains[hash] || { + contracts: {}, + name: this.env + }; return this._currentChain; })(); } @@ -130,6 +133,12 @@ export default class TrackingFunctions { if (contract.track === false) toTrack.track = false; const {hash} = await this.block; const chains = await this.chains; + if (!chains[hash]) { + chains[hash] = { + contracts: {}, + name: this.env + }; + } chains[hash].contracts[contract.hash] = toTrack; this.chains = chains; }