added account registry to registries

This commit is contained in:
Blair Vanderlugt 2021-06-12 09:57:30 -07:00
parent df395b7b61
commit 8c9eb4a6a3
2 changed files with 65 additions and 41 deletions

View File

@ -1,7 +1,8 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { environment } from '@src/environments/environment'; import { environment } from '@src/environments/environment';
import { CICRegistry, FileGetter } from '@cicnet/cic-client'; import { CICRegistry, FileGetter } from '@cicnet/cic-client';
import { TokenRegistry } from '@app/_eth'; import { TokenRegistry, AccountIndex } from '@app/_eth';
import { HttpGetter } from '@app/_helpers'; import { HttpGetter } from '@app/_helpers';
import { Web3Service } from '@app/_services/web3.service'; import { Web3Service } from '@app/_services/web3.service';
@ -12,43 +13,59 @@ import { Web3Service } from '@app/_services/web3.service';
//} //}
@Injectable({ @Injectable({
providedIn: 'root', providedIn: 'root',
}) })
export class RegistryService { export class RegistryService {
static fileGetter: FileGetter = new HttpGetter(); static fileGetter: FileGetter = new HttpGetter();
private static registry: CICRegistry; private static registry: CICRegistry;
private static tokenRegistry: TokenRegistry; private static tokenRegistry: TokenRegistry;
//private static registries: RegistryCollection; private static accountRegistry: AccountIndex;
//private static registries: RegistryCollection;
public static async getRegistry(): Promise<CICRegistry> { public static async getRegistry(): Promise<CICRegistry> {
if (!RegistryService.registry) { if (!RegistryService.registry) {
RegistryService.registry = new CICRegistry( RegistryService.registry = new CICRegistry(
Web3Service.getInstance(), Web3Service.getInstance(),
environment.registryAddress, environment.registryAddress,
'Registry', 'Registry',
RegistryService.fileGetter, RegistryService.fileGetter,
['../../assets/js/block-sync/data'] ['../../assets/js/block-sync/data']
); );
RegistryService.registry.declaratorHelper.addTrust(environment.trustedDeclaratorAddress); RegistryService.registry.declaratorHelper.addTrust(environment.trustedDeclaratorAddress);
await RegistryService.registry.load() await RegistryService.registry.load()
}
return RegistryService.registry;
} }
return RegistryService.registry;
}
public static async getTokenRegistry(): Promise<TokenRegistry> { public static async getTokenRegistry(): Promise<TokenRegistry> {
if (!RegistryService.tokenRegistry) { return new Promise(async (resolve, reject) => {
//then initial it if (!RegistryService.tokenRegistry) {
const registry = await RegistryService.getRegistry() const registry = await RegistryService.getRegistry()
const tokenRegistryAddress = await RegistryService.registry.getContractAddressByName('TokenRegistry') const tokenRegistryAddress = await RegistryService.registry.getContractAddressByName('TokenRegistry')
RegistryService.tokenRegistry = new TokenRegistry(tokenRegistryAddress); if (!tokenRegistryAddress) {
return new Promise((resolve, reject) => { return reject("Unable to initialize Token Registry")
resolve(RegistryService.tokenRegistry) }
}) RegistryService.tokenRegistry = new TokenRegistry(tokenRegistryAddress);
} return resolve(RegistryService.tokenRegistry)
return new Promise((resolve, reject) => { }
resolve(RegistryService.tokenRegistry); return resolve(RegistryService.tokenRegistry);
}) })
} }
public static async getAccountRegistry(): Promise<AccountIndex> {
return new Promise(async (resolve, reject) => {
if (!RegistryService.accountRegistry) {
const registry = await RegistryService.getRegistry()
const accountRegistryAddress = await RegistryService.registry.getContractAddressByName('AccountRegistry')
if (!accountRegistryAddress) {
return reject("Unable to initialize Account Registry")
}
RegistryService.accountRegistry = new AccountIndex(accountRegistryAddress);
return resolve(RegistryService.accountRegistry)
}
return resolve(RegistryService.accountRegistry);
})
}
} }

View File

@ -179,14 +179,21 @@ export class UserService {
async loadAccounts(limit: number = 100, offset: number = 0): Promise<void> { async loadAccounts(limit: number = 100, offset: number = 0): Promise<void> {
this.resetAccountsList(); this.resetAccountsList();
const accountIndexAddress: string = await this.registry.getContractAddressByName( //const accountIndexAddress: string = await this.registry.getContractAddressByName(
'AccountRegistry' // 'AccountRegistry'
); //);
const accountIndexQuery = new AccountIndex(accountIndexAddress); //const accountIndexQuery = new AccountIndex(accountIndexAddress);
const accountAddresses: Array<string> = await accountIndexQuery.last(limit); //const accountAddresses: Array<string> = await accountIndexQuery.last(limit);
this.loggingService.sendInfoLevelMessage(accountAddresses); try{
for (const accountAddress of accountAddresses.slice(offset, offset + limit)) { const accountRegistry = await RegistryService.getAccountRegistry();
await this.getAccountByAddress(accountAddress, limit); const accountAddresses: Array<string> = await accountRegistry.last(limit);
this.loggingService.sendInfoLevelMessage(accountAddresses);
for (const accountAddress of accountAddresses.slice(offset, offset + limit)) {
await this.getAccountByAddress(accountAddress, limit);
}
} catch (error) {
this.loggingService.sendErrorLevelMessage("Unable to load accounts.", "user.service", error)
throw error
} }
} }