Merge pull request #6362 from mempool/knorrium/electrum_address_validation

Fix electrum address validation
This commit is contained in:
mononaut 2026-03-06 20:21:19 +09:00 committed by GitHub
commit 54eae4ee7b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 15 additions and 24 deletions

View file

@ -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;

View file

@ -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);

View file

@ -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>