mirror of
https://github.com/mempool/mempool.git
synced 2026-08-13 12:33:11 +02:00
Merge pull request #6362 from mempool/knorrium/electrum_address_validation
Fix electrum address validation
This commit is contained in:
commit
54eae4ee7b
3 changed files with 15 additions and 24 deletions
|
|
@ -664,6 +664,10 @@ class BitcoinRoutes {
|
|||
const addressData = await bitcoinApi.$getAddress(req.params.address);
|
||||
res.json(addressData);
|
||||
} catch (e) {
|
||||
if (e instanceof Error && e.message === 'Invalid Bitcoin address') {
|
||||
res.status(400).send(e.message);
|
||||
return;
|
||||
}
|
||||
if (e instanceof Error && e.message && (e.message.indexOf('too long') > 0 || e.message.indexOf('confirmed status') > 0)) {
|
||||
handleError(req, res, 413, e.message);
|
||||
return;
|
||||
|
|
@ -690,6 +694,10 @@ class BitcoinRoutes {
|
|||
const transactions = await bitcoinApi.$getAddressTransactions(req.params.address, lastTxId);
|
||||
res.json(transactions);
|
||||
} catch (e) {
|
||||
if (e instanceof Error && e.message === 'Invalid Bitcoin address') {
|
||||
res.status(400).send(e.message);
|
||||
return;
|
||||
}
|
||||
if (e instanceof Error && e.message && (e.message.indexOf('too long') > 0 || e.message.indexOf('confirmed status') > 0)) {
|
||||
handleError(req, res, 413, e.message);
|
||||
return;
|
||||
|
|
@ -712,6 +720,10 @@ class BitcoinRoutes {
|
|||
const addressData = await bitcoinApi.$getAddressUtxos(req.params.address);
|
||||
res.json(addressData);
|
||||
} catch (e) {
|
||||
if (e instanceof Error && e.message === 'Invalid Bitcoin address') {
|
||||
res.status(400).send(e.message);
|
||||
return;
|
||||
}
|
||||
if (e instanceof Error && e.message && (e.message.indexOf('too long') > 0 || e.message.indexOf('confirmed status') > 0)) {
|
||||
handleError(req, res, 413, e.message);
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -44,23 +44,7 @@ class BitcoindElectrsApi extends BitcoinApi implements AbstractBitcoinApi {
|
|||
async $getAddress(address: string): Promise<IEsploraApi.Address> {
|
||||
const addressInfo = await this.bitcoindClient.validateAddress(address);
|
||||
if (!addressInfo || !addressInfo.isvalid) {
|
||||
return ({
|
||||
'address': address,
|
||||
'chain_stats': {
|
||||
'funded_txo_count': 0,
|
||||
'funded_txo_sum': 0,
|
||||
'spent_txo_count': 0,
|
||||
'spent_txo_sum': 0,
|
||||
'tx_count': 0
|
||||
},
|
||||
'mempool_stats': {
|
||||
'funded_txo_count': 0,
|
||||
'funded_txo_sum': 0,
|
||||
'spent_txo_count': 0,
|
||||
'spent_txo_sum': 0,
|
||||
'tx_count': 0
|
||||
}
|
||||
});
|
||||
throw new Error('Invalid Bitcoin address');
|
||||
}
|
||||
|
||||
try {
|
||||
|
|
@ -96,7 +80,7 @@ class BitcoindElectrsApi extends BitcoinApi implements AbstractBitcoinApi {
|
|||
async $getAddressTransactions(address: string, lastSeenTxId: string): Promise<IEsploraApi.Transaction[]> {
|
||||
const addressInfo = await this.bitcoindClient.validateAddress(address);
|
||||
if (!addressInfo || !addressInfo.isvalid) {
|
||||
return [];
|
||||
throw new Error('Invalid Bitcoin address');
|
||||
}
|
||||
|
||||
try {
|
||||
|
|
@ -166,7 +150,7 @@ class BitcoindElectrsApi extends BitcoinApi implements AbstractBitcoinApi {
|
|||
async $getAddressUtxos(address: string): Promise<IEsploraApi.UTXO[]> {
|
||||
const addressInfo = await this.bitcoindClient.validateAddress(address);
|
||||
if (!addressInfo || !addressInfo.isvalid) {
|
||||
return [];
|
||||
throw new Error('Invalid Bitcoin address');
|
||||
}
|
||||
const scripthash = this.encodeScriptHash(addressInfo.scriptPubKey);
|
||||
return this.$getScriptHashUtxos(scripthash);
|
||||
|
|
|
|||
|
|
@ -249,11 +249,6 @@
|
|||
<br><br>
|
||||
Consider viewing this address on the official Mempool website instead:
|
||||
</ng-container>
|
||||
} @else if (!officialMempoolSpace) {
|
||||
<br>
|
||||
Consider viewing this address on the official Mempool website instead:
|
||||
}
|
||||
@if (!officialMempoolSpace) {
|
||||
<br>
|
||||
<a href="https://mempool.space/address/{{ addressString }}" target="_blank">https://mempool.space/address/{{ addressString }}</a>
|
||||
<br>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue