import { AccountRegistry } from '@src/assets/js/eth_account_index'; // @ts-ignore import * as accountIndex from '@src/assets/json/accountIndex.abi.json'; import {environment} from '@src/environments/environment'; const Web3 = require('web3'); const web3 = new Web3(environment.web3Provider); // @ts-ignore const abi = accountIndex.default; export class AccountIndex { contractAddress: string; signerAddress: string; contract: any; constructor(contractAddress: string, signerAddress?: string) { this.contractAddress = contractAddress; if (signerAddress) { this.signerAddress = signerAddress; } this.contract = new AccountRegistry(web3, abi, this.contractAddress, this.signerAddress); } async totalAccounts(): Promise { return await this.contract.count(); } async haveAccount(address: string): Promise { return await this.contract.have(address); } async addAccount(address: string): Promise { return await this.contract.add(address); } async last(numberOfAccounts: number): Promise> { return await this.contract.last(numberOfAccounts); } async addToAccountRegistry(address: string): Promise { if (!await this.contract.have(address)) { await this.contract.add(address); return await this.contract.have(address); } else { return await this.contract.have(address); } } }