fix(@embark/deploy-tracker): fix not storing different chains

This commit is contained in:
Jonathan Rainville 2019-10-29 12:14:26 -04:00 committed by Michael Bradley
parent b8f7ec20d4
commit 72278aad72
3 changed files with 15 additions and 9 deletions

View File

@ -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);
});
}

View File

@ -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));

View File

@ -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;
}