bare bones bulk registration example spec

Signed-off-by: VoR0220 <catalanor0220@gmail.com>

add registrars to system

Signed-off-by: VoR0220 <catalanor0220@gmail.com>
This commit is contained in:
VoR0220 2018-06-20 14:14:06 -05:00 committed by Iuri Matias
parent abef066652
commit 056b5a0ab9
4 changed files with 75 additions and 9 deletions

View File

@ -273,7 +273,10 @@ 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

@ -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);
}
}

View File

@ -1,5 +1,6 @@
const fs = require('../../core/fs.js'); const fs = require('../../core/fs.js');
const utils = require('../../utils/utils.js'); const utils = require('../../utils/utils.js');
const namehash = require('eth-ens-namehash');
class ENS { class ENS {
constructor(embark, _options) { constructor(embark, _options) {
@ -7,12 +8,13 @@ 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.embark = embark; this.embark = embark;
this.ensRegistry = null;
this.ensResolver = null;
this.addENSToEmbarkJS(); this.addENSToEmbarkJS();
this.configureENSRegistry(); this.configureENSRegistry();
this.configureRootRegistrar();
self.embark.registerActionForEvent("contracts:deploy:afterAll", (cb) => { self.embark.registerActionForEvent("contracts:deploy:afterAll", (cb) => {
self.events.request('contracts:contract', "ENSRegistry", (contract) => { self.events.request('contracts:contract', "ENSRegistry", (contract) => {
let config = { let config = {
@ -55,6 +57,7 @@ class ENS {
configureENSRegistry() { configureENSRegistry() {
const self = this; const self = this;
self.embark.registerContractConfiguration({ self.embark.registerContractConfiguration({
"default": { "default": {
"gas": "auto", "gas": "auto",
@ -65,26 +68,40 @@ class ENS {
}, },
"ropsten": { "ropsten": {
"ENSRegistry": { "ENSRegistry": {
"address": "0x112234455c3a32fd11230c42e7bccd4a84e02010", "address": "0x112234455c3a32fd11230c42e7bccd4a84e02010"
"args": []
} }
}, },
"rinkeby": { "rinkeby": {
"ENSRegistry": { "ENSRegistry": {
"address": "0xe7410170f87102DF0055eB195163A03B7F2Bff4A", "address": "0xe7410170f87102DF0055eB195163A03B7F2Bff4A"
"args": []
} }
}, },
"livenet": { "livenet": {
"ENSRegistry": { "ENSRegistry": {
"address": "0x314159265dd8dbb310642f98f50c066173c1259b", "address": "0x314159265dd8dbb310642f98f50c066173c1259b"
"args": []
} }
} }
}); });
self.embark.events.request("config:contractsFiles:add", self.embark.pathToFile('./contracts/ENSRegistry.sol')); 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) { addSetProvider(config) {
let code = "\nEmbarkJS.Names.setProvider('ens'," + JSON.stringify(config) + ");"; let code = "\nEmbarkJS.Names.setProvider('ens'," + JSON.stringify(config) + ");";

View File

@ -0,0 +1,10 @@
{
"default": {
"enabled": true,
"available_providers": ["ens"],
"provider": "ens",
"register": {
"rootDomain": "embark"
}
}
}