Track and display purged transaction status
This commit is contained in:
@@ -16,6 +16,7 @@ class Mempool {
|
||||
private inSync: boolean = false;
|
||||
private mempoolCacheDelta: number = -1;
|
||||
private mempoolCache: { [txId: string]: TransactionExtended } = {};
|
||||
private minFeeMempool: { [txId: string]: boolean } = {};
|
||||
private mempoolInfo: IBitcoinApi.MempoolInfo = { loaded: false, size: 0, bytes: 0, usage: 0, total_fee: 0,
|
||||
maxmempool: 300000000, mempoolminfee: 0.00001000, minrelaytxfee: 0.00001000 };
|
||||
private mempoolChangedCallback: ((newMempool: {[txId: string]: TransactionExtended; }, newTransactions: TransactionExtended[],
|
||||
@@ -124,6 +125,7 @@ class Mempool {
|
||||
let hasChange: boolean = false;
|
||||
const currentMempoolSize = Object.keys(this.mempoolCache).length;
|
||||
const transactions = await bitcoinApi.$getRawMempool();
|
||||
await this.updateMinFeeMempool();
|
||||
const diff = transactions.length - currentMempoolSize;
|
||||
const newTransactions: TransactionExtended[] = [];
|
||||
|
||||
@@ -232,6 +234,34 @@ class Mempool {
|
||||
logger.debug(`Mempool updated in ${time / 1000} seconds. New size: ${Object.keys(this.mempoolCache).length} (${diff > 0 ? '+' + diff : diff})`);
|
||||
}
|
||||
|
||||
public isTxPurged(txid: string): boolean {
|
||||
return !this.minFeeMempool[txid];
|
||||
}
|
||||
|
||||
private async updateMinFeeMempool() {
|
||||
const minFeeTransactions = await bitcoinSecondClient.getRawMemPool();
|
||||
const minFeeTxMap = {};
|
||||
for (const txid of minFeeTransactions) {
|
||||
minFeeTxMap[txid] = true;
|
||||
}
|
||||
const removed: string[] = [];
|
||||
const added: string[] = [];
|
||||
for (const txid of Object.keys(this.minFeeMempool)) {
|
||||
if (!minFeeTxMap[txid]) {
|
||||
removed.push(txid);
|
||||
}
|
||||
}
|
||||
for (const txid of minFeeTransactions) {
|
||||
if (!this.minFeeMempool[txid]) {
|
||||
added.push(txid);
|
||||
this.minFeeMempool[txid] = true;
|
||||
}
|
||||
}
|
||||
for (const txid of removed) {
|
||||
delete this.minFeeMempool[txid];
|
||||
}
|
||||
}
|
||||
|
||||
public handleRbfTransactions(rbfTransactions: { [txid: string]: TransactionExtended; }) {
|
||||
for (const rbfTransaction in rbfTransactions) {
|
||||
if (this.mempoolCache[rbfTransaction]) {
|
||||
|
||||
@@ -19,6 +19,7 @@ import BlocksAuditsRepository from '../repositories/BlocksAuditsRepository';
|
||||
import BlocksSummariesRepository from '../repositories/BlocksSummariesRepository';
|
||||
import Audit from './audit';
|
||||
import { deepClone } from '../utils/clone';
|
||||
import mempool from './mempool';
|
||||
import priceUpdater from '../tasks/price-updater';
|
||||
import { ApiPrice } from '../repositories/PricesRepository';
|
||||
|
||||
@@ -92,6 +93,9 @@ class WebsocketHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (config.MEMPOOL.USE_SECOND_NODE_FOR_MINFEE && memPool.getMempool()[client['track-tx']]) {
|
||||
response['txPurged'] = memPool.isTxPurged(client['track-tx']);
|
||||
}
|
||||
} else {
|
||||
client['track-tx'] = null;
|
||||
}
|
||||
@@ -395,6 +399,11 @@ class WebsocketHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// update purge status of unconfirmed tracked txs
|
||||
if (config.MEMPOOL.USE_SECOND_NODE_FOR_MINFEE && newMempool[client['track-tx']]) {
|
||||
response['txPurged'] = memPool.isTxPurged(client['track-tx']);
|
||||
}
|
||||
}
|
||||
|
||||
if (client['track-mempool-block'] >= 0) {
|
||||
|
||||
Reference in New Issue
Block a user