import { Injectable } from '@angular/core';
import Web3 from 'web3';
import { environment } from '@src/environments/environment';
import { CICRegistry, FileGetter } from 'cic-client';
import { HttpGetter } from '@app/_helpers';

@Injectable({
  providedIn: 'root',
})
export class RegistryService {
  web3: Web3 = new Web3(environment.web3Provider);
  fileGetter: FileGetter = new HttpGetter();
  registry: CICRegistry = new CICRegistry(
    this.web3,
    environment.registryAddress,
    'Registry',
    this.fileGetter,
    ['../../assets/js/block-sync/data']
  );

  constructor() {
    this.registry.declaratorHelper.addTrust(environment.trustedDeclaratorAddress);
    this.registry.load();
  }

  getRegistry(): any {
    return this.registry;
  }

  getWeb3(): any {
    return this.web3;
  }
}
