if no register config, dont register anything

This commit is contained in:
Jonathan Rainville 2018-07-25 13:08:03 -04:00
parent c41961f3dd
commit 20c631434f
5 changed files with 44 additions and 26 deletions

View File

@ -278,10 +278,7 @@ Config.prototype.loadNameSystemConfigFile = function() {
"default": { "default": {
"available_providers": ["ens"], "available_providers": ["ens"],
"provider": "ens", "provider": "ens",
"enabled": true, "enabled": true
"register": {
"rootDomain": "embark"
}
} }
}; };

View File

@ -226,6 +226,10 @@ __embarkENS.lookup = function (address, callback) {
__embarkENS.registerSubDomain = function (name, address, callback) { __embarkENS.registerSubDomain = function (name, address, callback) {
callback = callback || function () {}; callback = callback || function () {};
if (!this.registration || !this.registration.rootDomain) {
return callback('No rootDomain is declared in config/namesystem.js (register.rootDomain). Unable to register a subdomain until then.');
}
if (!address || !web3.utils.isAddress(address)) { if (!address || !web3.utils.isAddress(address)) {
return callback('You need to specify a valid address for the subdomain'); return callback('You need to specify a valid address for the subdomain');
} }

View File

@ -8,10 +8,9 @@ class ENS {
this.logger = embark.logger; this.logger = embark.logger;
this.events = embark.events; this.events = embark.events;
this.namesConfig = embark.config.namesystemConfig; this.namesConfig = embark.config.namesystemConfig;
this.registration = this.namesConfig.register; this.registration = this.namesConfig.register || {};
this.embark = embark; this.embark = embark;
// TODO add checks to see if config is ok
this.addENSToEmbarkJS(); this.addENSToEmbarkJS();
this.configureContracts(); this.configureContracts();
this.registerEvents(); this.registerEvents();
@ -49,7 +48,7 @@ class ENS {
}; };
self.addSetProvider(config); self.addSetProvider(config);
if (!self.registration || !self.registration.domains || !Object.keys(self.registration.domains).length) { if (!self.registration || !self.registration.subdomains || !Object.keys(self.registration.subdomains).length) {
return cb(); return cb();
} }
self.registerConfigDomains(config, cb); self.registerConfigDomains(config, cb);
@ -63,7 +62,7 @@ class ENS {
self.events.request("blockchain:contract:create", self.events.request("blockchain:contract:create",
{abi: config.registrarAbi, address: config.registrarAddress}, {abi: config.registrarAbi, address: config.registrarAddress},
(registrar) => { (registrar) => {
async.each(Object.keys(self.registration.domains), (subDomainName, eachCb) => { async.each(Object.keys(self.registration.subdomains), (subDomainName, eachCb) => {
const toSend = registrar.methods.register(utils.soliditySha3(subDomainName), defaultAccount); const toSend = registrar.methods.register(utils.soliditySha3(subDomainName), defaultAccount);
toSend.estimateGas().then(gasEstimated => { toSend.estimateGas().then(gasEstimated => {
@ -112,11 +111,11 @@ class ENS {
} }
configureContracts() { configureContracts() {
let rootNode = namehash.hash(this.registration.rootDomain); const config = {
this.embark.registerContractConfiguration({
"default": { "default": {
"gas": "auto", "gas": "auto"
},
"development": {
"contracts": { "contracts": {
"ENSRegistry": { "ENSRegistry": {
"deploy": true, "deploy": true,
@ -127,17 +126,7 @@ class ENS {
"args": ["$ENSRegistry"] "args": ["$ENSRegistry"]
}, },
"FIFSRegistrar": { "FIFSRegistrar": {
"deploy": true, "deploy": false
"args": ["$ENSRegistry", rootNode],
"onDeploy": [
`ENSRegistry.methods.setOwner('${rootNode}', web3.eth.defaultAccount).send().then(() => {
ENSRegistry.methods.setResolver('${rootNode}', "$Resolver").send();
var reverseNode = web3.utils.soliditySha3(web3.eth.defaultAccount.toLowerCase().substr(2) + '.addr.reverse');
ENSRegistry.methods.setResolver(reverseNode, "$Resolver").send();
Resolver.methods.setAddr('${rootNode}', web3.eth.defaultAccount).send();
Resolver.methods.setName(reverseNode, '${this.registration.rootDomain}').send();
})`
]
} }
} }
}, },
@ -146,6 +135,9 @@ class ENS {
"ENSRegistry": { "ENSRegistry": {
"address": "0x112234455c3a32fd11230c42e7bccd4a84e02010" "address": "0x112234455c3a32fd11230c42e7bccd4a84e02010"
}, },
"Resolver": {
"deploy": false
},
"FIFSRegistrar": { "FIFSRegistrar": {
"deploy": false "deploy": false
} }
@ -156,6 +148,9 @@ class ENS {
"ENSRegistry": { "ENSRegistry": {
"address": "0xe7410170f87102DF0055eB195163A03B7F2Bff4A" "address": "0xe7410170f87102DF0055eB195163A03B7F2Bff4A"
}, },
"Resolver": {
"deploy": false
},
"FIFSRegistrar": { "FIFSRegistrar": {
"deploy": false "deploy": false
} }
@ -166,12 +161,35 @@ class ENS {
"ENSRegistry": { "ENSRegistry": {
"address": "0x314159265dd8dbb310642f98f50c066173c1259b" "address": "0x314159265dd8dbb310642f98f50c066173c1259b"
}, },
"Resolver": {
"deploy": false
},
"FIFSRegistrar": { "FIFSRegistrar": {
"deploy": false "deploy": false
} }
} }
} }
}); };
if (this.registration && this.registration.rootDomain) {
// Register root domain if it is defined
const rootNode = namehash.hash(this.registration.rootDomain);
config.development.contracts['FIFSRegistrar'] = {
"deploy": true,
"args": ["$ENSRegistry", rootNode],
"onDeploy": [
`ENSRegistry.methods.setOwner('${rootNode}', web3.eth.defaultAccount).send().then(() => {
ENSRegistry.methods.setResolver('${rootNode}', "$Resolver").send();
var reverseNode = web3.utils.soliditySha3(web3.eth.defaultAccount.toLowerCase().substr(2) + '.addr.reverse');
ENSRegistry.methods.setResolver(reverseNode, "$Resolver").send();
Resolver.methods.setAddr('${rootNode}', web3.eth.defaultAccount).send();
Resolver.methods.setName(reverseNode, '${this.registration.rootDomain}').send();
})`
]
};
}
this.embark.registerContractConfiguration(config);
this.embark.events.request("config:contractsFiles:add", this.embark.pathToFile('./contracts/ENSRegistry.sol')); this.embark.events.request("config:contractsFiles:add", this.embark.pathToFile('./contracts/ENSRegistry.sol'));
this.embark.events.request("config:contractsFiles:add", this.embark.pathToFile('./contracts/FIFSRegistrar.sol')); this.embark.events.request("config:contractsFiles:add", this.embark.pathToFile('./contracts/FIFSRegistrar.sol'));

View File

@ -1,7 +1,6 @@
const namehash = require('eth-ens-namehash'); const namehash = require('eth-ens-namehash');
function registerSubDomain(ens, registrar, resolver, defaultAccount, subdomain, rootDomain, reverseNode, address, callback) { function registerSubDomain(ens, registrar, resolver, defaultAccount, subdomain, rootDomain, reverseNode, address, callback) {
console.log('Register', arguments);
const subnode = namehash.hash(subdomain); const subnode = namehash.hash(subdomain);
const node = namehash.hash(`${subdomain}.${rootDomain}`); const node = namehash.hash(`${subdomain}.${rootDomain}`);
const toSend = registrar.methods.register(subnode, defaultAccount); const toSend = registrar.methods.register(subnode, defaultAccount);

View File

@ -4,7 +4,7 @@ module.exports = {
provider: "ens", provider: "ens",
register: { register: {
rootDomain: "embark.eth", rootDomain: "embark.eth",
domains: { subdomains: {
'status': '0x1a2f3b98e434c02363f3dac3174af93c1d690914' 'status': '0x1a2f3b98e434c02363f3dac3174af93c1d690914'
} }
} }