Hack to make it possible to load the Coinbase transaction from Bitcoin Core.

This commit is contained in:
softsimon 2021-01-02 04:40:10 +07:00
parent 89b4de2484
commit a25125091d
No known key found for this signature in database
GPG Key ID: 488D7DCFB5A430D7
4 changed files with 19 additions and 2 deletions

View File

@ -33,11 +33,17 @@ class BitcoinApi implements AbstractBitcoinApi {
}
$getRawTransaction(txId: string, skipConversion = false, addPrevout = false): Promise<IEsploraApi.Transaction> {
// 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<IEsploraApi.Transaction> {
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<IEsploraApi.Transaction> {
if (transaction.vin[0].is_coinbase) {
transaction.fee = 0;

View File

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

View File

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

View File

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