Adding latest blocks and transactions to dashboard.

This commit is contained in:
softsimon
2020-09-26 02:11:30 +07:00
parent aa3559e634
commit d4f768e3b6
10 changed files with 135 additions and 9 deletions

View File

@@ -1,6 +1,7 @@
const config = require('../../mempool-config.json');
import bitcoinApi from './bitcoin/electrs-api';
import { MempoolInfo, TransactionExtended, Transaction, VbytesPerSecond } from '../interfaces';
import { Common } from './common';
class Mempool {
private inSync: boolean = false;
@@ -15,6 +16,7 @@ class Mempool {
private vBytesPerSecondArray: VbytesPerSecond[] = [];
private vBytesPerSecond: number = 0;
private mempoolProtection = 0;
private latestTransactions: any[] = [];
constructor() {
setInterval(this.updateTxPerSecond.bind(this), 1000);
@@ -24,6 +26,10 @@ class Mempool {
return this.inSync;
}
public getLatestTransactions() {
return this.latestTransactions;
}
public setMempoolChangedCallback(fn: (newMempool: { [txId: string]: TransactionExtended; },
newTransactions: TransactionExtended[], deletedTransactions: TransactionExtended[]) => void) {
this.mempoolChangedCallback = fn;
@@ -159,6 +165,9 @@ class Mempool {
newMempool = this.mempoolCache;
}
const newTransactionsStripped = newTransactions.map((tx) => Common.stripTransaction(tx));
this.latestTransactions = newTransactionsStripped.concat(this.latestTransactions).slice(0, 6);
if (!this.inSync && transactions.length === Object.keys(newMempool).length) {
this.inSync = true;
console.log('The mempool is now in sync!');