Disable support for Electrum TX lookups (require -txindex).
This commit is contained in:
parent
5b268794af
commit
47a449e1d9
@ -96,7 +96,6 @@ Edit `mempool-config.json` to add your Bitcoin Core node RPC credentials:
|
|||||||
"HOST": "127.0.0.1",
|
"HOST": "127.0.0.1",
|
||||||
"PORT": 50002,
|
"PORT": 50002,
|
||||||
"TLS_ENABLED": true,
|
"TLS_ENABLED": true,
|
||||||
"TX_LOOKUPS": false
|
|
||||||
},
|
},
|
||||||
"DATABASE": {
|
"DATABASE": {
|
||||||
"ENABLED": true,
|
"ENABLED": true,
|
||||||
|
@ -16,8 +16,7 @@
|
|||||||
"ELECTRUM": {
|
"ELECTRUM": {
|
||||||
"HOST": "127.0.0.1",
|
"HOST": "127.0.0.1",
|
||||||
"PORT": 50002,
|
"PORT": 50002,
|
||||||
"TLS_ENABLED": true,
|
"TLS_ENABLED": true
|
||||||
"TX_LOOKUPS": false
|
|
||||||
},
|
},
|
||||||
"ESPLORA": {
|
"ESPLORA": {
|
||||||
"REST_API_URL": "http://127.0.0.1:3000"
|
"REST_API_URL": "http://127.0.0.1:3000"
|
||||||
|
@ -43,25 +43,6 @@ class BitcoindElectrsApi extends BitcoinApi implements AbstractBitcoinApi {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async $getRawTransaction(txId: string, skipConversion = false, addPrevout = false): Promise<IEsploraApi.Transaction> {
|
|
||||||
if (!config.ELECTRUM.TX_LOOKUPS) {
|
|
||||||
return super.$getRawTransaction(txId, skipConversion, addPrevout);
|
|
||||||
}
|
|
||||||
const txInMempool = mempool.getMempool()[txId];
|
|
||||||
if (txInMempool && addPrevout) {
|
|
||||||
return this.$addPrevouts(txInMempool);
|
|
||||||
}
|
|
||||||
const transaction: IBitcoinApi.Transaction = await this.electrumClient.blockchainTransaction_get(txId, true);
|
|
||||||
if (!transaction) {
|
|
||||||
throw new Error('Unable to get transaction: ' + txId);
|
|
||||||
}
|
|
||||||
if (skipConversion) {
|
|
||||||
// @ts-ignore
|
|
||||||
return transaction;
|
|
||||||
}
|
|
||||||
return this.$convertTransaction(transaction, addPrevout);
|
|
||||||
}
|
|
||||||
|
|
||||||
async $getAddress(address: string): Promise<IEsploraApi.Address> {
|
async $getAddress(address: string): Promise<IEsploraApi.Address> {
|
||||||
const addressInfo = await this.$validateAddress(address);
|
const addressInfo = await this.$validateAddress(address);
|
||||||
if (!addressInfo || !addressInfo.isvalid) {
|
if (!addressInfo || !addressInfo.isvalid) {
|
||||||
|
@ -67,23 +67,6 @@ class Blocks {
|
|||||||
let transactionsFound = 0;
|
let transactionsFound = 0;
|
||||||
|
|
||||||
for (let i = 0; i < txIds.length; i++) {
|
for (let i = 0; i < txIds.length; i++) {
|
||||||
// When using bitcoind, just fetch the coinbase tx for now
|
|
||||||
if (config.MEMPOOL.BACKEND !== 'esplora' && i === 0) {
|
|
||||||
let txFound = false;
|
|
||||||
let findCoinbaseTxTries = 0;
|
|
||||||
// It takes Electrum Server a few seconds to index the transaction after a block is found
|
|
||||||
while (findCoinbaseTxTries < 5 && !txFound) {
|
|
||||||
try {
|
|
||||||
const tx = await transactionUtils.$getTransactionExtended(txIds[i]);
|
|
||||||
txFound = true;
|
|
||||||
transactions.push(tx);
|
|
||||||
} catch (e) {
|
|
||||||
logger.debug('Coinbase transaction fetch error: ' + e.message || e);
|
|
||||||
await Common.sleep(1000);
|
|
||||||
findCoinbaseTxTries++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (mempool[txIds[i]]) {
|
if (mempool[txIds[i]]) {
|
||||||
transactions.push(mempool[txIds[i]]);
|
transactions.push(mempool[txIds[i]]);
|
||||||
transactionsFound++;
|
transactionsFound++;
|
||||||
|
@ -104,7 +104,7 @@ class Mempool {
|
|||||||
for (const txid of transactions) {
|
for (const txid of transactions) {
|
||||||
if (!this.mempoolCache[txid]) {
|
if (!this.mempoolCache[txid]) {
|
||||||
try {
|
try {
|
||||||
const transaction = await transactionUtils.$getTransactionExtended(txid, true);
|
const transaction = await transactionUtils.$getTransactionExtended(txid);
|
||||||
this.mempoolCache[txid] = transaction;
|
this.mempoolCache[txid] = transaction;
|
||||||
txCount++;
|
txCount++;
|
||||||
if (this.inSync) {
|
if (this.inSync) {
|
||||||
|
@ -20,13 +20,8 @@ class TransactionUtils {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public async $getTransactionExtended(txId: string, forceBitcoind = false, addPrevouts = false): Promise<TransactionExtended> {
|
public async $getTransactionExtended(txId: string, addPrevouts = false): Promise<TransactionExtended> {
|
||||||
let transaction: IEsploraApi.Transaction;
|
const transaction: IEsploraApi.Transaction = await bitcoinApi.$getRawTransaction(txId, false, addPrevouts);
|
||||||
if (forceBitcoind) {
|
|
||||||
transaction = await bitcoinApi.$getRawTransactionBitcoind(txId, false, addPrevouts);
|
|
||||||
} else {
|
|
||||||
transaction = await bitcoinApi.$getRawTransaction(txId, false, addPrevouts);
|
|
||||||
}
|
|
||||||
return this.extendTransaction(transaction);
|
return this.extendTransaction(transaction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -220,7 +220,7 @@ class WebsocketHandler {
|
|||||||
if (tx) {
|
if (tx) {
|
||||||
if (config.MEMPOOL.BACKEND !== 'esplora') {
|
if (config.MEMPOOL.BACKEND !== 'esplora') {
|
||||||
try {
|
try {
|
||||||
const fullTx = await transactionUtils.$getTransactionExtended(tx.txid, false, true);
|
const fullTx = await transactionUtils.$getTransactionExtended(tx.txid, true);
|
||||||
response['tx'] = fullTx;
|
response['tx'] = fullTx;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.debug('Error finding transaction in mempool: ' + e.message || e);
|
logger.debug('Error finding transaction in mempool: ' + e.message || e);
|
||||||
@ -240,7 +240,7 @@ class WebsocketHandler {
|
|||||||
if (someVin) {
|
if (someVin) {
|
||||||
if (config.MEMPOOL.BACKEND !== 'esplora') {
|
if (config.MEMPOOL.BACKEND !== 'esplora') {
|
||||||
try {
|
try {
|
||||||
const fullTx = await transactionUtils.$getTransactionExtended(tx.txid, false, true);
|
const fullTx = await transactionUtils.$getTransactionExtended(tx.txid, true);
|
||||||
foundTransactions.push(fullTx);
|
foundTransactions.push(fullTx);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.debug('Error finding transaction in mempool: ' + e.message || e);
|
logger.debug('Error finding transaction in mempool: ' + e.message || e);
|
||||||
@ -254,7 +254,7 @@ class WebsocketHandler {
|
|||||||
if (someVout) {
|
if (someVout) {
|
||||||
if (config.MEMPOOL.BACKEND !== 'esplora') {
|
if (config.MEMPOOL.BACKEND !== 'esplora') {
|
||||||
try {
|
try {
|
||||||
const fullTx = await transactionUtils.$getTransactionExtended(tx.txid, false, true);
|
const fullTx = await transactionUtils.$getTransactionExtended(tx.txid, true);
|
||||||
foundTransactions.push(fullTx);
|
foundTransactions.push(fullTx);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.debug('Error finding transaction in mempool: ' + e.message || e);
|
logger.debug('Error finding transaction in mempool: ' + e.message || e);
|
||||||
@ -305,7 +305,7 @@ class WebsocketHandler {
|
|||||||
const rbfTx = rbfTransactions[rbfTransaction];
|
const rbfTx = rbfTransactions[rbfTransaction];
|
||||||
if (config.MEMPOOL.BACKEND !== 'esplora') {
|
if (config.MEMPOOL.BACKEND !== 'esplora') {
|
||||||
try {
|
try {
|
||||||
const fullTx = await transactionUtils.$getTransactionExtended(rbfTransaction, false, true);
|
const fullTx = await transactionUtils.$getTransactionExtended(rbfTransaction, true);
|
||||||
response['rbfTransaction'] = fullTx;
|
response['rbfTransaction'] = fullTx;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.debug('Error finding transaction in mempool: ' + e.message || e);
|
logger.debug('Error finding transaction in mempool: ' + e.message || e);
|
||||||
|
@ -16,7 +16,6 @@ interface IConfig {
|
|||||||
HOST: string;
|
HOST: string;
|
||||||
PORT: number;
|
PORT: number;
|
||||||
TLS_ENABLED: boolean;
|
TLS_ENABLED: boolean;
|
||||||
TX_LOOKUPS: boolean;
|
|
||||||
};
|
};
|
||||||
CORE_RPC: {
|
CORE_RPC: {
|
||||||
HOST: string;
|
HOST: string;
|
||||||
@ -76,7 +75,6 @@ const defaults: IConfig = {
|
|||||||
'HOST': '127.0.0.1',
|
'HOST': '127.0.0.1',
|
||||||
'PORT': 3306,
|
'PORT': 3306,
|
||||||
'TLS_ENABLED': true,
|
'TLS_ENABLED': true,
|
||||||
'TX_LOOKUPS': false
|
|
||||||
},
|
},
|
||||||
'CORE_RPC': {
|
'CORE_RPC': {
|
||||||
'HOST': '127.0.0.1',
|
'HOST': '127.0.0.1',
|
||||||
|
@ -531,7 +531,7 @@ class Routes {
|
|||||||
|
|
||||||
public async getTransaction(req: Request, res: Response) {
|
public async getTransaction(req: Request, res: Response) {
|
||||||
try {
|
try {
|
||||||
const transaction = await transactionUtils.$getTransactionExtended(req.params.txId, false, true);
|
const transaction = await transactionUtils.$getTransactionExtended(req.params.txId, true);
|
||||||
res.json(transaction);
|
res.json(transaction);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
let statusCode = 500;
|
let statusCode = 500;
|
||||||
@ -599,7 +599,7 @@ class Routes {
|
|||||||
const endIndex = Math.min(startingIndex + 10, txIds.length);
|
const endIndex = Math.min(startingIndex + 10, txIds.length);
|
||||||
for (let i = startingIndex; i < endIndex; i++) {
|
for (let i = startingIndex; i < endIndex; i++) {
|
||||||
try {
|
try {
|
||||||
const transaction = await transactionUtils.$getTransactionExtended(txIds[i], false, true);
|
const transaction = await transactionUtils.$getTransactionExtended(txIds[i], true);
|
||||||
transactions.push(transaction);
|
transactions.push(transaction);
|
||||||
loadingIndicators.setProgress('blocktxs-' + req.params.hash, (i + 1) / endIndex * 100);
|
loadingIndicators.setProgress('blocktxs-' + req.params.hash, (i + 1) / endIndex * 100);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user