added account registry to registries
This commit is contained in:
parent
df395b7b61
commit
8c9eb4a6a3
@ -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';
|
||||||
|
|
||||||
@ -18,6 +19,7 @@ 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 accountRegistry: AccountIndex;
|
||||||
//private static registries: RegistryCollection;
|
//private static registries: RegistryCollection;
|
||||||
|
|
||||||
public static async getRegistry(): Promise<CICRegistry> {
|
public static async getRegistry(): Promise<CICRegistry> {
|
||||||
@ -37,17 +39,32 @@ export class RegistryService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static async getTokenRegistry(): Promise<TokenRegistry> {
|
public static async getTokenRegistry(): Promise<TokenRegistry> {
|
||||||
|
return new Promise(async (resolve, reject) => {
|
||||||
if (!RegistryService.tokenRegistry) {
|
if (!RegistryService.tokenRegistry) {
|
||||||
//then initial it
|
|
||||||
const registry = await RegistryService.getRegistry()
|
const registry = await RegistryService.getRegistry()
|
||||||
const tokenRegistryAddress = await RegistryService.registry.getContractAddressByName('TokenRegistry')
|
const tokenRegistryAddress = await RegistryService.registry.getContractAddressByName('TokenRegistry')
|
||||||
|
if (!tokenRegistryAddress) {
|
||||||
|
return reject("Unable to initialize Token Registry")
|
||||||
|
}
|
||||||
RegistryService.tokenRegistry = new TokenRegistry(tokenRegistryAddress);
|
RegistryService.tokenRegistry = new TokenRegistry(tokenRegistryAddress);
|
||||||
return new Promise((resolve, reject) => {
|
return resolve(RegistryService.tokenRegistry)
|
||||||
resolve(RegistryService.tokenRegistry)
|
}
|
||||||
|
return resolve(RegistryService.tokenRegistry);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
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,15 +179,22 @@ 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);
|
||||||
|
try{
|
||||||
|
const accountRegistry = await RegistryService.getAccountRegistry();
|
||||||
|
const accountAddresses: Array<string> = await accountRegistry.last(limit);
|
||||||
this.loggingService.sendInfoLevelMessage(accountAddresses);
|
this.loggingService.sendInfoLevelMessage(accountAddresses);
|
||||||
for (const accountAddress of accountAddresses.slice(offset, offset + limit)) {
|
for (const accountAddress of accountAddresses.slice(offset, offset + limit)) {
|
||||||
await this.getAccountByAddress(accountAddress, limit);
|
await this.getAccountByAddress(accountAddress, limit);
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
this.loggingService.sendErrorLevelMessage("Unable to load accounts.", "user.service", error)
|
||||||
|
throw error
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getAccountByAddress(
|
async getAccountByAddress(
|
||||||
|
Loading…
Reference in New Issue
Block a user