eth-accounts-index/js/src/registry.ts

40 lines
814 B
TypeScript
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

class AccountRegistry {
contract: any
constructor(w3:any, abi:object, address:string) {
this.contract = new w3.eth.Contract(abi, address);
}
public async count(): Promise<number> {
return this.contract.methods.count().call();
}
public async have(address:string): Promise<boolean> {
return await this.contract.methods.accountsIndex(address).call() != 0;
}
public async last(n:number): Promise<Array<string>> {
const c = await this.count();
let lo = c - n - 1;
if (lo < 0) {
lo = 0;
}
let accounts = [];
for (let i = c - 1; i > lo; i--) {
console.log('i', i);
console.log('foo', i, await this.contract.methods.accounts(i).call());
const a = await this.contract.methods.accounts(i).call();
accounts.push(a);
}
return accounts;
}
}
export {
AccountRegistry,
}