Add electrs sync progress updates

This commit is contained in:
Mononaut
2023-07-24 14:59:51 +09:00
parent db715a1dba
commit e59c961f25
4 changed files with 33 additions and 34 deletions

View File

@@ -3,7 +3,7 @@ import { IEsploraApi } from './esplora-api.interface';
export interface AbstractBitcoinApi {
$getRawMempool(): Promise<IEsploraApi.Transaction['txid'][]>;
$getRawTransaction(txId: string, skipConversion?: boolean, addPrevout?: boolean, lazyPrevouts?: boolean): Promise<IEsploraApi.Transaction>;
$getMempoolTransactions(expectedCount: number);
$getMempoolTransactions(lastTxid: string);
$getTransactionHex(txId: string): Promise<string>;
$getBlockHeightTip(): Promise<number>;
$getBlockHashTip(): Promise<string>;

View File

@@ -59,7 +59,7 @@ class BitcoinApi implements AbstractBitcoinApi {
});
}
$getMempoolTransactions(expectedCount: number): Promise<IEsploraApi.Transaction[]> {
$getMempoolTransactions(lastTxid: string): Promise<IEsploraApi.Transaction[]> {
return Promise.resolve([]);
}

View File

@@ -69,33 +69,8 @@ class ElectrsApi implements AbstractBitcoinApi {
return this.$queryWrapper<IEsploraApi.Transaction>(config.ESPLORA.REST_API_URL + '/tx/' + txId);
}
async $getMempoolTransactions(expectedCount: number): Promise<IEsploraApi.Transaction[]> {
const transactions: IEsploraApi.Transaction[] = [];
let count = 0;
let done = false;
let last_txid = '';
while (!done) {
try {
const result = await this.$queryWrapper<IEsploraApi.Transaction[]>(config.ESPLORA.REST_API_URL + '/mempool/txs' + (last_txid ? '/' + last_txid : ''));
if (result) {
for (const tx of result) {
transactions.push(tx);
count++;
}
logger.info(`Fetched ${count} of ${expectedCount} mempool transactions from esplora`);
if (result.length > 0) {
last_txid = result[result.length - 1].txid;
} else {
done = true;
}
} else {
done = true;
}
} catch(err) {
logger.err('failed to fetch bulk mempool transactions from esplora');
}
}
return transactions;
async $getMempoolTransactions(lastSeenTxid?: string): Promise<IEsploraApi.Transaction[]> {
return this.$queryWrapper<IEsploraApi.Transaction[]>(config.ESPLORA.REST_API_URL + '/mempool/txs' + (lastSeenTxid ? '/' + lastSeenTxid : ''));
}
$getTransactionHex(txId: string): Promise<string> {