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-05-23 14:58:18 +00:00
|
|
|
|
|
|
|
class ENS {
|
2018-05-23 16:46:02 +00:00
|
|
|
constructor(embark, options) {
|
|
|
|
this.logger = embark.logger;
|
|
|
|
this.events = embark.events;
|
|
|
|
this.web3 = options.web3;
|
|
|
|
this.embark = embark;
|
|
|
|
|
|
|
|
this.addENSToEmbarkJS();
|
|
|
|
this.addSetProvider();
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
self.events.request("version:get:eth-ens-namehash", function(namehashVersion) {
|
|
|
|
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-05-23 16:55:11 +00:00
|
|
|
addSetProvider() {
|
2018-05-23 16:46:02 +00:00
|
|
|
let config = JSON.stringify({
|
|
|
|
server: this.storageConfig.host,
|
|
|
|
port: this.storageConfig.port
|
|
|
|
});
|
2018-05-23 15:24:53 +00:00
|
|
|
|
2018-05-23 16:46:02 +00:00
|
|
|
let code = "\nEmbarkJS.Names.setProvider('ens'," + config + ");";
|
2018-05-23 15:24:53 +00:00
|
|
|
|
2018-05-23 16:46:02 +00:00
|
|
|
let shouldInit = (storageConfig) => {
|
|
|
|
return (namesConfig.provider === 'ens' && storageConfig.enabled === true);
|
|
|
|
};
|
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
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = ENS;
|