{"size": 886, "ext": "js", "max_stars_repo_path": "universal-login-example/src/services/EnsService.js", "max_stars_repo_name": "BoomerangProject/boomerang2.0", "max_stars_repo_stars_event_min_datetime": "2018-08-02T12:30:51.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-01T15:24:22.000Z", "max_issues_repo_path": "universal-login-example/src/services/EnsService.js", "max_issues_repo_name": "BoomerangProject/boomerang2.0", "max_issues_repo_issues_event_min_datetime": "2018-10-21T06:38:07.000Z", "max_issues_repo_issues_event_max_datetime": "2018-11-10T20:39:49.000Z", "max_forks_repo_path": "universal-login-example/src/services/EnsService.js", "max_forks_repo_name": "BoomerangProject/boomerang2.0", "max_forks_repo_forks_event_min_datetime": "2018-12-27T02:41:53.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-02T08:32:13.000Z"}
{"max_stars_count": 9, "max_issues_count": 12, "max_forks_count": 5, "avg_line_length": 28.5806451613, "max_line_length": 153, "alphanum_fraction": 0.7325056433}
import ethers, {utils} from 'ethers';
import PublicResolver from '../../abi/PublicResolver';

const {namehash} = utils;

class EnsService {
  constructor(sdk, provider) {
    this.sdk = sdk;
    this.provider = provider;
  }

  async getPublicResolverAddress() {
    this.relayerConfig = this.relayerConfig || await this.getEnsConfig();
    this.publicResolverAddress = this.relayerConfig.config.publicResolverAddress;
    return this.publicResolverAddress;
  }


  async getEnsConfig() {
    return await this.sdk.getRelayerConfig();
  }

  async getEnsName(address) {
    const node = namehash(`${address.slice(2)}.addr.reverse`.toLowerCase());
    this.resolverContract = this.resolverContract || new ethers.Contract(await this.getPublicResolverAddress(), PublicResolver.interface, this.provider);
    return await this.resolverContract.name(node);
  }
}

export default EnsService;
