Skip to content

Commit

Permalink
Merge 70ef6e7 into 06631ab
Browse files Browse the repository at this point in the history
  • Loading branch information
kewde committed Feb 2, 2018
2 parents 06631ab + 70ef6e7 commit 6a2d0cc
Show file tree
Hide file tree
Showing 39 changed files with 670 additions and 251 deletions.
6 changes: 4 additions & 2 deletions modules/rpc/rpc.js
Expand Up @@ -4,11 +4,12 @@ const http = require('http');
const cookie = require('./cookie');
const _options = require('../options');

/* spyOnRpc will output all RPC calls being made */
const spyOnRpc = false;

let TIMEOUT = 15000;
let HOSTNAME;
let PORT;
let TIMEOUT = 30000;
let rpcOptions;
let auth;

Expand All @@ -33,6 +34,7 @@ exports.call = function(method, params, callback) {
callback = function (){};
}

const timeout = [ 'extkeyimportmaster', 'extkeygenesisimport'].includes(method) ? 240 * 1000 : TIMEOUT; // TODO: replace
const postData = JSON.stringify({
method: method,
params: params
Expand Down Expand Up @@ -115,7 +117,7 @@ exports.call = function(method, params, callback) {
}
});

request.setTimeout(TIMEOUT, error => {
request.setTimeout(timeout, error => {
return request.abort();
});

Expand Down
3 changes: 2 additions & 1 deletion package.json
@@ -1,8 +1,9 @@
{
"name": "particl-desktop",
"version": "1.1.0",
"version": "1.1.0-RC3",
"license": "GPL-2.0",
"description": "Particl Desktop - decentralized marketplace, private currency, messaging & self-governance",
"homepage": "https://particl.io",
"keywords": [
"particl",
"angular2",
Expand Down
5 changes: 4 additions & 1 deletion src/app/app.component.ts
Expand Up @@ -2,6 +2,8 @@ import { Component, OnInit } from '@angular/core';
import { MatIconRegistry } from '@angular/material'; // TODO: move to material module?
import { Log } from 'ng2-logger';

import { NewTxNotifierService } from 'app/core/rpc/rpc.module';

@Component({
selector: 'app-root',
templateUrl: './app.component.html',
Expand All @@ -14,7 +16,8 @@ export class AppComponent implements OnInit {
// multiwallet: any = [];

constructor(
private _iconRegistry: MatIconRegistry
private _iconRegistry: MatIconRegistry,
private _newtxnotifier: NewTxNotifierService
) {
_iconRegistry
.registerFontClassAlias('partIcon', 'part-icon')
Expand Down
2 changes: 1 addition & 1 deletion src/app/core-ui/main/main-view.component.html
Expand Up @@ -3,7 +3,7 @@

<div class="logo-area">
<div class="logo">
<img src="./assets/particl-logo{{txService.testnet ? '-testnet' : ''}}.svg"
<img src="./assets/particl-logo{{testnet ? '-testnet' : ''}}.svg"
alt="Particl">
</div>
</div>
Expand Down
13 changes: 10 additions & 3 deletions src/app/core-ui/main/main-view.component.ts
Expand Up @@ -8,7 +8,7 @@ import { environment } from '../../../environments/environment';

import { RpcService } from '../../core/core.module';
import { ModalsService } from '../../modals/modals.module';
import { TransactionService } from '../../wallet/wallet/shared/transaction.service';

/*
* The MainView is basically:
* sidebar + router-outlet.
Expand All @@ -21,11 +21,14 @@ import { TransactionService } from '../../wallet/wallet/shared/transaction.servi
styleUrls: ['./main-view.component.scss']
})
export class MainViewComponent implements OnInit, OnDestroy {

log: any = Log.create('main-view.component');
private destroyed: boolean = false;

/* UI States */

title: string = '';
testnet: boolean = false;

/* errors */
walletInitialized: boolean = undefined;
Expand All @@ -37,13 +40,13 @@ export class MainViewComponent implements OnInit, OnDestroy {
unSubscribeTimer: any;
time: string = '5:00';
public unlocked_until: number = 0;
private destroyed: boolean = false;


constructor(
private _router: Router,
private _route: ActivatedRoute,
private _rpc: RpcService,
private _modals: ModalsService,
public txService: TransactionService,
private dialog: MatDialog
) { }

Expand Down Expand Up @@ -99,6 +102,10 @@ export class MainViewComponent implements OnInit, OnDestroy {
this._rpc.state.observe('subversion')
.takeWhile(() => !this.destroyed)
.subscribe(subversion => this.daemonVersion = subversion.match(/\d+\.\d+.\d+.\d+/)[0]);

/* check if testnet -> block explorer url */
this._rpc.state.observe('chain').take(1)
.subscribe(chain => this.testnet = chain === 'test');
}

ngOnDestroy() {
Expand Down
4 changes: 0 additions & 4 deletions src/app/core-ui/main/main-view.module.ts
Expand Up @@ -10,7 +10,6 @@ import { StatusComponent } from './status/status.component';
import { ConsoleModalComponent } from './status/modal/help-modal/console-modal.component';
import { PercentageBarComponent } from '../../modals/shared/percentage-bar/percentage-bar.component';

import { TransactionService } from '../../wallet/wallet/shared/transaction.service';
import { ReleaseNotificationComponent } from './release-notification/release-notification.component';


Expand All @@ -36,9 +35,6 @@ import { ReleaseNotificationComponent } from './release-notification/release-not
ConsoleModalComponent,
ReleaseNotificationComponent
],
providers: [
TransactionService
],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
})
export class MainViewModule { }
2 changes: 1 addition & 1 deletion src/app/core/rpc/blockstatus/blockstatus.service.ts
Expand Up @@ -8,7 +8,7 @@ import { PeerService } from '../peer/peer.service';
@Injectable()
export class BlockStatusService {

private log: any = Log.create('blockstatus.service');
private log: any = Log.create('blockstatus.service id:' + Math.floor((Math.random() * 1000) + 1));

/* Block variables */
private highestBlockHeightNetwork: number = -1;
Expand Down
23 changes: 23 additions & 0 deletions src/app/core/rpc/new-tx-notifier/new-tx-notifier.service.spec.ts
@@ -0,0 +1,23 @@
import { TestBed, inject } from '@angular/core/testing';
import { HttpClient, HttpClientModule } from '@angular/common/http';

import { RpcModule } from '../rpc.module';
import { NewTxNotifierService } from './new-tx-notifier.service';
import { CoreModule } from 'app/core/core.module';

describe('NewTxNotifierService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
HttpClientModule,
CoreModule.forRoot(),
// RpcModule.forRoot()
],
providers: [NewTxNotifierService]
});
});

it('should be created', inject([NewTxNotifierService], (service: NewTxNotifierService) => {
expect(service).toBeTruthy();
}));
});
82 changes: 82 additions & 0 deletions src/app/core/rpc/new-tx-notifier/new-tx-notifier.service.ts
@@ -0,0 +1,82 @@
import { Injectable, OnDestroy } from '@angular/core';
import { Log } from 'ng2-logger';
import { Observable } from 'rxjs/Observable';

import { NotificationService } from 'app/core/notification/notification.service';
import { RpcService } from 'app/core/rpc/rpc.service';

@Injectable()
export class NewTxNotifierService implements OnDestroy {

log: any = Log.create('new-tx-notifier.service id:' + Math.floor((Math.random() * 1000) + 1));
private destroyed: boolean = false;

private lastTxId: string = undefined;


constructor(
private _rpc: RpcService,
private _notification: NotificationService
) {

this.log.d('tx notifier service running!');
// TODO: when state moves into its own service, fix it here
// TODO: throttle (block sync)..
this._rpc.state.observe('blocks').
throttle(val => Observable.interval(30000/*ms*/)).
takeWhile(() => !this.destroyed).subscribe(
(blocks: number) => {
this.newTransaction();
}
);
}

// TODO: trigger by ZMQ in the future
newTransaction(): void {
this.log.d('newTransaction()');

const options = {
'count': 10
};
this._rpc.call('filtertransactions', [options])
.subscribe(
(txs: Array<any>) => {

// if no transactions: stop
if (txs.length === 0) {
return;
}

// not initialized yet
if (this.lastTxId === undefined) {
this.lastTxId = txs[0].txid;
} else {
txs.some((tx) => {
// we hit our last transaction, abort notifications
if (this.lastTxId === tx.txid) {
return true;
}

this.notifyNewTransaction(tx);
})

// update tip
this.lastTxId = txs[0].txid;
}
});
}

private notifyNewTransaction(tx: any) {
this.log.d('notify new tx: ' + tx);
if (tx.category === 'receive') {
this._notification.sendNotification('Incoming transaction', tx.amount + ' PART received');
} else if (tx.category === 'stake') {
this._notification.sendNotification('New stake reward', tx.amount + ' PART received');
}
}

ngOnDestroy() {
this.destroyed = true;
}

}
13 changes: 10 additions & 3 deletions src/app/core/rpc/peer/peer.service.ts
@@ -1,13 +1,14 @@
import { Injectable } from '@angular/core';
import { Injectable, OnDestroy } from '@angular/core';
import { Observable, Observer, Subscription } from 'rxjs'; // use this for testing atm
import { Log } from 'ng2-logger';

import { RpcService } from '../rpc.service';

@Injectable()
export class PeerService {
export class PeerService implements OnDestroy {

private log: any = Log.create('peer.service');
private destroyed: boolean = false;

// TODO: Peer interface
private _peerList: Observable<Array<Object>>;
Expand Down Expand Up @@ -59,7 +60,9 @@ export class PeerService {
error => this.log.er(`updatePeerListLoop(): getblockcount error ${error}`)
);

setTimeout(this.updatePeerListLoop.bind(this), 10000);
if (!this.destroyed) {
setTimeout(this.updatePeerListLoop.bind(this), 10000);
}
}

private setPeerList(peerList: Array<Object>) {
Expand Down Expand Up @@ -96,4 +99,8 @@ export class PeerService {
return this._peerList;
}

// TODO: destroy other observables
ngOnDestroy() {
this.destroyed = true;
}
}
5 changes: 2 additions & 3 deletions src/app/core/rpc/rpc-state/rpc-state.class.ts
Expand Up @@ -55,8 +55,6 @@ export class RpcStateClass implements OnDestroy {
.subscribe(status => {
this._rpc.state
.set('locked', ['Locked', 'Unlocked, staking only'].includes(status));
this._rpc.state
.set('ui:coldstaking:stake', ['Unencrypted', 'Unlocked', 'Unlocked, staking only'].includes(status));
});
}

Expand All @@ -66,6 +64,7 @@ export class RpcStateClass implements OnDestroy {
* update the coldstaking state.
*/
private coldStakeHook() {
// TODO: Remove
this._rpc.state.observe('locked')
.takeWhile(() => !this.destroyed)
.subscribe(locked => {
Expand All @@ -77,7 +76,7 @@ export class RpcStateClass implements OnDestroy {
// set state for coldstaking
response => this._rpc.state.set('ui:coldstaking',
response.changeaddress === 'default'
? undefined
? false
: !!response.changeaddress.coldstakingaddress
),
error => this.log.er('walletsettings changeaddress', error)
Expand Down
5 changes: 4 additions & 1 deletion src/app/core/rpc/rpc.module.ts
Expand Up @@ -4,7 +4,8 @@ import { CommonModule } from '@angular/common';

import { RpcService } from './rpc.service';

import { BlockStatusService } from './blockstatus/blockstatus.service'
import { BlockStatusService } from './blockstatus/blockstatus.service';
import { NewTxNotifierService } from './new-tx-notifier/new-tx-notifier.service';
import { PeerService } from './peer/peer.service';
import { StateService } from '../state/state.service';

Expand All @@ -21,6 +22,7 @@ export class RpcModule {
providers: [
RpcService,
BlockStatusService,
NewTxNotifierService,
PeerService,
StateService
]
Expand All @@ -34,3 +36,4 @@ export { RpcService } from './rpc.service';
export { BlockStatusService } from './blockstatus/blockstatus.service'
export { PeerService } from './peer/peer.service';
export { StateService } from '../state/state.service';
export { NewTxNotifierService } from './new-tx-notifier/new-tx-notifier.service';
1 change: 1 addition & 0 deletions src/app/core/rpc/rpc.service.ts
Expand Up @@ -8,6 +8,7 @@ import { map, catchError } from 'rxjs/operators';
import { IpcService } from '../ipc/ipc.service';
import { StateService } from '../state/state.service';
import { RpcStateClass } from './rpc-state/rpc-state.class';
import { NewTxNotifierService } from 'app/core/rpc/new-tx-notifier/new-tx-notifier.service';

const MAINNET_PORT = 51735;
const TESTNET_PORT = 51935;
Expand Down
2 changes: 1 addition & 1 deletion src/app/core/state/state.service.ts
Expand Up @@ -70,7 +70,7 @@ export class StateService {

this._observerPairs[prop].observable = Observable.create(
_observer => this._observerPairs[prop].observer = _observer
).shareReplay();
).shareReplay(1);
}

return this._observerPairs[prop];
Expand Down
3 changes: 2 additions & 1 deletion src/app/modals/createwallet/createwallet.component.ts
Expand Up @@ -79,7 +79,7 @@ export class CreateWalletComponent implements OnDestroy {
this.errorString = '';
this.step = 0;
this.state.observe('encryptionstatus')
.takeWhile(() => !this.destroyed)
.take(2)
.subscribe(status => this.isCrypted = status !== 'Unencrypted');
}

Expand Down Expand Up @@ -187,6 +187,7 @@ export class CreateWalletComponent implements OnDestroy {

public importMnemonicSeed(): void {
this.state.set('ui:spinner', true);

this._passphraseService.importMnemonic(this.words, this.password)
.subscribe(
success => {
Expand Down
2 changes: 2 additions & 0 deletions src/app/modals/modals.service.ts
Expand Up @@ -95,6 +95,8 @@ export class ModalsService implements OnDestroy {
dialogRef.afterClosed().subscribe(() => {
this.close();
});
} else {
dialogRef.close();
}
}
} else {
Expand Down

0 comments on commit 6a2d0cc

Please sign in to comment.