- Refactor HttpGetter function.
- Remove redundant asset files.
- Fix BlockSync dependency issues.
This commit is contained in:
Spencer Ofwiti
2021-02-25 13:46:24 +03:00
parent 857994fe8b
commit fbdfa54d9b
27 changed files with 138 additions and 1346 deletions

View File

@@ -1,19 +1,18 @@
function HttpGetter(): void {}
HttpGetter.prototype.get = filename => new Promise((whohoo, doh) => {
const xhr = new XMLHttpRequest();
xhr.addEventListener('load', (e) => {
if (xhr.status === 200) {
whohoo(xhr.responseText);
return;
}
doh('failed with status ' + xhr.status + ': ' + xhr.statusText);
});
xhr.open('GET', filename);
xhr.send();
});
class HttpGetter {
async get(filename: string): Promise<any> {
const xhr = new XMLHttpRequest();
xhr.addEventListener('load', (e) => {
if (xhr.status === 200) {
console.log(xhr.responseText);
return;
}
console.log('failed with status ' + xhr.status + ': ' + xhr.statusText);
});
xhr.open('GET', filename);
xhr.send();
}
}
export {
HttpGetter
};

View File

@@ -7,4 +7,3 @@ export * from '@app/_helpers/array-sum';
export * from '@app/_helpers/accountIndex';
export * from '@app/_helpers/http-getter';
export * from '@app/_helpers/pgp-signer';

View File

@@ -1,6 +1,6 @@
import { KeyStore } from 'cic-client-meta';
const openpgp = require('openpgp');
const keyring = new openpgp.Keyring();
import { KeyStore } from '@src/assets/js/cic-meta/auth';
interface MutableKeyStore extends KeyStore {
loadKeyring(): Promise<void>;

View File

@@ -1,33 +1,32 @@
import {Injectable} from '@angular/core';
import {Settings} from '@app/_models';
import Web3 from 'web3';
import {abi, Registry, TransactionHelper} from 'cic-client';
import {CICRegistry, TransactionHelper} from 'cic-client';
import {first} from 'rxjs/operators';
import {TransactionService} from '@app/_services/transaction.service';
import {environment} from '@src/environments/environment';
const cic = require('@src/assets/js/block-sync/cic-client.web');
import {HttpGetter} from '@app/_helpers';
@Injectable({
providedIn: 'root'
})
export class BlockSyncService {
trustedDeclaratorAddress: string = '0x5567139c7a1C2977A391f51D8cA45B1D6700f5F6';
readyStateTarget: number = 2;
readyState: number = 0;
fileGetter = new HttpGetter();
constructor(private transactionService: TransactionService) { }
blockSync(): any {
const settings = new Settings(this.scan);
const provider = environment.web3Provider;
const readyStateElements = {
token: 1,
network: 2,
};
const readyStateElements = { network: 2 };
settings.w3.provider = provider;
settings.w3.engine = new Web3(provider);
settings.registry = new Registry(settings.w3.engine, environment.registryAddress, abi);
settings.txHelper = new TransactionHelper(settings.registry);
settings.registry = new CICRegistry(settings.w3.engine, environment.registryAddress, this.fileGetter,
['../../assets/js/block-sync/data']);
settings.registry.declaratorHelper.addTrust(environment.trustedDeclaratorAddress);
settings.txHelper = new TransactionHelper(settings.w3.engine, settings.registry);
settings.txHelper.ontransfer = async (transaction: any): Promise<void> => {
window.dispatchEvent(this.newTransferEvent(transaction));
@@ -35,12 +34,8 @@ export class BlockSyncService {
settings.txHelper.onconversion = async (transaction: any): Promise<any> => {
window.dispatchEvent(this.newConversionEvent(transaction));
};
settings.registry.ontokensload = (tokenCount: number): void => {
// console.debug('loaded tokens', tokenCount);
this.readyStateProcessor(settings, readyStateElements.token);
};
settings.registry.onregistryload = (addressReturned: number): void => {
// console.debug('loaded network contracts', addressReturned);
settings.registry.onload = (addressReturned: number): void => {
console.log('loaded network contracts', addressReturned);
this.readyStateProcessor(settings, readyStateElements.network);
};
@@ -79,7 +74,7 @@ export class BlockSyncService {
}
async scan(settings, lo, hi, bloomBlockBytes, bloomBlocktxBytes, bloomRounds): Promise<void> {
const w = new Worker('./../assets/js/worker.js');
const w = new Worker('./../assets/js/block-sync/ondemand.js');
w.onmessage = (m) => {
settings.txHelper.processReceipt(m.data);
};
@@ -114,14 +109,4 @@ export class BlockSyncService {
settings.scanFilter(settings, data.low, data.high, bOne, bTwo, data.filter_rounds);
});
}
headWorker(): void {
const wHeadSync = new Worker('./../assets/js/block-sync/head.js', {type: 'module'});
wHeadSync.onmessage = (m) => {
console.log(m.data);
};
wHeadSync.postMessage({
w3_provider: environment.web3Provider,
});
}
}

View File

@@ -3,9 +3,8 @@ import {BehaviorSubject, Observable} from 'rxjs';
import {HttpClient, HttpHeaders, HttpParams} from '@angular/common/http';
import {environment} from '@src/environments/environment';
import {first} from 'rxjs/operators';
import {ArgPair, Envelope, Syncable} from '@src/assets/js/cic-meta/sync.js';
import {MutableKeyStore, MutablePgpKeyStore, PGPSigner, Signer} from '@app/_helpers';
import {User} from 'cic-client-meta';
import {ArgPair, Envelope, Syncable, User} from 'cic-client-meta';
@Injectable({
providedIn: 'root'
@@ -64,8 +63,7 @@ export class UserService {
await this.updateMeta(syncableAccount, accountKey, this.headers);
}, async error => {
console.error('There is an error!', error);
const refName = accountKey + ':cic.person';
const syncableAccount: Syncable = new Syncable(refName, accountDetails);
const syncableAccount: Syncable = new Syncable(accountKey, accountDetails);
await this.updateMeta(syncableAccount, accountKey, this.headers);
});
return accountKey;

View File

@@ -26,7 +26,6 @@ export class AppComponent implements OnInit {
}
ngOnInit(): void {
this.blockSyncService.headWorker();
this.mediaQuery.addListener(this.onResize);
this.onResize(this.mediaQuery);
this.queryAccountsIndex(20).then();

View File

@@ -8,8 +8,7 @@ import {ActivatedRoute, Params, Router} from '@angular/router';
import {first} from 'rxjs/operators';
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
import {CustomErrorStateMatcher} from '@app/_helpers';
import {User} from 'cic-client-meta';
import {Envelope} from '@src/assets/js/cic-meta/sync';
import {Envelope, User} from 'cic-client-meta';
@Component({
selector: 'app-account-details',

View File

@@ -1,5 +1,5 @@
import {AfterViewInit, Component, OnInit, ViewChild} from '@angular/core';
import {BlockSyncService, TransactionService} from '@app/_services';
import {TransactionService} from '@app/_services';
import {MatTableDataSource} from '@angular/material/table';
import {SelectionModel} from '@angular/cdk/collections';
import {MatPaginator} from '@angular/material/paginator';
@@ -25,10 +25,7 @@ export class TransactionsComponent implements OnInit, AfterViewInit {
constructor(
private transactionService: TransactionService,
private blockSyncService: BlockSyncService
) {
this.blockSyncService.blockSync();
}
) { }
ngOnInit(): void {
this.transactionService.transactionsSubject.subscribe(transactions => {