From 300b2326abd8b1ceef249b6c10a1f66cd54b3e32 Mon Sep 17 00:00:00 2001 From: VoR0220 Date: Fri, 15 Jun 2018 12:32:48 -0500 Subject: [PATCH] starting to create registration and some changes to the deployment Signed-off-by: VoR0220 --- js/embark.js | 8 +++++--- lib/modules/ens/embarkjs.js | 32 +++++++++++++++++++++++++++++--- lib/modules/ens/index.js | 20 +++++++++++--------- 3 files changed, 45 insertions(+), 15 deletions(-) diff --git a/js/embark.js b/js/embark.js index 90cab289f..2db701e18 100644 --- a/js/embark.js +++ b/js/embark.js @@ -376,12 +376,14 @@ EmbarkJS.Names.lookup = function (identifier) { // To Implement -/* + // register a name EmbarkJS.Names.register = function(name, options) { - + if (!this.currentNameSystems) { + throw new Error('Name system provider not set; e.g EmbarkJS.Names.setProvider("ens")'); + } + return this.currentNameSystems.register(name, options); } -*/ EmbarkJS.Utils = { fromAscii: function (str) { diff --git a/lib/modules/ens/embarkjs.js b/lib/modules/ens/embarkjs.js index 0e936e78d..3121d6984 100644 --- a/lib/modules/ens/embarkjs.js +++ b/lib/modules/ens/embarkjs.js @@ -183,7 +183,7 @@ __embarkENS.setProvider = function () { }); }; -__embarkENS.resolve = function(name) { +__embarkENS.resolve = function (name) { const self = this; if (self.ens === undefined) return; @@ -198,7 +198,7 @@ __embarkENS.resolve = function(name) { }).catch(err => err); }; -__embarkENS.lookup = function(address) { +__embarkENS.lookup = function (address) { const self = this; if (self.ens === undefined) return; @@ -211,7 +211,33 @@ __embarkENS.lookup = function(address) { let resolverContract = new EmbarkJS.Contract({abi: self.resolverInterface, address: resolverAddress}); return resolverContract.methods.name(node).call(); }).then((name) => { - if (name === "" || name === undefined) throw Error("ENS name not found"); + if (name === "" || name === undefined) { + console.warn("ENS name not found"); + return; + } return name; }).catch(err => err); }; + +__embarkENS.register = function (name, options) { + const self = this; + + if (self.ens === undefined) return; + + if (options.livenet) { + return; + } + + let node = namehash.hash(name); + + return self.ens.methods.owner(node).call().then((owner) => { + if (owner !== "0x" || owner !== undefined) { + console.warn("name has already been claimed, see owner: ", owner); + return; + } + return self.ens.methods.setSubnodeOwner(node, ); + }).then((addr) => { + + return addr; + }).catch(err => err); +} diff --git a/lib/modules/ens/index.js b/lib/modules/ens/index.js index 450b6e462..6d1336ccb 100644 --- a/lib/modules/ens/index.js +++ b/lib/modules/ens/index.js @@ -4,6 +4,7 @@ const utils = require('../../utils/utils.js'); class ENS { constructor(embark, _options) { + const self = this; this.logger = embark.logger; this.events = embark.events; this.namesConfig = embark.config.namesystemConfig; @@ -12,7 +13,12 @@ class ENS { this.ensResolver = null; this.addENSToEmbarkJS(); - this.addSetProvider(); + this.configureENSRegistry((abi, addr) => { + self.addSetProvider({ + abi: abi, + address: addr + }); + }); } addENSToEmbarkJS() { @@ -43,7 +49,7 @@ class ENS { this.embark.addCodeToEmbarkJS(code); } - configureENSRegistry() { + configureENSRegistry(cb) { const self = this; self.embark.addContractFile('./contracts/ENSRegistry.sol'); self.embark.registerContractConfiguration({ @@ -69,18 +75,14 @@ class ENS { } } }); - self.events.on("deploy:contract:deployed", (contract) => { + self.events.on("contracts:deploy:afterAll", (contract) => { if (contract.className === "ENSRegistry") { - return web3.eth.Contract(contract.abiDefinition, contract.address); + cb(contract.abiDefinition, contract.address); } }); } - addSetProvider() { - const self = this; - - let config = JSON.stringify(self.configureENSRegistry()); - + addSetProvider(config) { let code = "\nEmbarkJS.Names.setProvider('ens'," + config + ");"; let shouldInit = (namesConfig) => {