diff --git a/backend/src/api/bitcoin/bitcoin-api.ts b/backend/src/api/bitcoin/bitcoin-api.ts index 3b3c704c9..0e7bf22c4 100644 --- a/backend/src/api/bitcoin/bitcoin-api.ts +++ b/backend/src/api/bitcoin/bitcoin-api.ts @@ -33,11 +33,17 @@ class BitcoinApi implements AbstractBitcoinApi { } $getRawTransaction(txId: string, skipConversion = false, addPrevout = false): Promise { - // If the transaction is in the mempool we also already fetched the fee, just prevouts are missing + // If the transaction is in the mempool we already converted and fetched the fee. Only prevouts are missing const txInMempool = mempool.getMempool()[txId]; if (txInMempool && addPrevout) { return this.$addPrevouts(txInMempool); } + + // Special case to fetch the Coinbase transaction + if (txId === '4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b') { + return this.$returnCoinbaseTransaction(); + } + return this.bitcoindClient.getRawTransaction(txId, true) .then((transaction: IBitcoinApi.Transaction) => { if (skipConversion) { @@ -201,6 +207,15 @@ class BitcoinApi implements AbstractBitcoinApi { return transaction; } + protected $returnCoinbaseTransaction(): Promise { + return this.bitcoindClient.getBlock('000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f', 2) + .then((block: IBitcoinApi.Block) => { + return this.$convertTransaction(Object.assign(block.tx[0], { + confirmations: blocks.getCurrentBlockHeight() + 1, + blocktime: 1231006505 }), false); + }); + } + private async $calculateFeeFromInputs(transaction: IEsploraApi.Transaction, addPrevout: boolean): Promise { if (transaction.vin[0].is_coinbase) { transaction.fee = 0; diff --git a/backend/src/api/blocks.ts b/backend/src/api/blocks.ts index a6b181c1e..4258b5260 100644 --- a/backend/src/api/blocks.ts +++ b/backend/src/api/blocks.ts @@ -68,7 +68,7 @@ class Blocks { for (let i = 0; i < txIds.length; i++) { // When using bitcoind, just fetch the coinbase tx for now - if (config.MEMPOOL.BACKEND !== 'none' && i === 0) { + 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 diff --git a/backend/src/api/transaction-utils.ts b/backend/src/api/transaction-utils.ts index d4ca8124b..1b7fda068 100644 --- a/backend/src/api/transaction-utils.ts +++ b/backend/src/api/transaction-utils.ts @@ -31,6 +31,7 @@ class TransactionUtils { return this.extendTransaction(transaction); } catch (e) { logger.debug('getTransactionExtended error: ' + (e.message || e)); + logger.debug(JSON.stringify(e)); return null; } } diff --git a/backend/src/index.ts b/backend/src/index.ts index 775372580..4c753fea7 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -119,6 +119,7 @@ class Server { } else { logger.debug(loggerMsg); } + logger.debug(JSON.stringify(e)); setTimeout(this.runMainUpdateLoop.bind(this), 1000 * this.retryOnElectrsErrorAfterSeconds); this.retryOnElectrsErrorAfterSeconds *= 2; this.retryOnElectrsErrorAfterSeconds = Math.min(this.retryOnElectrsErrorAfterSeconds, 60);