2021-01-15 05:30:19 +01:00
|
|
|
import { AccountRegistry } from '../../assets/js/eth_account_index';
|
2021-02-06 15:08:37 +01:00
|
|
|
// @ts-ignore
|
2021-01-15 05:30:19 +01:00
|
|
|
import * as accountIndex from '../../assets/json/accountIndex.abi.json';
|
|
|
|
import {environment} from '../../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<number> {
|
|
|
|
return await this.contract.count();
|
|
|
|
}
|
|
|
|
|
|
|
|
async haveAccount(address: string): Promise<boolean> {
|
|
|
|
return await this.contract.have(address);
|
|
|
|
}
|
|
|
|
|
|
|
|
async addAccount(address: string): Promise<boolean> {
|
|
|
|
return await this.contract.add(address);
|
|
|
|
}
|
|
|
|
|
|
|
|
async last(numberOfAccounts: number): Promise<Array<string>> {
|
|
|
|
return await this.contract.last(numberOfAccounts);
|
|
|
|
}
|
|
|
|
|
|
|
|
async addToAccountRegistry(address: string): Promise<boolean> {
|
|
|
|
if (!await this.contract.have(address)) {
|
|
|
|
await this.contract.add(address);
|
|
|
|
return await this.contract.have(address);
|
|
|
|
} else {
|
|
|
|
return await this.contract.have(address);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|