mirror of https://github.com/embarklabs/embark.git
58 lines
1.7 KiB
JavaScript
58 lines
1.7 KiB
JavaScript
const fs = require('../../core/fs.js');
|
|
const utils = require('../../utils/utils.js');
|
|
|
|
class ENS {
|
|
constructor(embark, options) {
|
|
this.logger = embark.logger;
|
|
this.events = embark.events;
|
|
this.web3 = options.web3;
|
|
this.embark = embark;
|
|
|
|
this.addENSToEmbarkJS();
|
|
this.addSetProvider();
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
addSetProvider() {
|
|
let config = JSON.stringify({
|
|
server: this.storageConfig.host,
|
|
port: this.storageConfig.port
|
|
});
|
|
|
|
let code = "\nEmbarkJS.Names.setProvider('ens'," + config + ");";
|
|
|
|
let shouldInit = (storageConfig) => {
|
|
return (namesConfig.provider === 'ens' && storageConfig.enabled === true);
|
|
};
|
|
|
|
this.embark.addProviderInit('names', code, shouldInit);
|
|
}
|
|
}
|
|
|
|
module.exports = ENS; |