fix rebase problems and now works

This commit is contained in:
Jonathan Rainville 2018-10-03 10:29:36 -04:00 committed by Pascal Precht
parent c0d32e3581
commit eae7784a87
No known key found for this signature in database
GPG Key ID: 0EE28D8D6FD85D7D
1 changed files with 77 additions and 148 deletions

View File

@ -5,75 +5,45 @@ const async = require('async');
const embarkJsUtils = require('embarkjs').Utils; const embarkJsUtils = require('embarkjs').Utils;
const reverseAddrSuffix = '.addr.reverse'; const reverseAddrSuffix = '.addr.reverse';
const DEFAULT_ENS_CONTRACTS_CONFIG = {
"default": {
"contracts": {
"ENS": {
"deploy": false,
"silent": true
},
"ENSRegistry": {
"deploy": true,
"silent": true,
"args": []
},
"Resolver": {
"deploy": true,
"silent": true,
"args": ["$ENSRegistry"]
},
"FIFSRegistrar": {
"deploy": false
}
}
}
};
const MAINNET_ID = '1'; const MAINNET_ID = '1';
const ROPSTEN_ID = '3'; const ROPSTEN_ID = '3';
const RINKEBY_ID = '4'; const RINKEBY_ID = '4';
const ENS_CONTRACTS_CONFIG = { const ENS_CONTRACTS_CONFIG = {
[MAINNET_ID]: { [MAINNET_ID]: {
"contracts": { "ENSRegistry": {
"ENSRegistry": { "address": "0x314159265dd8dbb310642f98f50c066173c1259b",
"address": "0x314159265dd8dbb310642f98f50c066173c1259b", "silent": true
"silent": true },
}, "Resolver": {
"Resolver": { "deploy": false
"deploy": false },
}, "FIFSRegistrar": {
"FIFSRegistrar": { "deploy": false
"deploy": false
}
} }
}, },
[ROPSTEN_ID]: { [ROPSTEN_ID]: {
"contracts": { "ENSRegistry": {
"ENSRegistry": { "address": "0x112234455c3a32fd11230c42e7bccd4a84e02010",
"address": "0x112234455c3a32fd11230c42e7bccd4a84e02010", "silent": true
"silent": true },
}, "Resolver": {
"Resolver": { "deploy": false
"deploy": false },
}, "FIFSRegistrar": {
"FIFSRegistrar": { "deploy": false
"deploy": false
}
} }
}, },
[RINKEBY_ID]: { [RINKEBY_ID]: {
"contracts": { "ENSRegistry": {
"ENSRegistry": { "address": "0xe7410170f87102DF0055eB195163A03B7F2Bff4A",
"address": "0xe7410170f87102DF0055eB195163A03B7F2Bff4A", "silent": true
"silent": true },
}, "Resolver": {
"Resolver": { "deploy": false
"deploy": false },
}, "FIFSRegistrar": {
"FIFSRegistrar": { "deploy": false
"deploy": false
}
} }
} }
}; };
@ -130,7 +100,6 @@ class ENS {
registerEvents() { registerEvents() {
this.embark.registerActionForEvent("deploy:beforeAll", this.configureContractsAndRegister.bind(this)); this.embark.registerActionForEvent("deploy:beforeAll", this.configureContractsAndRegister.bind(this));
this.events.once("web3Ready", this.configureContracts.bind(this));
this.events.setCommandHandler("storage:ens:associate", this.associateStorageToEns.bind(this)); this.events.setCommandHandler("storage:ens:associate", this.associateStorageToEns.bind(this));
} }
@ -152,14 +121,14 @@ class ENS {
self.addSetProvider(config); self.addSetProvider(config);
} }
self.events.request('blockchain:networkId', (networkId) => { self.events.request('blockchain:networkId', (networkId) => {
const isKnownNetwork = Object.keys(ENS_CONTRACTS_CONFIG).includes(networkId); const isKnownNetwork = Boolean(ENS_CONTRACTS_CONFIG[networkId]);
const shouldRegisterSubdomain = self.registration && self.registration.subdomains && Object.keys(self.registration.subdomains).length; const shouldRegisterSubdomain = self.registration && self.registration.subdomains && Object.keys(self.registration.subdomains).length;
if (isKnownNetwork || !shouldRegisterSubdomain) { if (isKnownNetwork || !shouldRegisterSubdomain) {
return cb(); return cb();
} }
self.registerConfigDomains(config, cb); process.exit();
}); self.registerConfigDomains(config, cb);
}); });
} }
@ -298,100 +267,60 @@ class ENS {
} }
configureContractsAndRegister(cb) { configureContractsAndRegister(cb) {
this.events.request('blockchain:networkId', (networkId) => {
const config = Object.assign({}, DEFAULT_ENS_CONTRACTS_CONFIG, {[this.env]: ENS_CONTRACTS_CONFIG[networkId]});
const self = this; const self = this;
if (self.configured) { if (self.configured) {
return cb(); return cb();
} }
self.events.request('blockchain:networkId', (networkId) => {
const knownConfigs = { if (ENS_CONTRACTS_CONFIG[networkId]) {
"ropsten": { self.ensConfig = utils.recursiveMerge(self.ensConfig, ENS_CONTRACTS_CONFIG[networkId]);
"ENSRegistry": { } else {
"address": "0x112234455c3a32fd11230c42e7bccd4a84e02010", process.exit();
"silent": true
},
"Resolver": {
"deploy": false
},
"FIFSRegistrar": {
"deploy": false
}
},
"rinkeby": {
"ENSRegistry": {
"address": "0xe7410170f87102DF0055eB195163A03B7F2Bff4A",
"silent": true
},
"Resolver": {
"deploy": false
},
"FIFSRegistrar": {
"deploy": false
}
},
"livenet": {
"ENSRegistry": {
"address": "0x314159265dd8dbb310642f98f50c066173c1259b",
"silent": true
},
"Resolver": {
"deploy": false
},
"FIFSRegistrar": {
"deploy": false
}
} }
};
knownConfigs.testnet = knownConfigs.ropsten; // Synonyms
knownConfigs.mainnet = knownConfigs.livenet; // Synonyms
if (knownConfigs[this.env]) { async.waterfall([
self.ensConfig = utils.recursiveMerge(self.ensConfig, knownConfigs[this.env]); function registry(next) {
} self.events.request('deploy:contract', self.ensConfig.ENSRegistry, (err, _receipt) => {
return next(err);
async.waterfall([ });
function registry(next) { },
self.events.request('deploy:contract', self.ensConfig.ENSRegistry, (err, _receipt) => { function resolver(next) {
return next(err); self.ensConfig.Resolver.args = [self.ensConfig.ENSRegistry.deployedAddress];
}); self.events.request('deploy:contract', self.ensConfig.Resolver, (err, _receipt) => {
}, return next(err);
function resolver(next) { });
self.ensConfig.Resolver.args = [self.ensConfig.ENSRegistry.deployedAddress]; },
self.events.request('deploy:contract', self.ensConfig.Resolver, (err, _receipt) => { function registrar(next) {
return next(err); if (!self.registration || !self.registration.rootDomain) {
}); return next();
}, }
function registrar(next) { const registryAddress = self.ensConfig.ENSRegistry.deployedAddress;
if (!self.registration || !self.registration.rootDomain) { const resolverAddress = self.ensConfig.Resolver.deployedAddress;
return next(); const rootNode = namehash.hash(self.registration.rootDomain);
} const contract = self.ensConfig.FIFSRegistrar;
const registryAddress = self.ensConfig.ENSRegistry.deployedAddress; contract.args = [registryAddress, rootNode];
const resolverAddress = self.ensConfig.Resolver.deployedAddress; contract.onDeploy = [
const rootNode = namehash.hash(self.registration.rootDomain); `ENSRegistry.methods.setOwner('${rootNode}', web3.eth.defaultAccount).send({from: web3.eth.defaultAccount}).then(() => {
const contract = self.ensConfig.FIFSRegistrar;
contract.args = [registryAddress, rootNode];
contract.onDeploy = [
`ENSRegistry.methods.setOwner('${rootNode}', web3.eth.defaultAccount).send({from: web3.eth.defaultAccount}).then(() => {
ENSRegistry.methods.setResolver('${rootNode}', "${resolverAddress}").send({from: web3.eth.defaultAccount}); ENSRegistry.methods.setResolver('${rootNode}', "${resolverAddress}").send({from: web3.eth.defaultAccount});
var reverseNode = web3.utils.soliditySha3(web3.eth.defaultAccount.toLowerCase().substr(2) + '${reverseAddrSuffix}'); var reverseNode = web3.utils.soliditySha3(web3.eth.defaultAccount.toLowerCase().substr(2) + '${reverseAddrSuffix}');
ENSRegistry.methods.setResolver(reverseNode, "${resolverAddress}").send({from: web3.eth.defaultAccount}); ENSRegistry.methods.setResolver(reverseNode, "${resolverAddress}").send({from: web3.eth.defaultAccount});
Resolver.methods.setAddr('${rootNode}', web3.eth.defaultAccount).send({from: web3.eth.defaultAccount}); Resolver.methods.setAddr('${rootNode}', web3.eth.defaultAccount).send({from: web3.eth.defaultAccount});
Resolver.methods.setName(reverseNode, '${self.registration.rootDomain}').send({from: web3.eth.defaultAccount}); Resolver.methods.setName(reverseNode, '${self.registration.rootDomain}').send({from: web3.eth.defaultAccount});
})` })`
]; ];
self.events.request('deploy:contract', contract, (err, _receipt) => { self.events.request('deploy:contract', contract, (err, _receipt) => {
return next(err); return next(err);
}); });
} }
], (err) => { ], (err) => {
self.configured = true; self.configured = true;
if (err) { if (err) {
self.logger.error('Error while deploying ENS contracts'); self.logger.error('Error while deploying ENS contracts');
self.logger.error(err.message || err); self.logger.error(err.message || err);
return; return;
} }
self.setProviderAndRegisterDomains(cb); self.setProviderAndRegisterDomains(cb);
});
}); });
} }