small cleanups

This commit is contained in:
Jonathan Rainville 2018-07-25 16:12:17 -04:00
parent bb019a6989
commit c5d6c1321a
3 changed files with 11 additions and 7 deletions

View File

@ -134,6 +134,8 @@ __embarkENS.resolverInterface = [
const providerNotSetError = 'ENS provider not set';
const NoDecodeAddrError = 'Error: Couldn\'t decode address from ABI: 0x';
const NoDecodeStringError = 'ERROR: The returned value is not a convertible string: 0x0';
const reverseAddrSuffix = '.addr.reverse';
const voidAddress = '0x0000000000000000000000000000000000000000';
__embarkENS.registryAddresses = {
// Mainnet
@ -186,7 +188,7 @@ __embarkENS.resolve = function (name, callback) {
if (err) {
return cb(err);
}
if (resolverAddress === '0x0000000000000000000000000000000000000000') {
if (resolverAddress === voidAddress) {
return cb('Name not yet registered');
}
let resolverContract = new EmbarkJS.Contract({abi: this.resolverInterface, address: resolverAddress});
@ -202,7 +204,7 @@ __embarkENS.lookup = function (address, callback) {
if (address.startsWith("0x")) {
address = address.slice(2);
}
let node = web3.utils.soliditySha3(address.toLowerCase() + ".addr.reverse");
let node = web3.utils.soliditySha3(address.toLowerCase() + reverseAddrSuffix);
function cb(err, name) {
if (err === NoDecodeStringError || err === NoDecodeAddrError) {
@ -215,7 +217,7 @@ __embarkENS.lookup = function (address, callback) {
if (err) {
return cb(err);
}
if (resolverAddress === '0x0000000000000000000000000000000000000000') {
if (resolverAddress === voidAddress) {
return cb('Address not associated to a resolver');
}
let resolverContract = new EmbarkJS.Contract({abi: this.resolverInterface, address: resolverAddress});
@ -236,7 +238,7 @@ __embarkENS.registerSubDomain = function (name, address, callback) {
// Register function generated by the index
registerSubDomain(this.ens, this.registrar, this.resolver, web3.eth.defaultAccount, name, this.registration.rootDomain,
web3.utils.soliditySha3(address.toLowerCase().substr(2) + '.addr.reverse'), address, console, callback);
web3.utils.soliditySha3(address.toLowerCase().substr(2) + reverseAddrSuffix), address, console, callback);
};
__embarkENS.isAvailable = function () {

View File

@ -3,6 +3,8 @@ const utils = require('../../utils/utils.js');
const namehash = require('eth-ens-namehash');
const async = require('async');
const reverseAddrSuffix = '.addr.reverse';
class ENS {
constructor(embark, _options) {
this.logger = embark.logger;
@ -90,7 +92,7 @@ class ENS {
async.each(Object.keys(self.registration.subdomains), (subDomainName, eachCb) => {
const address = self.registration.subdomains[subDomainName];
const reverseNode = utils.soliditySha3(address.toLowerCase().substr(2) + '.addr.reverse');
const reverseNode = utils.soliditySha3(address.toLowerCase().substr(2) + reverseAddrSuffix);
register(ens, registrar, resolver, defaultAccount, subDomainName, self.registration.rootDomain,
reverseNode, address, self.logger, eachCb);
}, cb);
@ -197,7 +199,7 @@ class ENS {
"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');
var reverseNode = web3.utils.soliditySha3(web3.eth.defaultAccount.toLowerCase().substr(2) + '${reverseAddrSuffix}');
ENSRegistry.methods.setResolver(reverseNode, "$Resolver").send();
Resolver.methods.setAddr('${rootNode}', web3.eth.defaultAccount).send();
Resolver.methods.setName(reverseNode, '${this.registration.rootDomain}').send();

View File

@ -32,7 +32,7 @@ contract("ENS", function () {
// Wait for onDeploy to finish
setTimeout(function () {
done();
}, 100);
}, 500);
});
it("should have registered embark.eth", async function () {