import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { Observable } from 'rxjs'; import { Block, Transaction, Address, Outspend, Recent } from '../interfaces/electrs.interface'; const API_BASE_URL = document.location.protocol + '//' + document.location.hostname + ':' + document.location.port + '/electrs'; @Injectable({ providedIn: 'root' }) export class ElectrsApiService { constructor( private httpClient: HttpClient, ) { } getBlock$(hash: string): Observable { return this.httpClient.get(API_BASE_URL + '/block/' + hash); } listBlocks$(height?: number): Observable { return this.httpClient.get(API_BASE_URL + '/blocks/' + (height || '')); } getTransaction$(txId: string): Observable { return this.httpClient.get(API_BASE_URL + '/tx/' + txId); } getRecentTransaction$(): Observable { return this.httpClient.get(API_BASE_URL + '/mempool/recent'); } getOutspend$(hash: string, vout: number): Observable { return this.httpClient.get(API_BASE_URL + '/tx/' + hash + '/outspend/' + vout); } getOutspends$(hash: string): Observable { return this.httpClient.get(API_BASE_URL + '/tx/' + hash + '/outspends'); } getBlockTransactions$(hash: string, index: number = 0): Observable { return this.httpClient.get(API_BASE_URL + '/block/' + hash + '/txs/' + index); } getAddress$(address: string): Observable
{ return this.httpClient.get
(API_BASE_URL + '/address/' + address); } getAddressTransactions$(address: string): Observable { return this.httpClient.get(API_BASE_URL + '/address/' + address + '/txs'); } getAddressTransactionsFromHash$(address: string, txid: string): Observable { return this.httpClient.get(API_BASE_URL + '/address/' + address + '/txs/chain/' + txid); } }