Fetch coinbase tx with core when esplora fails to do so
This commit is contained in:
		
							parent
							
								
									5905eebaa6
								
							
						
					
					
						commit
						9f4107319f
					
				@ -101,12 +101,23 @@ class Blocks {
 | 
			
		||||
          transactions.push(tx);
 | 
			
		||||
          transactionsFetched++;
 | 
			
		||||
        } catch (e) {
 | 
			
		||||
          if (i === 0) {
 | 
			
		||||
            const msg = `Cannot fetch coinbase tx ${txIds[i]}. Reason: ` + (e instanceof Error ? e.message : e); 
 | 
			
		||||
            logger.err(msg);
 | 
			
		||||
            throw new Error(msg);
 | 
			
		||||
          } else {
 | 
			
		||||
            logger.err(`Cannot fetch tx ${txIds[i]}. Reason: ` + (e instanceof Error ? e.message : e));
 | 
			
		||||
          try {
 | 
			
		||||
            if (config.MEMPOOL.BACKEND === 'esplora') {
 | 
			
		||||
              // Try again with core
 | 
			
		||||
              const tx = await transactionUtils.$getTransactionExtended(txIds[i], false, false, true);
 | 
			
		||||
              transactions.push(tx);
 | 
			
		||||
              transactionsFetched++;
 | 
			
		||||
            } else {
 | 
			
		||||
              throw e;
 | 
			
		||||
            }
 | 
			
		||||
          } catch (e) {
 | 
			
		||||
            if (i === 0) {
 | 
			
		||||
              const msg = `Cannot fetch coinbase tx ${txIds[i]}. Reason: ` + (e instanceof Error ? e.message : e); 
 | 
			
		||||
              logger.err(msg);
 | 
			
		||||
              throw new Error(msg);
 | 
			
		||||
            } else {
 | 
			
		||||
              logger.err(`Cannot fetch tx ${txIds[i]}. Reason: ` + (e instanceof Error ? e.message : e));
 | 
			
		||||
            }
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
@ -3,6 +3,7 @@ import { TransactionExtended, TransactionMinerInfo } from '../mempool.interfaces
 | 
			
		||||
import { IEsploraApi } from './bitcoin/esplora-api.interface';
 | 
			
		||||
import config from '../config';
 | 
			
		||||
import { Common } from './common';
 | 
			
		||||
import bitcoinClient from './bitcoin/bitcoin-client';
 | 
			
		||||
 | 
			
		||||
class TransactionUtils {
 | 
			
		||||
  constructor() { }
 | 
			
		||||
@ -21,8 +22,19 @@ class TransactionUtils {
 | 
			
		||||
    };
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public async $getTransactionExtended(txId: string, addPrevouts = false, lazyPrevouts = false): Promise<TransactionExtended> {
 | 
			
		||||
    const transaction: IEsploraApi.Transaction = await bitcoinApi.$getRawTransaction(txId, false, addPrevouts, lazyPrevouts);
 | 
			
		||||
  /**
 | 
			
		||||
   * @param txId 
 | 
			
		||||
   * @param addPrevouts 
 | 
			
		||||
   * @param lazyPrevouts 
 | 
			
		||||
   * @param forceCore - See https://github.com/mempool/mempool/issues/2904
 | 
			
		||||
   */
 | 
			
		||||
  public async $getTransactionExtended(txId: string, addPrevouts = false, lazyPrevouts = false, forceCore = false): Promise<TransactionExtended> {
 | 
			
		||||
    let transaction: IEsploraApi.Transaction;
 | 
			
		||||
    if (forceCore === true) {
 | 
			
		||||
      transaction  = await bitcoinClient.$getRawTransaction(txId, true);
 | 
			
		||||
    } else {
 | 
			
		||||
      transaction  = await bitcoinApi.$getRawTransaction(txId, false, addPrevouts, lazyPrevouts);
 | 
			
		||||
    }
 | 
			
		||||
    return this.extendTransaction(transaction);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user