Skip to content

Commit

Permalink
fix(@embark/contracts): fix ENS contracts not being resolved as deps
Browse files Browse the repository at this point in the history
This was caused by the fact that we add the ENS contract to the
manager when before they deploy, but the dependency resolution was
done while building the contracts, so even before.
So the solution was to add a "before build" action so that the ENS
module could add its contracts to the manager if needed.
  • Loading branch information
jrainville committed Jan 29, 2020
1 parent 03ca790 commit 2f5c16b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 21 deletions.
52 changes: 32 additions & 20 deletions packages/plugins/ens/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,26 +66,26 @@ class ENS {
async.map(
this.config.namesystemConfig.dappConnection || this.config.contractsConfig.dappConnection,
(conn, next) => {
if (conn === '$EMBARK') {
return this.events.request('proxy:endpoint:get', next);
}
next(null, conn);
}, (err, connections) => {
if (err) {
return done(err);
}
done(null, {
env: this.env,
registration: this.config.namesystemConfig.register,
registryAbi: this.ensConfig.ENSRegistry.abiDefinition,
registryAddress: this.ensConfig.ENSRegistry.deployedAddress,
registrarAbi: this.ensConfig.FIFSRegistrar.abiDefinition,
registrarAddress: this.ensConfig.FIFSRegistrar.deployedAddress,
resolverAbi: this.ensConfig.Resolver.abiDefinition,
resolverAddress: this.ensConfig.Resolver.deployedAddress,
dappConnection: connections
if (conn === '$EMBARK') {
return this.events.request('proxy:endpoint:get', next);
}
next(null, conn);
}, (err, connections) => {
if (err) {
return done(err);
}
done(null, {
env: this.env,
registration: this.config.namesystemConfig.register,
registryAbi: this.ensConfig.ENSRegistry.abiDefinition,
registryAddress: this.ensConfig.ENSRegistry.deployedAddress,
registrarAbi: this.ensConfig.FIFSRegistrar.abiDefinition,
registrarAddress: this.ensConfig.FIFSRegistrar.deployedAddress,
resolverAbi: this.ensConfig.Resolver.abiDefinition,
resolverAddress: this.ensConfig.Resolver.deployedAddress,
dappConnection: connections
});
});
});
}

async init(cb = () => {}) {
Expand All @@ -110,6 +110,7 @@ class ENS {
return;
}
this.actionsRegistered = true;
this.embark.registerActionForEvent("contracts:build:before", this.beforeContractBuild.bind(this));
this.embark.registerActionForEvent("deployment:deployContracts:beforeAll", this.configureContractsAndRegister.bind(this));
this.embark.registerActionForEvent('deployment:contract:beforeDeploy', this.modifyENSArguments.bind(this));
this.embark.registerActionForEvent("deployment:deployContracts:afterAll", this.associateContractAddresses.bind(this));
Expand Down Expand Up @@ -271,6 +272,17 @@ class ENS {
});
}

async beforeContractBuild(_options, cb) {
if (this.configured) {
return cb();
}
// Add contracts to contract manager so that they can be resolved as dependencies
this.ensConfig.ENSRegistry = await this.events.request2('contracts:add', this.ensConfig.ENSRegistry);
this.ensConfig.Resolver = await this.events.request2('contracts:add', this.ensConfig.Resolver);
this.ensConfig.FIFSRegistrar = await this.events.request2('contracts:add', this.ensConfig.FIFSRegistrar);
cb();
}

async configureContractsAndRegister(_options, cb) {
const NO_REGISTRATION = 'NO_REGISTRATION';
const self = this;
Expand All @@ -292,8 +304,8 @@ class ENS {
const registration = this.config.namesystemConfig.register;
const doRegister = registration && registration.rootDomain;

this.ensConfig.ENSRegistry = await this.events.request2('contracts:add', this.ensConfig.ENSRegistry);
await this.events.request2('deployment:contract:deploy', this.ensConfig.ENSRegistry);
// Add Resolver to contract manager again but this time with correct arguments (Registry address)
this.ensConfig.Resolver.args = [this.ensConfig.ENSRegistry.deployedAddress];
this.ensConfig.Resolver = await this.events.request2('contracts:add', this.ensConfig.Resolver);
await this.events.request2('deployment:contract:deploy', this.ensConfig.Resolver);
Expand Down
5 changes: 4 additions & 1 deletion packages/stack/contracts-manager/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,10 @@ export default class ContractsManager {
const self = this;

async.waterfall([
function prepareContractsFromConfig(callback) {
function beforeBuild(callback) {
self.plugins.emitAndRunActionsForEvent('contracts:build:before', callback);
},
function prepareContractsFromConfig(_options, callback) {
self.events.emit("status", __("Building..."));

if (contractsConfig.contracts.deploy) {
Expand Down

0 comments on commit 2f5c16b

Please sign in to comment.