added account registry to registries
This commit is contained in:
parent
df395b7b61
commit
8c9eb4a6a3
@ -1,7 +1,8 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
|
||||
import { environment } from '@src/environments/environment';
|
||||
import { CICRegistry, FileGetter } from '@cicnet/cic-client';
|
||||
import { TokenRegistry } from '@app/_eth';
|
||||
import { TokenRegistry, AccountIndex } from '@app/_eth';
|
||||
import { HttpGetter } from '@app/_helpers';
|
||||
import { Web3Service } from '@app/_services/web3.service';
|
||||
|
||||
@ -12,43 +13,59 @@ import { Web3Service } from '@app/_services/web3.service';
|
||||
//}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class RegistryService {
|
||||
static fileGetter: FileGetter = new HttpGetter();
|
||||
private static registry: CICRegistry;
|
||||
private static tokenRegistry: TokenRegistry;
|
||||
//private static registries: RegistryCollection;
|
||||
static fileGetter: FileGetter = new HttpGetter();
|
||||
private static registry: CICRegistry;
|
||||
private static tokenRegistry: TokenRegistry;
|
||||
private static accountRegistry: AccountIndex;
|
||||
//private static registries: RegistryCollection;
|
||||
|
||||
public static async getRegistry(): Promise<CICRegistry> {
|
||||
if (!RegistryService.registry) {
|
||||
RegistryService.registry = new CICRegistry(
|
||||
Web3Service.getInstance(),
|
||||
environment.registryAddress,
|
||||
'Registry',
|
||||
RegistryService.fileGetter,
|
||||
['../../assets/js/block-sync/data']
|
||||
);
|
||||
RegistryService.registry.declaratorHelper.addTrust(environment.trustedDeclaratorAddress);
|
||||
await RegistryService.registry.load()
|
||||
public static async getRegistry(): Promise<CICRegistry> {
|
||||
if (!RegistryService.registry) {
|
||||
RegistryService.registry = new CICRegistry(
|
||||
Web3Service.getInstance(),
|
||||
environment.registryAddress,
|
||||
'Registry',
|
||||
RegistryService.fileGetter,
|
||||
['../../assets/js/block-sync/data']
|
||||
);
|
||||
RegistryService.registry.declaratorHelper.addTrust(environment.trustedDeclaratorAddress);
|
||||
await RegistryService.registry.load()
|
||||
|
||||
}
|
||||
return RegistryService.registry;
|
||||
}
|
||||
return RegistryService.registry;
|
||||
}
|
||||
|
||||
public static async getTokenRegistry(): Promise<TokenRegistry> {
|
||||
if (!RegistryService.tokenRegistry) {
|
||||
//then initial it
|
||||
const registry = await RegistryService.getRegistry()
|
||||
const tokenRegistryAddress = await RegistryService.registry.getContractAddressByName('TokenRegistry')
|
||||
RegistryService.tokenRegistry = new TokenRegistry(tokenRegistryAddress);
|
||||
return new Promise((resolve, reject) => {
|
||||
resolve(RegistryService.tokenRegistry)
|
||||
})
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
resolve(RegistryService.tokenRegistry);
|
||||
})
|
||||
}
|
||||
public static async getTokenRegistry(): Promise<TokenRegistry> {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
if (!RegistryService.tokenRegistry) {
|
||||
const registry = await RegistryService.getRegistry()
|
||||
const tokenRegistryAddress = await RegistryService.registry.getContractAddressByName('TokenRegistry')
|
||||
if (!tokenRegistryAddress) {
|
||||
return reject("Unable to initialize Token Registry")
|
||||
}
|
||||
RegistryService.tokenRegistry = new TokenRegistry(tokenRegistryAddress);
|
||||
return 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);
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -179,14 +179,21 @@ export class UserService {
|
||||
|
||||
async loadAccounts(limit: number = 100, offset: number = 0): Promise<void> {
|
||||
this.resetAccountsList();
|
||||
const accountIndexAddress: string = await this.registry.getContractAddressByName(
|
||||
'AccountRegistry'
|
||||
);
|
||||
const accountIndexQuery = new AccountIndex(accountIndexAddress);
|
||||
const accountAddresses: Array<string> = await accountIndexQuery.last(limit);
|
||||
this.loggingService.sendInfoLevelMessage(accountAddresses);
|
||||
for (const accountAddress of accountAddresses.slice(offset, offset + limit)) {
|
||||
await this.getAccountByAddress(accountAddress, limit);
|
||||
//const accountIndexAddress: string = await this.registry.getContractAddressByName(
|
||||
// 'AccountRegistry'
|
||||
//);
|
||||
//const accountIndexQuery = new AccountIndex(accountIndexAddress);
|
||||
//const accountAddresses: Array<string> = await accountIndexQuery.last(limit);
|
||||
try{
|
||||
const accountRegistry = await RegistryService.getAccountRegistry();
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user