-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feature/tx
- Loading branch information
Showing
59 changed files
with
1,712 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import { Injectable } from '@angular/core'; | ||
|
||
import { ElectronService } from 'ngx-electron'; | ||
import { RPCService } from './core/rpc/rpc.service'; | ||
|
||
@Injectable() | ||
export class AppService { | ||
public isElectron: boolean = false; | ||
|
||
constructor(public electronService: ElectronService) { | ||
this.isElectron = this.electronService.isElectronApp; | ||
constructor(public rpc: RPCService) { | ||
this.isElectron = this.rpc.electronService.isElectronApp; | ||
rpc.postConstruct(this); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,21 @@ | ||
import { TestBed, inject } from '@angular/core/testing'; | ||
import { HttpModule } from '@angular/http'; | ||
|
||
import { RpcService } from './rpc.service'; | ||
import { RPCService } from './rpc.service'; | ||
import { ElectronService } from 'ngx-electron'; | ||
|
||
describe('RpcService', () => { | ||
describe('RPCService', () => { | ||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
providers: [RpcService] | ||
imports: [HttpModule], | ||
providers: [ | ||
RPCService, | ||
ElectronService | ||
] | ||
}); | ||
}); | ||
|
||
it('should ...', inject([RpcService], (service: RpcService) => { | ||
it('should be created', inject([RPCService], (service: RPCService) => { | ||
expect(service).toBeTruthy(); | ||
})); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,103 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { ElectronService } from 'ngx-electron'; | ||
|
||
import { Headers, Http } from '@angular/http'; | ||
import { AppService } from 'app/app.service'; | ||
|
||
const MAINNET_PORT = 51935; | ||
const TESTNET_PORT = 51935; | ||
|
||
const HOSTNAME = 'localhost'; | ||
|
||
@Injectable() | ||
export class RpcService { | ||
export class RPCService { | ||
private hostname: String = HOSTNAME; // TODO: URL Flag / Settings | ||
private port: number = TESTNET_PORT; // TODO: Mainnet / testnet flag... | ||
|
||
private username: string = 'test'; | ||
private password: string = 'test'; | ||
|
||
private _appService: AppService; | ||
private _callOnBlock: Array<any> = []; | ||
private _callOnTransaction: Array<any> = []; | ||
|
||
private _pollTimout: NodeJS.Timer; | ||
|
||
constructor(private http: Http, public electronService: ElectronService) { } | ||
|
||
postConstruct(appService: AppService) { // Gets rid of circular dependency.. We could possibly handle this better.. | ||
this._appService = appService; | ||
} | ||
|
||
call(instance: Injectable, method: string, params: Array<any> | null, callback: Function): void { | ||
const postData = JSON.stringify({ | ||
method: method, | ||
params: params, | ||
id: 1 | ||
}); | ||
const headers = new Headers(); | ||
|
||
headers.append('Content-Type', 'application/json'); | ||
headers.append('Authorization', 'Basic ' + btoa(`${this.username}:${this.password}`)); | ||
headers.append('Accept', 'application/json'); | ||
|
||
if (this._appService.isElectron) { | ||
// TODO: electron.ipcCall | ||
} else { | ||
this.http | ||
.post(`http://${this.hostname}:${this.port}`, postData, { headers: headers }) | ||
.subscribe( | ||
response => { | ||
callback.call(instance, response.json().result); | ||
}, | ||
error => { | ||
// TODO: Call error modal? | ||
console.log('RPC Call returned an error', error); | ||
}); | ||
} | ||
} | ||
|
||
register(instance: Injectable, method: string, params: Array<any> | Function | null, | ||
callback: Function, when: string): void { | ||
let valid = false; | ||
const _call = { | ||
instance: instance, | ||
method: method, | ||
params: params, | ||
callback: callback | ||
}; | ||
if (when.indexOf('block') !== -1 || when.indexOf('both') !== -1) { | ||
this._callOnBlock.push(_call); | ||
valid = true; | ||
} | ||
if (when.indexOf('tx') !== -1 || when.indexOf('both') !== -1) { | ||
this._callOnTransaction.push(_call); | ||
valid = true; | ||
} | ||
} | ||
|
||
poll(): void { | ||
// TODO: Actual polling... Check block height and last transaction | ||
const _call = (element) => { | ||
this.call( | ||
element.instance, | ||
element.method, | ||
element.params && element.params.typeOf === 'function' ? element.params() : element.params, | ||
element.callback); | ||
}; | ||
|
||
this._callOnBlock.forEach(_call); | ||
this._callOnTransaction.forEach(_call); | ||
this._pollTimout = setTimeout(() => { this.poll(); }, 3000); | ||
} | ||
|
||
startPolling(): void { | ||
clearTimeout(this._pollTimout); | ||
this.poll(); | ||
} | ||
|
||
constructor() { } | ||
stopPolling(): void { | ||
clearTimeout(this._pollTimout); | ||
} | ||
|
||
} |
Oops, something went wrong.