eth-accounts-index

Accounts index evm contract tooling with permissioned writes
Info | Log | Files | Refs

registry.ts (814B)


      1 class AccountRegistry {
      2 
      3 	contract:	any
      4 
      5 	constructor(w3:any, abi:object, address:string) {
      6 		this.contract = new w3.eth.Contract(abi, address);
      7 	}
      8 
      9 
     10 	public async count(): Promise<number> {
     11 		return this.contract.methods.count().call();
     12 	}
     13 
     14 
     15 	public async have(address:string): Promise<boolean> { 
     16 		return await this.contract.methods.accountsIndex(address).call() != 0;
     17 	}
     18 
     19 
     20 	public async last(n:number): Promise<Array<string>> {
     21 		const c = await this.count();
     22 		let lo = c - n - 1;
     23 		if (lo < 0) {
     24 			lo = 0;
     25 		}
     26 		let accounts = [];
     27 		for (let i = c - 1; i > lo; i--) {
     28 			console.log('i', i);
     29 			console.log('foo', i, await this.contract.methods.accounts(i).call());
     30 			const a = await this.contract.methods.accounts(i).call();
     31 			accounts.push(a);
     32 		}
     33 		return accounts;
     34 	}
     35 }
     36 
     37 export {
     38 	AccountRegistry,
     39 }