2022-04-27 02:52:23 +04:00
|
|
|
import { Injectable } from '@angular/core';
|
2022-05-01 03:01:27 +04:00
|
|
|
import { HttpClient, HttpParams } from '@angular/common/http';
|
2022-04-27 02:52:23 +04:00
|
|
|
import { Observable } from 'rxjs';
|
2022-07-06 11:58:06 +02:00
|
|
|
import { StateService } from '../services/state.service';
|
2022-04-27 02:52:23 +04:00
|
|
|
|
|
|
|
@Injectable({
|
|
|
|
providedIn: 'root'
|
|
|
|
})
|
|
|
|
export class LightningApiService {
|
2022-07-06 11:58:06 +02:00
|
|
|
private apiBasePath = ''; // network path is /testnet, etc. or '' for mainnet
|
|
|
|
|
2022-04-27 02:52:23 +04:00
|
|
|
constructor(
|
|
|
|
private httpClient: HttpClient,
|
2022-07-06 11:58:06 +02:00
|
|
|
private stateService: StateService,
|
|
|
|
) {
|
|
|
|
this.apiBasePath = ''; // assume mainnet by default
|
|
|
|
this.stateService.networkChanged$.subscribe((network) => {
|
|
|
|
if (network === 'bisq' && !this.stateService.env.BISQ_SEPARATE_BACKEND) {
|
|
|
|
network = '';
|
|
|
|
}
|
|
|
|
this.apiBasePath = network ? '/' + network : '';
|
|
|
|
});
|
|
|
|
}
|
2022-04-27 02:52:23 +04:00
|
|
|
|
2022-04-29 03:57:27 +04:00
|
|
|
getNode$(publicKey: string): Observable<any> {
|
2022-07-06 11:58:06 +02:00
|
|
|
return this.httpClient.get<any>(this.apiBasePath + '/api/v1/lightning/nodes/' + publicKey);
|
2022-04-29 03:57:27 +04:00
|
|
|
}
|
|
|
|
|
2022-05-01 03:01:27 +04:00
|
|
|
getChannel$(shortId: string): Observable<any> {
|
2022-07-06 11:58:06 +02:00
|
|
|
return this.httpClient.get<any>(this.apiBasePath + '/api/v1/lightning/channels/' + shortId);
|
2022-05-01 03:01:27 +04:00
|
|
|
}
|
|
|
|
|
2022-05-16 01:36:59 +04:00
|
|
|
getChannelsByNodeId$(publicKey: string, index: number = 0, status = 'open'): Observable<any> {
|
2022-05-01 03:01:27 +04:00
|
|
|
let params = new HttpParams()
|
|
|
|
.set('public_key', publicKey)
|
2022-05-16 01:36:59 +04:00
|
|
|
.set('index', index)
|
|
|
|
.set('status', status)
|
2022-05-01 03:01:27 +04:00
|
|
|
;
|
|
|
|
|
2022-07-06 11:58:06 +02:00
|
|
|
return this.httpClient.get<any>(this.apiBasePath + '/api/v1/lightning/channels', { params, observe: 'response' });
|
2022-04-29 03:57:27 +04:00
|
|
|
}
|
|
|
|
|
2022-04-27 02:52:23 +04:00
|
|
|
getLatestStatistics$(): Observable<any> {
|
2022-07-06 11:58:06 +02:00
|
|
|
return this.httpClient.get<any>(this.apiBasePath + '/api/v1/lightning/statistics/latest');
|
2022-04-27 02:52:23 +04:00
|
|
|
}
|
|
|
|
|
2022-05-05 23:19:24 +04:00
|
|
|
listNodeStats$(publicKey: string): Observable<any> {
|
2022-07-06 11:58:06 +02:00
|
|
|
return this.httpClient.get<any>(this.apiBasePath + '/api/v1/lightning/nodes/' + publicKey + '/statistics');
|
2022-05-05 23:19:24 +04:00
|
|
|
}
|
|
|
|
|
2022-04-27 02:52:23 +04:00
|
|
|
listTopNodes$(): Observable<any> {
|
2022-07-06 11:58:06 +02:00
|
|
|
return this.httpClient.get<any>(this.apiBasePath + '/api/v1/lightning/nodes/top');
|
2022-04-27 02:52:23 +04:00
|
|
|
}
|
2022-07-01 16:50:53 +02:00
|
|
|
|
|
|
|
listStatistics$(): Observable<any> {
|
2022-07-06 11:58:06 +02:00
|
|
|
return this.httpClient.get<any>(this.apiBasePath + '/api/v1/lightning/statistics');
|
2022-07-01 16:50:53 +02:00
|
|
|
}
|
2022-04-27 02:52:23 +04:00
|
|
|
}
|