From e3bdbd520fa8dd5379ea4882d7c266a443fae644 Mon Sep 17 00:00:00 2001 From: VoR0220 Date: Wed, 20 Jun 2018 14:14:06 -0500 Subject: [PATCH 1/3] bare bones bulk registration example spec Signed-off-by: VoR0220 add registrars to system Signed-off-by: VoR0220 --- lib/core/config.js | 5 ++- lib/modules/ens/contracts/FIFSRegistrar.sol | 36 +++++++++++++++++++++ lib/modules/ens/index.js | 33 ++++++++++++++----- test_apps/test_app/config/namesystem.json | 10 ++++++ 4 files changed, 75 insertions(+), 9 deletions(-) create mode 100644 lib/modules/ens/contracts/FIFSRegistrar.sol create mode 100644 test_apps/test_app/config/namesystem.json diff --git a/lib/core/config.js b/lib/core/config.js index 608d1f580..691eea978 100644 --- a/lib/core/config.js +++ b/lib/core/config.js @@ -265,7 +265,10 @@ Config.prototype.loadNameSystemConfigFile = function() { "default": { "available_providers": ["ens"], "provider": "ens", - "enabled": true + "enabled": true, + "register": { + "rootDomain": "embark" + } } }; diff --git a/lib/modules/ens/contracts/FIFSRegistrar.sol b/lib/modules/ens/contracts/FIFSRegistrar.sol new file mode 100644 index 000000000..62b7f270b --- /dev/null +++ b/lib/modules/ens/contracts/FIFSRegistrar.sol @@ -0,0 +1,36 @@ +pragma solidity ^0.4.18; + +import './ENS.sol'; + +/** + * A registrar that allocates subdomains to the first person to claim them. + */ +contract FIFSRegistrar { + ENS ens; + bytes32 rootNode; + + modifier only_owner(bytes32 subnode) { + address currentOwner = ens.owner(keccak256(rootNode, subnode)); + require(currentOwner == 0 || currentOwner == msg.sender); + _; + } + + /** + * Constructor. + * @param ensAddr The address of the ENS registry. + * @param node The node that this registrar administers. + */ + function FIFSRegistrar(ENS ensAddr, bytes32 node) public { + ens = ensAddr; + rootNode = node; + } + + /** + * Register a name, or change the owner of an existing registration. + * @param subnode The hash of the label to register. + * @param owner The address of the new owner. + */ + function register(bytes32 subnode, address owner) public only_owner(subnode) { + ens.setSubnodeOwner(rootNode, subnode, owner); + } +} diff --git a/lib/modules/ens/index.js b/lib/modules/ens/index.js index 585c34bb1..c6cd454b7 100644 --- a/lib/modules/ens/index.js +++ b/lib/modules/ens/index.js @@ -1,5 +1,6 @@ const fs = require('../../core/fs.js'); const utils = require('../../utils/utils.js'); +const namehash = require('eth-ens-namehash'); class ENS { constructor(embark, _options) { @@ -7,12 +8,13 @@ class ENS { this.logger = embark.logger; this.events = embark.events; this.namesConfig = embark.config.namesystemConfig; + this.registration = this.namesConfig.register; this.embark = embark; - this.ensRegistry = null; - this.ensResolver = null; this.addENSToEmbarkJS(); this.configureENSRegistry(); + this.configureRootRegistrar(); + self.embark.registerActionForEvent("contracts:deploy:afterAll", (cb) => { self.events.request('contracts:contract', "ENSRegistry", (contract) => { let config = { @@ -55,6 +57,7 @@ class ENS { configureENSRegistry() { const self = this; + self.embark.registerContractConfiguration({ "default": { "gas": "auto", @@ -65,26 +68,40 @@ class ENS { }, "ropsten": { "ENSRegistry": { - "address": "0x112234455c3a32fd11230c42e7bccd4a84e02010", - "args": [] + "address": "0x112234455c3a32fd11230c42e7bccd4a84e02010" } }, "rinkeby": { "ENSRegistry": { - "address": "0xe7410170f87102DF0055eB195163A03B7F2Bff4A", - "args": [] + "address": "0xe7410170f87102DF0055eB195163A03B7F2Bff4A" } }, "livenet": { "ENSRegistry": { - "address": "0x314159265dd8dbb310642f98f50c066173c1259b", - "args": [] + "address": "0x314159265dd8dbb310642f98f50c066173c1259b" } } }); + self.embark.events.request("config:contractsFiles:add", self.embark.pathToFile('./contracts/ENSRegistry.sol')); } + configureRootRegistrar() { + const self = this; + let rootNode = namehash.hash(self.registration.rootDomain); + self.embark.registerContractConfiguration({ + "default": { + "gas": "auto", + "FIFSRegistrar": { + "deploy": true, + "args": ["$ENSRegistry", rootNode], + "onDeploy": ["ENSRegistry.methods.setOwner(0, FIFSRegistrar.options.address).send()"] + } + } + }); + self.embark.events.request("config:contractsFiles:add", self.embark.pathToFile('./contracts/FIFSRegistrar.sol')); + } + addSetProvider(config) { let code = "\nEmbarkJS.Names.setProvider('ens'," + JSON.stringify(config) + ");"; diff --git a/test_apps/test_app/config/namesystem.json b/test_apps/test_app/config/namesystem.json new file mode 100644 index 000000000..3995055a3 --- /dev/null +++ b/test_apps/test_app/config/namesystem.json @@ -0,0 +1,10 @@ +{ + "default": { + "enabled": true, + "available_providers": ["ens"], + "provider": "ens", + "register": { + "rootDomain": "embark" + } + } +} \ No newline at end of file From 4589803003be94c0aa541db203e9aeaf3855af08 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Thu, 21 Jun 2018 13:24:41 -0400 Subject: [PATCH 2/3] put contracts inside the contracts field --- lib/modules/ens/index.js | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/lib/modules/ens/index.js b/lib/modules/ens/index.js index c6cd454b7..0845edb57 100644 --- a/lib/modules/ens/index.js +++ b/lib/modules/ens/index.js @@ -61,24 +61,32 @@ class ENS { self.embark.registerContractConfiguration({ "default": { "gas": "auto", - "ENSRegistry": { - "deploy": true, - "args": [] + "contracts": { + "ENSRegistry": { + "deploy": true, + "args": [] + } } }, "ropsten": { - "ENSRegistry": { - "address": "0x112234455c3a32fd11230c42e7bccd4a84e02010" + "contracts": { + "ENSRegistry": { + "address": "0x112234455c3a32fd11230c42e7bccd4a84e02010" + } } }, "rinkeby": { - "ENSRegistry": { - "address": "0xe7410170f87102DF0055eB195163A03B7F2Bff4A" + "contracts": { + "ENSRegistry": { + "address": "0xe7410170f87102DF0055eB195163A03B7F2Bff4A" + } } }, "livenet": { - "ENSRegistry": { - "address": "0x314159265dd8dbb310642f98f50c066173c1259b" + "contracts": { + "ENSRegistry": { + "address": "0x314159265dd8dbb310642f98f50c066173c1259b" + } } } }); @@ -92,10 +100,12 @@ class ENS { self.embark.registerContractConfiguration({ "default": { "gas": "auto", - "FIFSRegistrar": { - "deploy": true, - "args": ["$ENSRegistry", rootNode], - "onDeploy": ["ENSRegistry.methods.setOwner(0, FIFSRegistrar.options.address).send()"] + "contracts": { + "FIFSRegistrar": { + "deploy": true, + "args": ["$ENSRegistry", rootNode], + "onDeploy": ["ENSRegistry.methods.setOwner(0, FIFSRegistrar.options.address).send()"] + } } } }); From e5ad90719bc7e3088e701f7624ed8c22774da698 Mon Sep 17 00:00:00 2001 From: VoR0220 Date: Thu, 21 Jun 2018 12:57:41 -0500 Subject: [PATCH 3/3] ensure that FIFS doesn't deploy on other test and main networks Signed-off-by: VoR0220 --- lib/modules/ens/index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/modules/ens/index.js b/lib/modules/ens/index.js index 0845edb57..5051570c9 100644 --- a/lib/modules/ens/index.js +++ b/lib/modules/ens/index.js @@ -107,7 +107,10 @@ class ENS { "onDeploy": ["ENSRegistry.methods.setOwner(0, FIFSRegistrar.options.address).send()"] } } - } + }, + "ropsten": {}, + "rinkeby": {}, + "livenet": {} }); self.embark.events.request("config:contractsFiles:add", self.embark.pathToFile('./contracts/FIFSRegistrar.sol')); }