Skip to content

Commit 2f5c16b

Browse files
committed
fix(@embark/contracts): fix ENS contracts not being resolved as deps
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.
1 parent 03ca790 commit 2f5c16b

File tree

2 files changed

+36
-21
lines changed

2 files changed

+36
-21
lines changed

packages/plugins/ens/src/index.js

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -66,26 +66,26 @@ class ENS {
6666
async.map(
6767
this.config.namesystemConfig.dappConnection || this.config.contractsConfig.dappConnection,
6868
(conn, next) => {
69-
if (conn === '$EMBARK') {
70-
return this.events.request('proxy:endpoint:get', next);
71-
}
72-
next(null, conn);
73-
}, (err, connections) => {
74-
if (err) {
75-
return done(err);
76-
}
77-
done(null, {
78-
env: this.env,
79-
registration: this.config.namesystemConfig.register,
80-
registryAbi: this.ensConfig.ENSRegistry.abiDefinition,
81-
registryAddress: this.ensConfig.ENSRegistry.deployedAddress,
82-
registrarAbi: this.ensConfig.FIFSRegistrar.abiDefinition,
83-
registrarAddress: this.ensConfig.FIFSRegistrar.deployedAddress,
84-
resolverAbi: this.ensConfig.Resolver.abiDefinition,
85-
resolverAddress: this.ensConfig.Resolver.deployedAddress,
86-
dappConnection: connections
69+
if (conn === '$EMBARK') {
70+
return this.events.request('proxy:endpoint:get', next);
71+
}
72+
next(null, conn);
73+
}, (err, connections) => {
74+
if (err) {
75+
return done(err);
76+
}
77+
done(null, {
78+
env: this.env,
79+
registration: this.config.namesystemConfig.register,
80+
registryAbi: this.ensConfig.ENSRegistry.abiDefinition,
81+
registryAddress: this.ensConfig.ENSRegistry.deployedAddress,
82+
registrarAbi: this.ensConfig.FIFSRegistrar.abiDefinition,
83+
registrarAddress: this.ensConfig.FIFSRegistrar.deployedAddress,
84+
resolverAbi: this.ensConfig.Resolver.abiDefinition,
85+
resolverAddress: this.ensConfig.Resolver.deployedAddress,
86+
dappConnection: connections
87+
});
8788
});
88-
});
8989
}
9090

9191
async init(cb = () => {}) {
@@ -110,6 +110,7 @@ class ENS {
110110
return;
111111
}
112112
this.actionsRegistered = true;
113+
this.embark.registerActionForEvent("contracts:build:before", this.beforeContractBuild.bind(this));
113114
this.embark.registerActionForEvent("deployment:deployContracts:beforeAll", this.configureContractsAndRegister.bind(this));
114115
this.embark.registerActionForEvent('deployment:contract:beforeDeploy', this.modifyENSArguments.bind(this));
115116
this.embark.registerActionForEvent("deployment:deployContracts:afterAll", this.associateContractAddresses.bind(this));
@@ -271,6 +272,17 @@ class ENS {
271272
});
272273
}
273274

275+
async beforeContractBuild(_options, cb) {
276+
if (this.configured) {
277+
return cb();
278+
}
279+
// Add contracts to contract manager so that they can be resolved as dependencies
280+
this.ensConfig.ENSRegistry = await this.events.request2('contracts:add', this.ensConfig.ENSRegistry);
281+
this.ensConfig.Resolver = await this.events.request2('contracts:add', this.ensConfig.Resolver);
282+
this.ensConfig.FIFSRegistrar = await this.events.request2('contracts:add', this.ensConfig.FIFSRegistrar);
283+
cb();
284+
}
285+
274286
async configureContractsAndRegister(_options, cb) {
275287
const NO_REGISTRATION = 'NO_REGISTRATION';
276288
const self = this;
@@ -292,8 +304,8 @@ class ENS {
292304
const registration = this.config.namesystemConfig.register;
293305
const doRegister = registration && registration.rootDomain;
294306

295-
this.ensConfig.ENSRegistry = await this.events.request2('contracts:add', this.ensConfig.ENSRegistry);
296307
await this.events.request2('deployment:contract:deploy', this.ensConfig.ENSRegistry);
308+
// Add Resolver to contract manager again but this time with correct arguments (Registry address)
297309
this.ensConfig.Resolver.args = [this.ensConfig.ENSRegistry.deployedAddress];
298310
this.ensConfig.Resolver = await this.events.request2('contracts:add', this.ensConfig.Resolver);
299311
await this.events.request2('deployment:contract:deploy', this.ensConfig.Resolver);

packages/stack/contracts-manager/src/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,10 @@ export default class ContractsManager {
263263
const self = this;
264264

265265
async.waterfall([
266-
function prepareContractsFromConfig(callback) {
266+
function beforeBuild(callback) {
267+
self.plugins.emitAndRunActionsForEvent('contracts:build:before', callback);
268+
},
269+
function prepareContractsFromConfig(_options, callback) {
267270
self.events.emit("status", __("Building..."));
268271

269272
if (contractsConfig.contracts.deploy) {

0 commit comments

Comments
 (0)