2018-05-23 09:58:18 -05:00
|
|
|
const fs = require('../../core/fs.js');
|
2018-05-23 10:24:53 -05:00
|
|
|
const utils = require('../../utils/utils.js');
|
2018-06-20 14:14:06 -05:00
|
|
|
const namehash = require('eth-ens-namehash');
|
2018-07-26 14:50:38 -04:00
|
|
|
const async = require('async');
|
2018-08-22 18:32:43 -04:00
|
|
|
const embarkJsUtils = require('embarkjs').Utils;
|
2018-07-25 16:12:17 -04:00
|
|
|
const reverseAddrSuffix = '.addr.reverse';
|
|
|
|
|
2018-07-25 16:12:17 -04:00
|
|
|
const reverseAddrSuffix = '.addr.reverse';
|
|
|
|
|
2018-05-23 09:58:18 -05:00
|
|
|
class ENS {
|
2018-05-30 12:26:49 -04:00
|
|
|
constructor(embark, _options) {
|
2018-08-22 18:32:43 -04:00
|
|
|
this.env = embark.env;
|
|
|
|
this.isDev = embark.config.blockchainConfig.isDev;
|
2018-05-23 11:46:02 -05:00
|
|
|
this.logger = embark.logger;
|
|
|
|
this.events = embark.events;
|
2018-05-30 12:26:49 -04:00
|
|
|
this.namesConfig = embark.config.namesystemConfig;
|
2018-07-25 13:08:03 -04:00
|
|
|
this.registration = this.namesConfig.register || {};
|
2018-05-23 11:46:02 -05:00
|
|
|
this.embark = embark;
|
|
|
|
|
2018-08-22 18:32:43 -04:00
|
|
|
if (this.namesConfig === {} ||
|
|
|
|
this.namesConfig.enabled !== true ||
|
|
|
|
this.namesConfig.available_providers.indexOf('ens') < 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.doSetENSProvider = this.namesConfig.provider === 'ens';
|
|
|
|
|
2018-05-23 11:46:02 -05:00
|
|
|
this.addENSToEmbarkJS();
|
2018-07-13 12:37:34 -04:00
|
|
|
this.configureContracts();
|
2018-08-13 11:36:48 +01:00
|
|
|
this.registerActionForEvents();
|
2018-07-13 16:41:35 -04:00
|
|
|
}
|
2018-06-20 14:14:06 -05:00
|
|
|
|
2018-07-13 16:41:35 -04:00
|
|
|
registerEvents() {
|
2018-08-22 18:32:43 -04:00
|
|
|
this.embark.registerActionForEvent("contracts:deploy:afterAll", this.setProviderAndRegisterDomains.bind(this));
|
|
|
|
|
|
|
|
this.events.setCommandHandler("storage:ens:associate", this.associateStorageToEns.bind(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
setProviderAndRegisterDomains(cb) {
|
2018-07-13 16:41:35 -04:00
|
|
|
const self = this;
|
2018-08-22 18:32:43 -04:00
|
|
|
async.parallel([
|
|
|
|
function getENSRegistry(paraCb) {
|
|
|
|
self.events.request('contracts:contract', "ENSRegistry", (contract) => {
|
|
|
|
paraCb(null, contract);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
function getRegistrar(paraCb) {
|
|
|
|
self.events.request('contracts:contract', "FIFSRegistrar", (contract) => {
|
|
|
|
paraCb(null, contract);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
function getResolver(paraCb) {
|
|
|
|
self.events.request('contracts:contract', "Resolver", (contract) => {
|
|
|
|
paraCb(null, contract);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
], (err, results) => {
|
|
|
|
// result[0] => ENSRegistry; result[1] => FIFSRegistrar; result[2] => FIFSRegistrar
|
|
|
|
let config = {
|
|
|
|
env: self.env,
|
|
|
|
registration: self.registration,
|
|
|
|
registryAbi: results[0].abiDefinition,
|
|
|
|
registryAddress: results[0].deployedAddress,
|
|
|
|
registrarAbi: results[1].abiDefinition,
|
|
|
|
registrarAddress: results[1].deployedAddress,
|
|
|
|
resolverAbi: results[2].abiDefinition,
|
|
|
|
resolverAddress: results[2].deployedAddress
|
|
|
|
};
|
|
|
|
|
|
|
|
if (self.doSetENSProvider) {
|
2018-08-06 08:47:27 -04:00
|
|
|
self.addSetProvider(config);
|
2018-08-22 18:32:43 -04:00
|
|
|
}
|
2018-07-26 13:52:22 -04:00
|
|
|
|
2018-08-22 18:32:43 -04:00
|
|
|
if ((!self.isDev && self.env !== 'privatenet') || !self.registration || !self.registration.subdomains || !Object.keys(self.registration.subdomains).length) {
|
|
|
|
return cb();
|
|
|
|
}
|
|
|
|
self.registerConfigDomains(config, cb);
|
2018-07-26 13:52:22 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-08-22 18:32:43 -04:00
|
|
|
associateStorageToEns(options, cb) {
|
|
|
|
const self = this;
|
|
|
|
// Code inspired by https://github.com/monkybrain/ipfs-to-ens
|
|
|
|
const {name, storageHash} = options;
|
|
|
|
|
|
|
|
if (!utils.isValidEthDomain(name)) {
|
|
|
|
return cb('Invalid domain name ' + name);
|
|
|
|
}
|
|
|
|
|
|
|
|
let hashedName = namehash.hash(name);
|
|
|
|
let contentHash;
|
|
|
|
try {
|
|
|
|
contentHash = utils.hashTo32ByteHexString(storageHash);
|
|
|
|
} catch (e) {
|
|
|
|
return cb('Invalid IPFS hash');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set content
|
|
|
|
async.waterfall([
|
|
|
|
function getRegistryABI(next) {
|
|
|
|
self.events.request('contracts:contract', "ENSRegistry", (contract) => {
|
|
|
|
next(null, contract);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
function createRegistryContract(contract, next) {
|
|
|
|
self.events.request("blockchain:contract:create",
|
|
|
|
{abi: contract.abiDefinition, address: contract.deployedAddress},
|
|
|
|
(resolver) => {
|
|
|
|
next(null, resolver);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
function getResolverForName(registry, next) {
|
|
|
|
registry.methods.resolver(hashedName).call((err, resolverAddress) => {
|
|
|
|
if (err) {
|
|
|
|
return cb(err);
|
|
|
|
}
|
|
|
|
if (resolverAddress === '0x0000000000000000000000000000000000000000') {
|
|
|
|
return cb('Name not yet registered');
|
|
|
|
}
|
|
|
|
next(null, resolverAddress);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
function getResolverABI(resolverAddress, next) {
|
|
|
|
self.events.request('contracts:contract', "Resolver", (contract) => {
|
|
|
|
next(null, resolverAddress, contract);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
function createResolverContract(resolverAddress, contract, next) {
|
|
|
|
self.events.request("blockchain:contract:create",
|
|
|
|
{abi: contract.abiDefinition, address: resolverAddress},
|
|
|
|
(resolver) => {
|
|
|
|
next(null, resolver);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
function getDefaultAccount(resolver, next) {
|
|
|
|
self.events.request("blockchain:defaultAccount:get", (defaultAccount) => {
|
|
|
|
next(null, resolver, defaultAccount);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
function setContent(resolver, defaultAccount, next) {
|
|
|
|
resolver.methods.setContent(hashedName, contentHash).send({from: defaultAccount}).then((transaction) => {
|
|
|
|
if (transaction.status !== "0x1" && transaction.status !== "0x01" && transaction.status !== true) {
|
|
|
|
return next('Association failed. Status: ' + transaction.status);
|
|
|
|
}
|
|
|
|
next();
|
|
|
|
}).catch(next);
|
|
|
|
}
|
|
|
|
], cb);
|
|
|
|
}
|
|
|
|
|
2018-07-13 16:41:35 -04:00
|
|
|
registerConfigDomains(config, cb) {
|
|
|
|
const self = this;
|
2018-07-25 13:57:03 -04:00
|
|
|
const register = require('./register');
|
2018-08-22 18:32:43 -04:00
|
|
|
const secureSend = embarkJsUtils.secureSend;
|
2018-07-25 13:57:03 -04:00
|
|
|
self.events.request("blockchain:defaultAccount:get", (defaultAccount) => {
|
2018-07-25 13:57:03 -04:00
|
|
|
async.parallel([
|
|
|
|
function createRegistryContract(paraCb) {
|
|
|
|
self.events.request("blockchain:contract:create",
|
|
|
|
{abi: config.registryAbi, address: config.registryAddress},
|
|
|
|
(registry) => {
|
|
|
|
paraCb(null, registry);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
function createRegistrarContract(paraCb) {
|
|
|
|
self.events.request("blockchain:contract:create",
|
|
|
|
{abi: config.registrarAbi, address: config.registrarAddress},
|
|
|
|
(registrar) => {
|
|
|
|
paraCb(null, registrar);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
function createResolverContract(paraCb) {
|
|
|
|
self.events.request("blockchain:contract:create",
|
|
|
|
{abi: config.resolverAbi, address: config.resolverAddress},
|
|
|
|
(resolver) => {
|
|
|
|
paraCb(null, resolver);
|
2018-07-13 16:41:35 -04:00
|
|
|
});
|
2018-07-25 13:57:03 -04:00
|
|
|
}
|
2018-08-22 18:32:43 -04:00
|
|
|
], function(err, contracts) {
|
2018-07-25 13:57:03 -04:00
|
|
|
if (err) {
|
|
|
|
return cb(err);
|
|
|
|
}
|
|
|
|
const [ens, registrar, resolver] = contracts;
|
|
|
|
|
|
|
|
async.each(Object.keys(self.registration.subdomains), (subDomainName, eachCb) => {
|
|
|
|
const address = self.registration.subdomains[subDomainName];
|
2018-07-25 16:12:17 -04:00
|
|
|
const reverseNode = utils.soliditySha3(address.toLowerCase().substr(2) + reverseAddrSuffix);
|
2018-07-25 13:57:03 -04:00
|
|
|
register(ens, registrar, resolver, defaultAccount, subDomainName, self.registration.rootDomain,
|
2018-08-22 18:32:43 -04:00
|
|
|
reverseNode, address, self.logger, secureSend, eachCb);
|
2018-07-25 13:57:03 -04:00
|
|
|
}, cb);
|
|
|
|
|
|
|
|
});
|
2018-07-13 16:41:35 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-08-10 11:31:10 +01:00
|
|
|
registerAPI(config) {
|
|
|
|
let self = this;
|
|
|
|
self.embark.registerAPICall(
|
|
|
|
'get',
|
2018-08-13 11:36:48 +01:00
|
|
|
'/embark-api/ens/resolve',
|
2018-08-10 11:31:10 +01:00
|
|
|
(req, res) => {
|
2018-08-13 11:36:48 +01:00
|
|
|
self.resolveName(req.query.name, config, (error, address) => {
|
|
|
|
if (error) {
|
|
|
|
return res.send({error: error.message});
|
|
|
|
}
|
|
|
|
res.send({address});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
self.embark.registerAPICall(
|
|
|
|
'get',
|
|
|
|
'/embark-api/ens/lookup',
|
|
|
|
(req, res) => {
|
|
|
|
self.lookupAddress(req.query.address, config, (error, name) => {
|
|
|
|
if (error) {
|
|
|
|
return res.send({error: error.message});
|
|
|
|
}
|
|
|
|
res.send({name});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
2018-08-10 11:31:10 +01:00
|
|
|
|
2018-08-13 11:36:48 +01:00
|
|
|
self.embark.registerAPICall(
|
|
|
|
'post',
|
|
|
|
'/embark-api/ens/register',
|
|
|
|
(req, res) => {
|
|
|
|
self.registerSubdomain({[req.body.subdomain]: req.body.address}, config, (error, transaction) => {
|
|
|
|
if (error) {
|
|
|
|
return res.send({error: error.message});
|
|
|
|
}
|
|
|
|
res.send({transaction});
|
|
|
|
});
|
2018-08-10 11:31:10 +01:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-08-13 11:36:48 +01:00
|
|
|
registerConfigSubdomains(config, callback) {
|
|
|
|
this.registerSubdomains(this.registration.subdomains, config, callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
lookupAddress(address, config, callback) {
|
|
|
|
let self = this;
|
|
|
|
self.createResolverContract(config, (err, resolver) => {
|
|
|
|
if (err) {
|
|
|
|
return callback(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (address.startsWith("0x")) {
|
|
|
|
address = address.slice(2);
|
|
|
|
}
|
|
|
|
let node = utils.soliditySha3(address.toLowerCase() + reverseAddrSuffix);
|
|
|
|
resolver.methods.name(node).call(callback);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
resolveName(name, config, callback) {
|
|
|
|
let self = this;
|
|
|
|
self.createResolverContract(config, (err, resolver) => {
|
|
|
|
if (err) {
|
|
|
|
return callback(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
let node = namehash.hash(name);
|
|
|
|
resolver.methods.name(node).call(callback);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
registerSubdomains(subdomains, config, callback) {
|
2018-07-13 16:41:35 -04:00
|
|
|
const self = this;
|
2018-07-25 13:57:03 -04:00
|
|
|
const register = require('./register');
|
2018-08-13 11:36:48 +01:00
|
|
|
|
2018-07-13 16:41:35 -04:00
|
|
|
self.events.request("blockchain:defaultAccount:get", (defaultAccount) => {
|
2018-08-13 11:36:48 +01:00
|
|
|
async.parallel({
|
|
|
|
ens: self.createRegistryContract.bind(this, config),
|
|
|
|
registrar: self.createRegistrarContract.bind(this, config),
|
|
|
|
resolver: self.createResolverContract.bind(this, config)
|
|
|
|
}, function (err, contracts) {
|
2018-07-25 13:57:03 -04:00
|
|
|
if (err) {
|
2018-08-13 11:36:48 +01:00
|
|
|
return callback(err);
|
2018-07-25 13:57:03 -04:00
|
|
|
}
|
2018-08-13 11:36:48 +01:00
|
|
|
const {ens, registrar, resolver} = contracts;
|
2018-07-25 13:57:03 -04:00
|
|
|
|
2018-08-13 11:36:48 +01:00
|
|
|
async.each(Object.keys(subdomains), (subdomainName, eachCb) => {
|
|
|
|
const address = subdomains[subdomainName];
|
2018-07-25 16:12:17 -04:00
|
|
|
const reverseNode = utils.soliditySha3(address.toLowerCase().substr(2) + reverseAddrSuffix);
|
2018-08-13 11:36:48 +01:00
|
|
|
register(ens, registrar, resolver, defaultAccount, subdomainName, self.registration.rootDomain,
|
2018-07-25 13:57:03 -04:00
|
|
|
reverseNode, address, self.logger, eachCb);
|
2018-08-13 11:36:48 +01:00
|
|
|
}, callback);
|
2018-07-25 13:57:03 -04:00
|
|
|
});
|
2018-07-13 16:41:35 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-08-13 11:36:48 +01:00
|
|
|
createRegistryContract(config, callback) {
|
|
|
|
this.events.request("blockchain:contract:create", {
|
|
|
|
abi: config.registryAbi,
|
|
|
|
address: config.registryAddress
|
|
|
|
}, (registry) => {
|
|
|
|
callback(null, registry);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
createRegistrarContract(config, callback) {
|
|
|
|
this.events.request("blockchain:contract:create", {
|
|
|
|
abi: config.registrarAbi,
|
|
|
|
address: config.registrarAddress
|
|
|
|
}, (registrar) => {
|
|
|
|
callback(null, registrar);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
createResolverContract(config, callback) {
|
|
|
|
this.events.request("blockchain:contract:create", {
|
|
|
|
abi: config.resolverAbi,
|
|
|
|
address: config.resolverAddress
|
|
|
|
}, (resolver) => {
|
|
|
|
callback(null, resolver);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-05-23 11:46:02 -05:00
|
|
|
addENSToEmbarkJS() {
|
|
|
|
const self = this;
|
|
|
|
|
2018-06-15 10:23:55 -05:00
|
|
|
// get namehash, import it into file
|
2018-07-13 16:41:35 -04:00
|
|
|
self.events.request("version:get:eth-ens-namehash", function (EnsNamehashVersion) {
|
2018-05-23 11:46:02 -05:00
|
|
|
let currentEnsNamehashVersion = require('../../../package.json').dependencies["eth-ens-namehash"];
|
|
|
|
if (EnsNamehashVersion !== currentEnsNamehashVersion) {
|
2018-07-13 16:41:35 -04:00
|
|
|
self.events.request("version:getPackageLocation", "eth-ens-namehash", EnsNamehashVersion, function (err, location) {
|
2018-05-23 11:46:02 -05:00
|
|
|
self.embark.registerImportFile("eth-ens-namehash", fs.dappPath(location));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-07-25 12:48:46 -04:00
|
|
|
let code = fs.readFileSync(utils.joinPath(__dirname, 'register.js')).toString();
|
2018-05-23 11:46:02 -05:00
|
|
|
code += "\n" + fs.readFileSync(utils.joinPath(__dirname, 'embarkjs.js')).toString();
|
|
|
|
code += "\nEmbarkJS.Names.registerProvider('ens', __embarkENS);";
|
|
|
|
|
|
|
|
this.embark.addCodeToEmbarkJS(code);
|
2018-05-23 11:55:11 -05:00
|
|
|
}
|
2018-05-23 10:24:53 -05:00
|
|
|
|
2018-07-13 12:37:34 -04:00
|
|
|
configureContracts() {
|
2018-07-25 13:08:03 -04:00
|
|
|
const config = {
|
2018-06-15 10:23:55 -05:00
|
|
|
"default": {
|
2018-07-25 13:08:03 -04:00
|
|
|
"gas": "auto"
|
|
|
|
},
|
|
|
|
"development": {
|
2018-08-22 18:32:43 -04:00
|
|
|
"contracts": {
|
|
|
|
"ENS": {
|
|
|
|
"deploy": false,
|
|
|
|
"silent": true
|
|
|
|
}
|
|
|
|
}
|
2018-07-25 13:08:03 -04:00
|
|
|
},
|
2018-07-25 13:08:03 -04:00
|
|
|
"development": {
|
2018-06-21 13:24:41 -04:00
|
|
|
"contracts": {
|
|
|
|
"ENSRegistry": {
|
|
|
|
"deploy": true,
|
2018-08-22 18:32:43 -04:00
|
|
|
"silent": true,
|
2018-06-21 13:24:41 -04:00
|
|
|
"args": []
|
2018-07-13 12:37:34 -04:00
|
|
|
},
|
|
|
|
"Resolver": {
|
|
|
|
"deploy": true,
|
2018-08-22 18:32:43 -04:00
|
|
|
"silent": true,
|
2018-07-13 12:37:34 -04:00
|
|
|
"args": ["$ENSRegistry"]
|
|
|
|
},
|
2018-06-21 13:24:41 -04:00
|
|
|
"FIFSRegistrar": {
|
2018-07-25 13:08:03 -04:00
|
|
|
"deploy": false
|
2018-06-21 13:24:41 -04:00
|
|
|
}
|
2018-06-20 14:14:06 -05:00
|
|
|
}
|
2018-06-21 12:57:41 -05:00
|
|
|
},
|
2018-06-26 13:32:53 -05:00
|
|
|
"ropsten": {
|
|
|
|
"contracts": {
|
2018-07-13 12:37:34 -04:00
|
|
|
"ENSRegistry": {
|
2018-08-22 18:32:43 -04:00
|
|
|
"address": "0x112234455c3a32fd11230c42e7bccd4a84e02010",
|
|
|
|
"silent": true
|
2018-07-25 13:08:03 -04:00
|
|
|
},
|
2018-07-25 13:08:03 -04:00
|
|
|
"Resolver": {
|
|
|
|
"deploy": false
|
|
|
|
},
|
2018-06-26 13:32:53 -05:00
|
|
|
"FIFSRegistrar": {
|
|
|
|
"deploy": false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"rinkeby": {
|
|
|
|
"contracts": {
|
2018-07-13 12:37:34 -04:00
|
|
|
"ENSRegistry": {
|
2018-08-22 18:32:43 -04:00
|
|
|
"address": "0xe7410170f87102DF0055eB195163A03B7F2Bff4A",
|
|
|
|
"silent": true
|
2018-07-25 13:08:03 -04:00
|
|
|
},
|
2018-07-25 13:08:03 -04:00
|
|
|
"Resolver": {
|
|
|
|
"deploy": false
|
|
|
|
},
|
2018-06-26 13:32:53 -05:00
|
|
|
"FIFSRegistrar": {
|
|
|
|
"deploy": false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"livenet": {
|
|
|
|
"contracts": {
|
2018-07-13 12:37:34 -04:00
|
|
|
"ENSRegistry": {
|
2018-08-22 18:32:43 -04:00
|
|
|
"address": "0x314159265dd8dbb310642f98f50c066173c1259b",
|
|
|
|
"silent": true
|
2018-07-25 13:08:03 -04:00
|
|
|
},
|
2018-07-25 13:08:03 -04:00
|
|
|
"Resolver": {
|
|
|
|
"deploy": false
|
|
|
|
},
|
2018-06-26 13:32:53 -05:00
|
|
|
"FIFSRegistrar": {
|
|
|
|
"deploy": false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-07-25 13:08:03 -04:00
|
|
|
};
|
2018-08-22 18:32:43 -04:00
|
|
|
config.testnet = config.ropsten;
|
2018-07-25 13:08:03 -04:00
|
|
|
|
|
|
|
if (this.registration && this.registration.rootDomain) {
|
|
|
|
// Register root domain if it is defined
|
|
|
|
const rootNode = namehash.hash(this.registration.rootDomain);
|
|
|
|
config.development.contracts['FIFSRegistrar'] = {
|
|
|
|
"deploy": true,
|
2018-08-22 18:32:43 -04:00
|
|
|
"silent": true,
|
2018-07-25 13:08:03 -04:00
|
|
|
"args": ["$ENSRegistry", rootNode],
|
|
|
|
"onDeploy": [
|
2018-08-22 18:32:43 -04:00
|
|
|
`ENSRegistry.methods.setOwner('${rootNode}', web3.eth.defaultAccount).send({from: web3.eth.defaultAccount}).then(() => {
|
|
|
|
ENSRegistry.methods.setResolver('${rootNode}', "$Resolver").send({from: web3.eth.defaultAccount});
|
2018-07-25 16:12:17 -04:00
|
|
|
var reverseNode = web3.utils.soliditySha3(web3.eth.defaultAccount.toLowerCase().substr(2) + '${reverseAddrSuffix}');
|
2018-08-22 18:32:43 -04:00
|
|
|
ENSRegistry.methods.setResolver(reverseNode, "$Resolver").send({from: web3.eth.defaultAccount});
|
|
|
|
Resolver.methods.setAddr('${rootNode}', web3.eth.defaultAccount).send({from: web3.eth.defaultAccount});
|
|
|
|
Resolver.methods.setName(reverseNode, '${this.registration.rootDomain}').send({from: web3.eth.defaultAccount});
|
2018-07-25 13:08:03 -04:00
|
|
|
})`
|
|
|
|
]
|
|
|
|
};
|
|
|
|
}
|
2018-08-22 18:32:43 -04:00
|
|
|
config.privatenet = config.development;
|
2018-07-25 13:08:03 -04:00
|
|
|
this.embark.registerContractConfiguration(config);
|
2018-07-25 13:08:03 -04:00
|
|
|
|
2018-08-22 18:32:43 -04:00
|
|
|
if (this.isDev || this.env === 'privatenet') {
|
|
|
|
this.embark.events.request("config:contractsFiles:add", this.embark.pathToFile('./contracts/ENSRegistry.sol'));
|
|
|
|
this.embark.events.request("config:contractsFiles:add", this.embark.pathToFile('./contracts/FIFSRegistrar.sol'));
|
|
|
|
this.embark.events.request("config:contractsFiles:add", this.embark.pathToFile('./contracts/Resolver.sol'));
|
|
|
|
}
|
2018-06-20 14:14:06 -05:00
|
|
|
}
|
|
|
|
|
2018-06-20 14:14:06 -05:00
|
|
|
configureRootRegistrar() {
|
|
|
|
const self = this;
|
|
|
|
let rootNode = namehash.hash(self.registration.rootDomain);
|
|
|
|
self.embark.registerContractConfiguration({
|
|
|
|
"default": {
|
|
|
|
"gas": "auto",
|
2018-06-21 13:24:41 -04:00
|
|
|
"contracts": {
|
|
|
|
"FIFSRegistrar": {
|
|
|
|
"deploy": true,
|
2018-07-25 11:05:27 -04:00
|
|
|
"args": ["$ENSRegistry", rootNode],
|
2018-07-13 12:37:34 -04:00
|
|
|
"onDeploy": [
|
|
|
|
`ENSRegistry.methods.setOwner('${rootNode}', web3.eth.defaultAccount).send().then(() => {
|
|
|
|
ENSRegistry.methods.setResolver('${rootNode}', "$Resolver").send();
|
2018-07-25 11:05:27 -04:00
|
|
|
var reverseNode = web3.utils.soliditySha3(web3.eth.defaultAccount.toLowerCase().substr(2) + '.addr.reverse');
|
2018-07-23 17:11:21 -04:00
|
|
|
ENSRegistry.methods.setResolver(reverseNode, "$Resolver").send();
|
2018-07-13 12:37:34 -04:00
|
|
|
Resolver.methods.setAddr('${rootNode}', web3.eth.defaultAccount).send();
|
2018-07-23 17:11:21 -04:00
|
|
|
Resolver.methods.setName(reverseNode, '${this.registration.rootDomain}').send();
|
2018-07-13 12:37:34 -04:00
|
|
|
})`
|
|
|
|
]
|
2018-06-21 13:24:41 -04:00
|
|
|
}
|
2018-06-20 14:14:06 -05:00
|
|
|
}
|
2018-06-21 12:57:41 -05:00
|
|
|
},
|
2018-06-26 13:32:53 -05:00
|
|
|
"ropsten": {
|
|
|
|
"contracts": {
|
2018-07-13 12:37:34 -04:00
|
|
|
"ENSRegistry": {
|
|
|
|
"address": "0x112234455c3a32fd11230c42e7bccd4a84e02010"
|
|
|
|
},
|
2018-07-25 13:08:03 -04:00
|
|
|
"Resolver": {
|
|
|
|
"deploy": false
|
|
|
|
},
|
2018-06-26 13:32:53 -05:00
|
|
|
"FIFSRegistrar": {
|
|
|
|
"deploy": false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"rinkeby": {
|
|
|
|
"contracts": {
|
2018-07-13 12:37:34 -04:00
|
|
|
"ENSRegistry": {
|
|
|
|
"address": "0xe7410170f87102DF0055eB195163A03B7F2Bff4A"
|
|
|
|
},
|
2018-07-25 13:08:03 -04:00
|
|
|
"Resolver": {
|
|
|
|
"deploy": false
|
|
|
|
},
|
2018-06-26 13:32:53 -05:00
|
|
|
"FIFSRegistrar": {
|
|
|
|
"deploy": false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"livenet": {
|
|
|
|
"contracts": {
|
2018-07-13 12:37:34 -04:00
|
|
|
"ENSRegistry": {
|
|
|
|
"address": "0x314159265dd8dbb310642f98f50c066173c1259b"
|
|
|
|
},
|
2018-07-25 13:08:03 -04:00
|
|
|
"Resolver": {
|
|
|
|
"deploy": false
|
|
|
|
},
|
2018-06-26 13:32:53 -05:00
|
|
|
"FIFSRegistrar": {
|
|
|
|
"deploy": false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-07-25 13:08:03 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
if (this.registration && this.registration.rootDomain) {
|
|
|
|
// Register root domain if it is defined
|
|
|
|
const rootNode = namehash.hash(this.registration.rootDomain);
|
|
|
|
config.development.contracts['FIFSRegistrar'] = {
|
|
|
|
"deploy": true,
|
|
|
|
"args": ["$ENSRegistry", rootNode],
|
|
|
|
"onDeploy": [
|
|
|
|
`ENSRegistry.methods.setOwner('${rootNode}', web3.eth.defaultAccount).send().then(() => {
|
|
|
|
ENSRegistry.methods.setResolver('${rootNode}', "$Resolver").send();
|
2018-07-25 16:12:17 -04:00
|
|
|
var reverseNode = web3.utils.soliditySha3(web3.eth.defaultAccount.toLowerCase().substr(2) + '${reverseAddrSuffix}');
|
2018-07-25 13:08:03 -04:00
|
|
|
ENSRegistry.methods.setResolver(reverseNode, "$Resolver").send();
|
|
|
|
Resolver.methods.setAddr('${rootNode}', web3.eth.defaultAccount).send();
|
|
|
|
Resolver.methods.setName(reverseNode, '${this.registration.rootDomain}').send();
|
|
|
|
})`
|
|
|
|
]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
this.embark.registerContractConfiguration(config);
|
2018-07-13 12:37:34 -04:00
|
|
|
|
|
|
|
this.embark.events.request("config:contractsFiles:add", this.embark.pathToFile('./contracts/ENSRegistry.sol'));
|
|
|
|
this.embark.events.request("config:contractsFiles:add", this.embark.pathToFile('./contracts/FIFSRegistrar.sol'));
|
|
|
|
this.embark.events.request("config:contractsFiles:add", this.embark.pathToFile('./contracts/Resolver.sol'));
|
2018-06-20 14:14:06 -05:00
|
|
|
}
|
|
|
|
|
2018-06-15 12:32:48 -05:00
|
|
|
addSetProvider(config) {
|
2018-06-18 12:52:02 -05:00
|
|
|
|
2018-06-18 12:43:52 -05:00
|
|
|
let code = "\nEmbarkJS.Names.setProvider('ens'," + JSON.stringify(config) + ");";
|
2018-05-23 10:24:53 -05:00
|
|
|
|
2018-05-23 13:00:34 -05:00
|
|
|
let shouldInit = (namesConfig) => {
|
|
|
|
return (namesConfig.provider === 'ens' && namesConfig.enabled === true);
|
2018-05-23 11:46:02 -05:00
|
|
|
};
|
2018-05-23 10:24:53 -05:00
|
|
|
|
2018-05-23 11:55:11 -05:00
|
|
|
this.embark.addProviderInit('names', code, shouldInit);
|
|
|
|
}
|
2018-05-23 10:24:53 -05:00
|
|
|
}
|
|
|
|
|
2018-05-23 12:13:06 -05:00
|
|
|
module.exports = ENS;
|