Retire internal registry class.
This commit is contained in:
parent
23b213e319
commit
1223ccc48e
@ -1,3 +1,2 @@
|
||||
export * from '@app/_eth/accountIndex';
|
||||
export * from '@app/_eth/registry';
|
||||
export * from '@app/_eth/token-registry';
|
||||
|
@ -1,8 +0,0 @@
|
||||
import { Registry } from '@app/_eth/registry';
|
||||
import {environment} from '@src/environments/environment';
|
||||
|
||||
describe('Registry', () => {
|
||||
it('should create an instance', () => {
|
||||
expect(new Registry(environment.registryAddress)).toBeTruthy();
|
||||
});
|
||||
});
|
@ -1,32 +0,0 @@
|
||||
// @ts-ignore
|
||||
import * as registry from '@src/assets/js/block-sync/data/Registry.json';
|
||||
import {environment} from '@src/environments/environment';
|
||||
const Web3 = require('web3');
|
||||
|
||||
const web3 = new Web3(environment.web3Provider);
|
||||
const abi = registry.default;
|
||||
|
||||
export class Registry {
|
||||
contractAddress: string;
|
||||
signerAddress: string;
|
||||
contract: any;
|
||||
|
||||
constructor(contractAddress: string, signerAddress?: string) {
|
||||
this.contractAddress = contractAddress;
|
||||
this.contract = new web3.eth.Contract(abi, contractAddress);
|
||||
if (signerAddress) {
|
||||
this.signerAddress = signerAddress;
|
||||
} else {
|
||||
this.signerAddress = web3.eth.accounts[0];
|
||||
}
|
||||
}
|
||||
|
||||
public async owner(): Promise<string> {
|
||||
return await this.contract.methods.owner().call();
|
||||
}
|
||||
|
||||
public async addressOf(identifier: string): Promise<string> {
|
||||
const id = '0x' + web3.utils.padRight(new Buffer(identifier).toString('hex'), 64);
|
||||
return await this.contract.methods.addressOf(id).call();
|
||||
}
|
||||
}
|
@ -1,12 +1,11 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {Settings} from '@app/_models';
|
||||
import Web3 from 'web3';
|
||||
import {CICRegistry, TransactionHelper} from 'cic-client';
|
||||
import {TransactionHelper} from 'cic-client';
|
||||
import {first} from 'rxjs/operators';
|
||||
import {TransactionService} from '@app/_services/transaction.service';
|
||||
import {environment} from '@src/environments/environment';
|
||||
import {HttpGetter} from '@app/_helpers';
|
||||
import {LoggingService} from '@app/_services/logging.service';
|
||||
import {RegistryService} from '@app/_services/registry.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@ -14,23 +13,20 @@ import {LoggingService} from '@app/_services/logging.service';
|
||||
export class BlockSyncService {
|
||||
readyStateTarget: number = 2;
|
||||
readyState: number = 0;
|
||||
fileGetter = new HttpGetter();
|
||||
|
||||
constructor(
|
||||
private transactionService: TransactionService,
|
||||
private loggingService: LoggingService
|
||||
private loggingService: LoggingService,
|
||||
private registryService: RegistryService,
|
||||
) { }
|
||||
|
||||
blockSync(address: string = null, offset: number = 0, limit: number = 100): any {
|
||||
this.transactionService.resetTransactionsList();
|
||||
const settings = new Settings(this.scan);
|
||||
const provider = environment.web3Provider;
|
||||
const readyStateElements = { network: 2 };
|
||||
settings.w3.provider = provider;
|
||||
settings.w3.engine = new Web3(provider);
|
||||
settings.registry = new CICRegistry(settings.w3.engine, environment.registryAddress, this.fileGetter,
|
||||
['../../assets/js/block-sync/data']);
|
||||
settings.registry.declaratorHelper.addTrust(environment.trustedDeclaratorAddress);
|
||||
settings.w3.provider = environment.web3Provider;
|
||||
settings.w3.engine = this.registryService.getWeb3();
|
||||
settings.registry = this.registryService.getRegistry();
|
||||
settings.txHelper = new TransactionHelper(settings.w3.engine, settings.registry);
|
||||
|
||||
settings.txHelper.ontransfer = async (transaction: any): Promise<void> => {
|
||||
|
16
src/app/_services/registry.service.spec.ts
Normal file
16
src/app/_services/registry.service.spec.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { RegistryService } from './registry.service';
|
||||
|
||||
describe('RegistryService', () => {
|
||||
let service: RegistryService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(RegistryService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
28
src/app/_services/registry.service.ts
Normal file
28
src/app/_services/registry.service.ts
Normal file
@ -0,0 +1,28 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import Web3 from 'web3';
|
||||
import {environment} from '@src/environments/environment';
|
||||
import {CICRegistry} from 'cic-client';
|
||||
import {HttpGetter} from '@app/_helpers';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class RegistryService {
|
||||
web3 = new Web3(environment.web3Provider);
|
||||
fileGetter = new HttpGetter();
|
||||
registry = new CICRegistry(this.web3, environment.registryAddress, 'CICRegistry', this.fileGetter,
|
||||
['../../assets/js/block-sync/data']);
|
||||
|
||||
constructor() {
|
||||
this.registry.declaratorHelper.addTrust(environment.trustedDeclaratorAddress);
|
||||
this.registry.load();
|
||||
}
|
||||
|
||||
getRegistry(): any {
|
||||
return this.registry;
|
||||
}
|
||||
|
||||
getWeb3(): any {
|
||||
return this.web3;
|
||||
}
|
||||
}
|
@ -1,32 +1,35 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import {environment} from '@src/environments/environment';
|
||||
import {BehaviorSubject, Observable} from 'rxjs';
|
||||
import {HttpGetter} from '@app/_helpers';
|
||||
import {CICRegistry} from 'cic-client';
|
||||
import Web3 from 'web3';
|
||||
import {Registry, TokenRegistry} from '@app/_eth';
|
||||
import {TokenRegistry} from '@app/_eth';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {RegistryService} from '@app/_services/registry.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class TokenService {
|
||||
web3 = new Web3(environment.web3Provider);
|
||||
fileGetter = new HttpGetter();
|
||||
registry = new Registry(environment.registryAddress);
|
||||
cicRegistry = new CICRegistry(this.web3, environment.registryAddress, this.fileGetter, ['../../assets/js/block-sync/data']);
|
||||
registry: CICRegistry;
|
||||
tokenRegistry: TokenRegistry;
|
||||
tokens: any = '';
|
||||
private tokensList = new BehaviorSubject<any>(this.tokens);
|
||||
tokensSubject = this.tokensList.asObservable();
|
||||
|
||||
constructor(
|
||||
private httpClient: HttpClient,
|
||||
) { }
|
||||
private registryService: RegistryService,
|
||||
) {
|
||||
this.registry = registryService.getRegistry();
|
||||
this.registry.load();
|
||||
this.registry.onload = async (address: string): Promise<void> => {
|
||||
this.tokenRegistry = new TokenRegistry(await this.registry.getContractAddressByName('TokenRegistry'));
|
||||
};
|
||||
}
|
||||
|
||||
async getTokens(): Promise<any> {
|
||||
const tokenRegistryQuery = new TokenRegistry(await this.registry.addressOf('TokenRegistry'));
|
||||
const count = await tokenRegistryQuery.totalTokens();
|
||||
return Array.from({length: count}, async (v, i) => await tokenRegistryQuery.entry(i));
|
||||
const count = await this.tokenRegistry.totalTokens();
|
||||
return Array.from({length: count}, async (v, i) => await this.tokenRegistry.entry(i));
|
||||
}
|
||||
|
||||
getTokenBySymbol(symbol: string): Observable<any> {
|
||||
@ -34,8 +37,7 @@ export class TokenService {
|
||||
}
|
||||
|
||||
async getTokenBalance(address: string): Promise<number> {
|
||||
const tokenRegistryQuery = new TokenRegistry(await this.registry.addressOf('TokenRegistry'));
|
||||
const sarafuToken = await this.cicRegistry.addToken(await tokenRegistryQuery.entry(0));
|
||||
const sarafuToken = await this.registry.addToken(await this.tokenRegistry.entry(0));
|
||||
return await sarafuToken.methods.balanceOf(address).call();
|
||||
}
|
||||
}
|
||||
|
@ -13,9 +13,9 @@ import * as secp256k1 from 'secp256k1';
|
||||
import {AuthService} from '@app/_services/auth.service';
|
||||
import {defaultAccount} from '@app/_models';
|
||||
import {LoggingService} from '@app/_services/logging.service';
|
||||
import {Registry} from '@app/_eth';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
const Web3 = require('web3');
|
||||
import {CICRegistry} from 'cic-client';
|
||||
import {RegistryService} from '@app/_services/registry.service';
|
||||
const vCard = require('vcard-parser');
|
||||
|
||||
@Injectable({
|
||||
@ -26,15 +26,20 @@ export class TransactionService {
|
||||
private transactionList = new BehaviorSubject<any[]>(this.transactions);
|
||||
transactionsSubject = this.transactionList.asObservable();
|
||||
userInfo: any;
|
||||
web3 = new Web3(environment.web3Provider);
|
||||
registry = new Registry(environment.registryAddress);
|
||||
web3: any;
|
||||
registry: CICRegistry;
|
||||
|
||||
constructor(
|
||||
private httpClient: HttpClient,
|
||||
private authService: AuthService,
|
||||
private userService: UserService,
|
||||
private loggingService: LoggingService
|
||||
) { }
|
||||
private loggingService: LoggingService,
|
||||
private registryService: RegistryService,
|
||||
) {
|
||||
this.web3 = this.registryService.getWeb3();
|
||||
this.registry = registryService.getRegistry();
|
||||
this.registry.load();
|
||||
}
|
||||
|
||||
getAllTransactions(offset: number, limit: number): Observable<any> {
|
||||
return this.httpClient.get(`${environment.cicCacheUrl}/tx/${offset}/${limit}`);
|
||||
@ -100,7 +105,7 @@ export class TransactionService {
|
||||
}
|
||||
|
||||
async transferRequest(tokenAddress: string, senderAddress: string, recipientAddress: string, value: number): Promise<any> {
|
||||
const transferAuthAddress = await this.registry.addressOf('TransferAuthorization');
|
||||
const transferAuthAddress = await this.registry.getContractAddressByName('TransferAuthorization');
|
||||
const hashFunction = new Keccak(256);
|
||||
hashFunction.update('createRequest(address,address,address,uint256)');
|
||||
const hash = hashFunction.digest();
|
||||
|
@ -7,8 +7,10 @@ import {ArgPair, Envelope, Phone, Syncable, User} from 'cic-client-meta';
|
||||
import {AccountDetails, MetaResponse} from '@app/_models';
|
||||
import {LoggingService} from '@app/_services/logging.service';
|
||||
import {TokenService} from '@app/_services/token.service';
|
||||
import {AccountIndex, Registry} from '@app/_eth';
|
||||
import {AccountIndex} from '@app/_eth';
|
||||
import {MutableKeyStore, MutablePgpKeyStore, PGPSigner, Signer} from '@app/_pgp';
|
||||
import {RegistryService} from '@app/_services/registry.service';
|
||||
import {CICRegistry} from 'cic-client';
|
||||
const vCard = require('vcard-parser');
|
||||
|
||||
@Injectable({
|
||||
@ -18,7 +20,7 @@ export class UserService {
|
||||
headers: HttpHeaders = new HttpHeaders({'x-cic-automerge': 'client'});
|
||||
keystore: MutableKeyStore = new MutablePgpKeyStore();
|
||||
signer: Signer = new PGPSigner(this.keystore);
|
||||
registry = new Registry(environment.registryAddress);
|
||||
registry: CICRegistry;
|
||||
|
||||
accountsMeta = [];
|
||||
accounts: any = [];
|
||||
@ -36,8 +38,11 @@ export class UserService {
|
||||
constructor(
|
||||
private httpClient: HttpClient,
|
||||
private loggingService: LoggingService,
|
||||
private tokenService: TokenService
|
||||
private tokenService: TokenService,
|
||||
private registryService: RegistryService,
|
||||
) {
|
||||
this.registry = registryService.getRegistry();
|
||||
this.registry.load();
|
||||
}
|
||||
|
||||
resetPin(phone: string): Observable<any> {
|
||||
@ -152,7 +157,7 @@ export class UserService {
|
||||
|
||||
async loadAccounts(limit: number = 100, offset: number = 0): Promise<void> {
|
||||
this.resetAccountsList();
|
||||
const accountIndexAddress = await this.registry.addressOf('AccountRegistry');
|
||||
const accountIndexAddress = await this.registry.getContractAddressByName('AccountRegistry');
|
||||
const accountIndexQuery = new AccountIndex(accountIndexAddress);
|
||||
const accountAddresses = await accountIndexQuery.last(await accountIndexQuery.totalAccounts());
|
||||
this.loggingService.sendInfoLevelMessage(accountAddresses);
|
||||
|
Loading…
Reference in New Issue
Block a user