2019-07-21 17:59:47 +03:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
import { environment } from '../../environments/environment';
|
|
|
|
import { webSocket } from 'rxjs/webSocket';
|
|
|
|
import { HttpClient, HttpParams } from '@angular/common/http';
|
|
|
|
import { IMempoolDefaultResponse, IMempoolStats, IBlockTransaction } from '../blockchain/interfaces';
|
|
|
|
import { Observable } from 'rxjs';
|
|
|
|
|
2019-07-22 21:30:52 +09:00
|
|
|
const WEB_SOCKET_URL = 'ws://' + document.location.hostname + ':8999';
|
2019-07-21 18:35:58 +03:00
|
|
|
const API_BASE_URL = '/api/v1';
|
2019-07-21 17:59:47 +03:00
|
|
|
|
|
|
|
@Injectable({
|
|
|
|
providedIn: 'root'
|
|
|
|
})
|
|
|
|
export class ApiService {
|
|
|
|
constructor(
|
|
|
|
private httpClient: HttpClient,
|
|
|
|
) { }
|
|
|
|
|
|
|
|
websocketSubject = webSocket<IMempoolDefaultResponse>(WEB_SOCKET_URL);
|
|
|
|
|
|
|
|
listTransactionsForBlock$(height: number): Observable<IBlockTransaction[]> {
|
|
|
|
return this.httpClient.get<IBlockTransaction[]>(API_BASE_URL + '/transactions/height/' + height);
|
|
|
|
}
|
|
|
|
|
|
|
|
listTransactionsForProjectedBlock$(index: number): Observable<IBlockTransaction[]> {
|
|
|
|
return this.httpClient.get<IBlockTransaction[]>(API_BASE_URL + '/transactions/projected/' + index);
|
|
|
|
}
|
|
|
|
|
|
|
|
listLiveStatistics$(lastId: number): Observable<IMempoolStats[]> {
|
|
|
|
const params = new HttpParams()
|
|
|
|
.set('lastId', lastId.toString());
|
|
|
|
|
|
|
|
return this.httpClient.get<IMempoolStats[]>(API_BASE_URL + '/statistics/live', {
|
|
|
|
params: params
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
list2HStatistics$(): Observable<IMempoolStats[]> {
|
|
|
|
return this.httpClient.get<IMempoolStats[]>(API_BASE_URL + '/statistics/2h');
|
|
|
|
}
|
|
|
|
|
|
|
|
list24HStatistics$(): Observable<IMempoolStats[]> {
|
|
|
|
return this.httpClient.get<IMempoolStats[]>(API_BASE_URL + '/statistics/24h');
|
|
|
|
}
|
|
|
|
|
|
|
|
list1WStatistics$(): Observable<IMempoolStats[]> {
|
|
|
|
return this.httpClient.get<IMempoolStats[]>(API_BASE_URL + '/statistics/1w');
|
|
|
|
}
|
|
|
|
|
|
|
|
list1MStatistics$(): Observable<IMempoolStats[]> {
|
|
|
|
return this.httpClient.get<IMempoolStats[]>(API_BASE_URL + '/statistics/1m');
|
|
|
|
}
|
|
|
|
|
|
|
|
list3MStatistics$(): Observable<IMempoolStats[]> {
|
|
|
|
return this.httpClient.get<IMempoolStats[]>(API_BASE_URL + '/statistics/3m');
|
|
|
|
}
|
|
|
|
|
|
|
|
list6MStatistics$(): Observable<IMempoolStats[]> {
|
|
|
|
return this.httpClient.get<IMempoolStats[]>(API_BASE_URL + '/statistics/6m');
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|