diff --git a/backend/src/api/bitcoin/electrum-api.ts b/backend/src/api/bitcoin/electrum-api.ts index f2d498b00..2929c2da4 100644 --- a/backend/src/api/bitcoin/electrum-api.ts +++ b/backend/src/api/bitcoin/electrum-api.ts @@ -83,29 +83,35 @@ class BitcoindElectrsApi extends BitcoinApi implements AbstractBitcoinApi { }); } - const balance = await this.$getScriptHashBalance(addressInfo.scriptPubKey); - const history = await this.$getScriptHashHistory(addressInfo.scriptPubKey); + try { + const balance = await this.$getScriptHashBalance(addressInfo.scriptPubKey); + const history = await this.$getScriptHashHistory(addressInfo.scriptPubKey); - const unconfirmed = history.filter((h) => h.fee).length; + const unconfirmed = history.filter((h) => h.fee).length; - return { - 'address': addressInfo.address, - 'chain_stats': { - 'funded_txo_count': 0, - 'funded_txo_sum': balance.confirmed ? balance.confirmed : 0, - 'spent_txo_count': 0, - 'spent_txo_sum': balance.confirmed < 0 ? balance.confirmed : 0, - 'tx_count': history.length - unconfirmed, - }, - 'mempool_stats': { - 'funded_txo_count': 0, - 'funded_txo_sum': balance.unconfirmed > 0 ? balance.unconfirmed : 0, - 'spent_txo_count': 0, - 'spent_txo_sum': balance.unconfirmed < 0 ? -balance.unconfirmed : 0, - 'tx_count': unconfirmed, + return { + 'address': addressInfo.address, + 'chain_stats': { + 'funded_txo_count': 0, + 'funded_txo_sum': balance.confirmed ? balance.confirmed : 0, + 'spent_txo_count': 0, + 'spent_txo_sum': balance.confirmed < 0 ? balance.confirmed : 0, + 'tx_count': history.length - unconfirmed, + }, + 'mempool_stats': { + 'funded_txo_count': 0, + 'funded_txo_sum': balance.unconfirmed > 0 ? balance.unconfirmed : 0, + 'spent_txo_count': 0, + 'spent_txo_sum': balance.unconfirmed < 0 ? -balance.unconfirmed : 0, + 'tx_count': unconfirmed, + } + }; + } catch (e) { + if (e === 'failed to get confirmed status') { + e = 'The number of transactions on this address exceeds the Electrum server limit'; } - }; - + throw new Error(e); + } } async $getAddressTransactions(address: string, lastSeenTxId: string): Promise { @@ -113,26 +119,34 @@ class BitcoindElectrsApi extends BitcoinApi implements AbstractBitcoinApi { if (!addressInfo || !addressInfo.isvalid) { return []; } - const transactions: IEsploraApi.Transaction[] = []; - const history = await this.$getScriptHashHistory(addressInfo.scriptPubKey); - history.reverse(); - let startingIndex = 0; - if (lastSeenTxId) { - const pos = history.findIndex((historicalTx) => historicalTx.tx_hash === lastSeenTxId); - if (pos) { - startingIndex = pos + 1; + try { + const transactions: IEsploraApi.Transaction[] = []; + const history = await this.$getScriptHashHistory(addressInfo.scriptPubKey); + history.reverse(); + + let startingIndex = 0; + if (lastSeenTxId) { + const pos = history.findIndex((historicalTx) => historicalTx.tx_hash === lastSeenTxId); + if (pos) { + startingIndex = pos + 1; + } } - } - for (let i = startingIndex; i < Math.min(startingIndex + 10, history.length); i++) { - const tx = await this.$getRawTransaction(history[i].tx_hash, false, true); - if (tx) { - transactions.push(tx); + for (let i = startingIndex; i < Math.min(startingIndex + 10, history.length); i++) { + const tx = await this.$getRawTransaction(history[i].tx_hash, false, true); + if (tx) { + transactions.push(tx); + } } - } - return transactions; + return transactions; + } catch (e) { + if (e === 'failed to get confirmed status') { + e = 'The number of transactions on this address exceeds the Electrum server limit'; + } + throw new Error(e); + } } private $getScriptHashBalance(scriptHash: string): Promise { diff --git a/backend/src/routes.ts b/backend/src/routes.ts index 8dfeffa04..d770aea8d 100644 --- a/backend/src/routes.ts +++ b/backend/src/routes.ts @@ -538,7 +538,7 @@ class Routes { res.status(500).send('Error fetching transaction.'); } } catch (e) { - res.status(500).send(e.message); + res.status(500).send(e.message || e); } } @@ -547,7 +547,7 @@ class Routes { const result = await bitcoinApi.$getBlock(req.params.hash); res.json(result); } catch (e) { - res.status(500).send(e.message); + res.status(500).send(e.message || e); } } @@ -580,7 +580,7 @@ class Routes { res.json(returnBlocks); } catch (e) { - res.status(500).send(e.message); + res.status(500).send(e.message || e); } } @@ -598,7 +598,7 @@ class Routes { } res.json(transactions); } catch (e) { - res.status(500).send(e.message); + res.status(500).send(e.message || e); } } @@ -607,7 +607,7 @@ class Routes { const blockHash = await bitcoinApi.$getBlockHash(parseInt(req.params.height, 10)); res.send(blockHash); } catch (e) { - res.status(500).send(e.message); + res.status(500).send(e.message || e); } } @@ -621,7 +621,10 @@ class Routes { const addressData = await bitcoinApi.$getAddress(req.params.address); res.json(addressData); } catch (e) { - res.status(500).send(e.message); + if (e.message && e.message.indexOf('exceeds') > 0) { + return res.status(413).send(e.message); + } + res.status(500).send(e.message || e); } } @@ -635,7 +638,10 @@ class Routes { const transactions = await bitcoinApi.$getAddressTransactions(req.params.address, req.params.txId); res.json(transactions); } catch (e) { - res.status(500).send(e.message); + if (e.message && e.message.indexOf('exceeds') > 0) { + return res.status(413).send(e.message); + } + res.status(500).send(e.message || e); } } diff --git a/frontend/src/app/components/address/address.component.html b/frontend/src/app/components/address/address.component.html index 41728c083..e5a0ffd0a 100644 --- a/frontend/src/app/components/address/address.component.html +++ b/frontend/src/app/components/address/address.component.html @@ -105,6 +105,14 @@ Error loading address data.
{{ error.error }} + +

+ Consider view this address on the official Mempool website instead: +
+ https://mempool.space/address/{{ addressString }} +
+ http://mempoolhqx4isw62xs7abwphsq7ldayuidyx2v2oethdhhj6mlo2r6ad.onion/address/{{ addressString }} +