2018-05-23 14:58:18 +00:00
|
|
|
const fs = require('../../core/fs.js');
|
2018-05-23 15:24:53 +00:00
|
|
|
const utils = require('../../utils/utils.js');
|
2018-06-20 19:14:06 +00:00
|
|
|
const namehash = require('eth-ens-namehash');
|
2018-05-23 14:58:18 +00:00
|
|
|
|
|
|
|
class ENS {
|
2018-05-30 16:26:49 +00:00
|
|
|
constructor(embark, _options) {
|
2018-06-15 17:32:48 +00:00
|
|
|
const self = this;
|
2018-05-23 16:46:02 +00:00
|
|
|
this.logger = embark.logger;
|
|
|
|
this.events = embark.events;
|
2018-05-30 16:26:49 +00:00
|
|
|
this.namesConfig = embark.config.namesystemConfig;
|
2018-06-20 19:14:06 +00:00
|
|
|
this.registration = this.namesConfig.register;
|
2018-05-23 16:46:02 +00:00
|
|
|
this.embark = embark;
|
|
|
|
|
|
|
|
this.addENSToEmbarkJS();
|
2018-06-18 15:45:20 +00:00
|
|
|
this.configureENSRegistry();
|
2018-06-20 19:14:06 +00:00
|
|
|
this.configureRootRegistrar();
|
|
|
|
|
2018-06-18 15:45:20 +00:00
|
|
|
self.embark.registerActionForEvent("contracts:deploy:afterAll", (cb) => {
|
|
|
|
self.events.request('contracts:contract', "ENSRegistry", (contract) => {
|
2018-06-18 15:58:42 +00:00
|
|
|
let config = {
|
2018-06-18 15:45:20 +00:00
|
|
|
abi: contract.abiDefinition,
|
|
|
|
address: contract.deployedAddress
|
2018-06-18 15:58:42 +00:00
|
|
|
};
|
|
|
|
self.addSetProvider(config);
|
2018-06-18 19:31:22 +00:00
|
|
|
cb();
|
2018-06-15 17:32:48 +00:00
|
|
|
});
|
|
|
|
});
|
2018-05-23 17:13:06 +00:00
|
|
|
}
|
2018-05-23 15:24:53 +00:00
|
|
|
|
2018-05-23 16:46:02 +00:00
|
|
|
addENSToEmbarkJS() {
|
|
|
|
const self = this;
|
|
|
|
// TODO: make this a shouldAdd condition
|
|
|
|
if (this.namesConfig === {}) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((this.namesConfig.available_providers.indexOf('ens') < 0) && (this.namesConfig.provider !== 'ens' || this.namesConfig.enabled !== true)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-06-15 15:23:55 +00:00
|
|
|
// get namehash, import it into file
|
2018-05-23 17:13:06 +00:00
|
|
|
self.events.request("version:get:eth-ens-namehash", function(EnsNamehashVersion) {
|
2018-05-23 16:46:02 +00:00
|
|
|
let currentEnsNamehashVersion = require('../../../package.json').dependencies["eth-ens-namehash"];
|
|
|
|
if (EnsNamehashVersion !== currentEnsNamehashVersion) {
|
|
|
|
self.events.request("version:getPackageLocation", "eth-ens-namehash", EnsNamehashVersion, function(err, location) {
|
|
|
|
self.embark.registerImportFile("eth-ens-namehash", fs.dappPath(location));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
let code = "";
|
|
|
|
code += "\n" + fs.readFileSync(utils.joinPath(__dirname, 'embarkjs.js')).toString();
|
|
|
|
code += "\nEmbarkJS.Names.registerProvider('ens', __embarkENS);";
|
|
|
|
|
|
|
|
this.embark.addCodeToEmbarkJS(code);
|
2018-05-23 16:55:11 +00:00
|
|
|
}
|
2018-05-23 15:24:53 +00:00
|
|
|
|
2018-06-18 15:45:20 +00:00
|
|
|
configureENSRegistry() {
|
2018-06-15 15:23:55 +00:00
|
|
|
const self = this;
|
2018-06-20 19:14:06 +00:00
|
|
|
|
2018-06-15 15:23:55 +00:00
|
|
|
self.embark.registerContractConfiguration({
|
|
|
|
"default": {
|
|
|
|
"gas": "auto",
|
2018-06-21 17:24:41 +00:00
|
|
|
"contracts": {
|
|
|
|
"ENSRegistry": {
|
|
|
|
"deploy": true,
|
|
|
|
"args": []
|
|
|
|
}
|
2018-06-15 15:23:55 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
"ropsten": {
|
2018-06-21 17:24:41 +00:00
|
|
|
"contracts": {
|
|
|
|
"ENSRegistry": {
|
|
|
|
"address": "0x112234455c3a32fd11230c42e7bccd4a84e02010"
|
|
|
|
}
|
2018-06-15 15:23:55 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
"rinkeby": {
|
2018-06-21 17:24:41 +00:00
|
|
|
"contracts": {
|
|
|
|
"ENSRegistry": {
|
|
|
|
"address": "0xe7410170f87102DF0055eB195163A03B7F2Bff4A"
|
|
|
|
}
|
2018-06-15 15:23:55 +00:00
|
|
|
}
|
|
|
|
},
|
2018-06-18 15:45:20 +00:00
|
|
|
"livenet": {
|
2018-06-21 17:24:41 +00:00
|
|
|
"contracts": {
|
|
|
|
"ENSRegistry": {
|
|
|
|
"address": "0x314159265dd8dbb310642f98f50c066173c1259b"
|
|
|
|
}
|
2018-06-15 15:23:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2018-06-20 19:14:06 +00:00
|
|
|
|
2018-06-18 15:58:42 +00:00
|
|
|
self.embark.events.request("config:contractsFiles:add", self.embark.pathToFile('./contracts/ENSRegistry.sol'));
|
2018-06-15 15:23:55 +00:00
|
|
|
}
|
|
|
|
|
2018-06-20 19:14:06 +00:00
|
|
|
configureRootRegistrar() {
|
|
|
|
const self = this;
|
|
|
|
let rootNode = namehash.hash(self.registration.rootDomain);
|
|
|
|
self.embark.registerContractConfiguration({
|
|
|
|
"default": {
|
|
|
|
"gas": "auto",
|
2018-06-21 17:24:41 +00:00
|
|
|
"contracts": {
|
|
|
|
"FIFSRegistrar": {
|
|
|
|
"deploy": true,
|
|
|
|
"args": ["$ENSRegistry", rootNode],
|
2018-07-12 20:31:00 +00:00
|
|
|
"onDeploy": ["ENSRegistry.methods.setOwner('"+rootNode+"', web3.eth.defaultAccount).send()"]
|
2018-06-21 17:24:41 +00:00
|
|
|
}
|
2018-06-20 19:14:06 +00:00
|
|
|
}
|
2018-06-21 17:57:41 +00:00
|
|
|
},
|
2018-06-26 18:32:53 +00:00
|
|
|
"ropsten": {
|
|
|
|
"contracts": {
|
|
|
|
"FIFSRegistrar": {
|
|
|
|
"deploy": false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"rinkeby": {
|
|
|
|
"contracts": {
|
|
|
|
"FIFSRegistrar": {
|
|
|
|
"deploy": false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"livenet": {
|
|
|
|
"contracts": {
|
|
|
|
"FIFSRegistrar": {
|
|
|
|
"deploy": false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-06-20 19:14:06 +00:00
|
|
|
});
|
|
|
|
self.embark.events.request("config:contractsFiles:add", self.embark.pathToFile('./contracts/FIFSRegistrar.sol'));
|
|
|
|
}
|
|
|
|
|
2018-06-15 17:32:48 +00:00
|
|
|
addSetProvider(config) {
|
2018-06-18 17:52:02 +00:00
|
|
|
|
2018-06-18 17:43:52 +00:00
|
|
|
let code = "\nEmbarkJS.Names.setProvider('ens'," + JSON.stringify(config) + ");";
|
2018-05-23 15:24:53 +00:00
|
|
|
|
2018-05-23 18:00:34 +00:00
|
|
|
let shouldInit = (namesConfig) => {
|
|
|
|
return (namesConfig.provider === 'ens' && namesConfig.enabled === true);
|
2018-05-23 16:46:02 +00:00
|
|
|
};
|
2018-05-23 15:24:53 +00:00
|
|
|
|
2018-05-23 16:55:11 +00:00
|
|
|
this.embark.addProviderInit('names', code, shouldInit);
|
|
|
|
}
|
2018-05-23 15:24:53 +00:00
|
|
|
}
|
|
|
|
|
2018-05-23 17:13:06 +00:00
|
|
|
module.exports = ENS;
|