Add support for account index.
This commit is contained in:
47
src/app/_helpers/accountIndex.ts
Normal file
47
src/app/_helpers/accountIndex.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
34
src/app/_helpers/http-getter.ts
Normal file
34
src/app/_helpers/http-getter.ts
Normal 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
|
||||
// };
|
||||
@@ -1,2 +1,6 @@
|
||||
export * from './mock-backend';
|
||||
export * from './array-sum';
|
||||
export * from './accountIndex';
|
||||
export {AccountIndex} from './accountIndex';
|
||||
export * from './http-getter';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user