diff --git a/backend/src/api/bitcoin/bitcoin.routes.ts b/backend/src/api/bitcoin/bitcoin.routes.ts index 17ebc9275..babc0aa53 100644 --- a/backend/src/api/bitcoin/bitcoin.routes.ts +++ b/backend/src/api/bitcoin/bitcoin.routes.ts @@ -121,7 +121,6 @@ class BitcoinRoutes { .get(config.MEMPOOL.API_URL_PREFIX + 'block-height/:height', this.getBlockHeight) .get(config.MEMPOOL.API_URL_PREFIX + 'address/:address', this.getAddress) .get(config.MEMPOOL.API_URL_PREFIX + 'address/:address/txs', this.getAddressTransactions) - .get(config.MEMPOOL.API_URL_PREFIX + 'address/:address/txs/chain/:txId', this.getAddressTransactions) .get(config.MEMPOOL.API_URL_PREFIX + 'address-prefix/:prefix', this.getAddressPrefix) ; } @@ -546,27 +545,28 @@ class BitcoinRoutes { } } - private async getAddressTransactions(req: Request, res: Response) { + private async getAddressTransactions(req: Request, res: Response): Promise { if (config.MEMPOOL.BACKEND === 'none') { res.status(405).send('Address lookups cannot be used with bitcoind as backend.'); return; } try { - const transactions = await bitcoinApi.$getAddressTransactions(req.params.address, req.params.txId); + let lastTxId: string = ''; + if (req.query.after_txid && typeof req.query.after_txid === 'string') { + lastTxId = req.query.after_txid; + } + const transactions = await bitcoinApi.$getAddressTransactions(req.params.address, lastTxId); res.json(transactions); } catch (e) { if (e instanceof Error && e.message && (e.message.indexOf('too long') > 0 || e.message.indexOf('confirmed status') > 0)) { - return res.status(413).send(e instanceof Error ? e.message : e); + res.status(413).send(e instanceof Error ? e.message : e); + return; } res.status(500).send(e instanceof Error ? e.message : e); } } - private async getAdressTxChain(req: Request, res: Response) { - res.status(501).send('Not implemented'); - } - private async getAddressPrefix(req: Request, res: Response) { try { const blockHash = await bitcoinApi.$getAddressPrefix(req.params.prefix); diff --git a/frontend/src/app/components/address/address.component.ts b/frontend/src/app/components/address/address.component.ts index 2ae9a962b..57439f983 100644 --- a/frontend/src/app/components/address/address.component.ts +++ b/frontend/src/app/components/address/address.component.ts @@ -207,7 +207,7 @@ export class AddressComponent implements OnInit, OnDestroy { } this.isLoadingTransactions = true; this.retryLoadMore = false; - this.electrsApiService.getAddressTransactionsFromHash$(this.address.address, this.lastTransactionTxId) + this.electrsApiService.getAddressTransactions$(this.address.address, this.lastTransactionTxId) .subscribe((transactions: Transaction[]) => { this.lastTransactionTxId = transactions[transactions.length - 1].txid; this.loadedConfirmedTxCount += transactions.length; @@ -217,6 +217,10 @@ export class AddressComponent implements OnInit, OnDestroy { (error) => { this.isLoadingTransactions = false; this.retryLoadMore = true; + // In the unlikely event of the txid wasn't found in the mempool anymore and we must reload the page. + if (error.status === 422) { + window.location.reload(); + } }); } diff --git a/frontend/src/app/services/electrs-api.service.ts b/frontend/src/app/services/electrs-api.service.ts index 5756f7fb2..c87018741 100644 --- a/frontend/src/app/services/electrs-api.service.ts +++ b/frontend/src/app/services/electrs-api.service.ts @@ -1,5 +1,5 @@ import { Injectable } from '@angular/core'; -import { HttpClient } from '@angular/common/http'; +import { HttpClient, HttpParams } from '@angular/common/http'; import { Observable } from 'rxjs'; import { Transaction, Address, Outspend, Recent, Asset } from '../interfaces/electrs.interface'; import { StateService } from './state.service'; @@ -65,12 +65,12 @@ export class ElectrsApiService { return this.httpClient.get
(this.apiBaseUrl + this.apiBasePath + '/api/address/' + address); } - getAddressTransactions$(address: string): Observable { - return this.httpClient.get(this.apiBaseUrl + this.apiBasePath + '/api/address/' + address + '/txs'); - } - - getAddressTransactionsFromHash$(address: string, txid: string): Observable { - return this.httpClient.get(this.apiBaseUrl + this.apiBasePath + '/api/address/' + address + '/txs/chain/' + txid); + getAddressTransactions$(address: string, txid?: string): Observable { + let params = new HttpParams(); + if (txid) { + params = params.append('after_txid', txid); + } + return this.httpClient.get(this.apiBaseUrl + this.apiBasePath + '/api/address/' + address + '/txs', { params }); } getAsset$(assetId: string): Observable {