Add support for account index.

This commit is contained in:
Spencer Ofwiti
2021-01-15 07:30:19 +03:00
parent f7f4fe77f6
commit 4d920cdbe9
31 changed files with 1117 additions and 17 deletions

View File

@@ -0,0 +1,47 @@
import { AccountRegistry } from '../../assets/js/eth_account_index';
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);
}
}
}

View File

@@ -0,0 +1,34 @@
// function httpGetter(): any {
// }
//
// httpGetter().prototype.get = (filename: string) => new Promise((whohoo, doh) => {
// const xhr = new XMLHttpRequest();
// xhr.addEventListener('load', (e) => {
// if (xhr.status === 200) {
// whohoo(xhr.responseText);
// return;
// }
// doh('failed with status ' + xhr.status + ': ' + xhr.statusText);
// });
// xhr.open('GET', filename);
// xhr.send();
// });
//
// class HttpGetter {
// async get(filename: string): Promise<any> {
// const xhr = new XMLHttpRequest();
// xhr.addEventListener('load', (e) => {
// if (xhr.status === 200) {
// // whohoo(xhr.responseText);
// return;
// }
// // doh('failed with status ' + xhr.status + ': ' + xhr.statusText);
// });
// xhr.open('GET', filename);
// xhr.send();
// }
// }
// export {
// httpGetter,
// HttpGetter
// };

View File

@@ -1,2 +1,6 @@
export * from './mock-backend';
export * from './array-sum';
export * from './accountIndex';
export {AccountIndex} from './accountIndex';
export * from './http-getter';