starting to create registration and some changes to the deployment

Signed-off-by: VoR0220 <catalanor0220@gmail.com>
This commit is contained in:
VoR0220 2018-06-15 12:32:48 -05:00 committed by Iuri Matias
parent 0308a65301
commit 300b2326ab
3 changed files with 45 additions and 15 deletions

View File

@ -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) {

View File

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

View File

@ -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) => {