mempool/frontend/src/app/lightning/lightning-api.service.ts

63 lines
2.1 KiB
TypeScript
Raw Normal View History

import { Injectable } from '@angular/core';
2022-05-01 03:01:27 +04:00
import { HttpClient, HttpParams } from '@angular/common/http';
import { Observable } from 'rxjs';
import { StateService } from '../services/state.service';
@Injectable({
providedIn: 'root'
})
export class LightningApiService {
private apiBasePath = ''; // network path is /testnet, etc. or '' for mainnet
constructor(
private httpClient: HttpClient,
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-29 03:57:27 +04:00
getNode$(publicKey: string): Observable<any> {
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> {
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
;
return this.httpClient.get<any>(this.apiBasePath + '/api/v1/lightning/channels', { params, observe: 'response' });
2022-04-29 03:57:27 +04:00
}
getLatestStatistics$(): Observable<any> {
return this.httpClient.get<any>(this.apiBasePath + '/api/v1/lightning/statistics/latest');
}
2022-05-05 23:19:24 +04:00
listNodeStats$(publicKey: string): Observable<any> {
return this.httpClient.get<any>(this.apiBasePath + '/api/v1/lightning/nodes/' + publicKey + '/statistics');
2022-05-05 23:19:24 +04:00
}
listTopNodes$(): Observable<any> {
return this.httpClient.get<any>(this.apiBasePath + '/api/v1/lightning/nodes/top');
}
2022-07-01 16:50:53 +02:00
listChannelStats$(publicKey: string): Observable<any> {
return this.httpClient.get<any>(this.apiBasePath + '/channels/' + publicKey + '/statistics');
}
2022-07-01 16:50:53 +02:00
listStatistics$(): Observable<any> {
return this.httpClient.get<any>(this.apiBasePath + '/api/v1/lightning/statistics');
2022-07-01 16:50:53 +02:00
}
}