Amount of projected blocks is now a config.
This commit is contained in:
parent
8dd58db42a
commit
76f8af9048
@ -13,6 +13,7 @@
|
|||||||
"CHAT_SSL_CHAIN": "",
|
"CHAT_SSL_CHAIN": "",
|
||||||
"MEMPOOL_REFRESH_RATE_MS": 500,
|
"MEMPOOL_REFRESH_RATE_MS": 500,
|
||||||
"INITIAL_BLOCK_AMOUNT": 8,
|
"INITIAL_BLOCK_AMOUNT": 8,
|
||||||
|
"DEFAULT_PROJECTED_BLOCKS_AMOUNT": 3,
|
||||||
"KEEP_BLOCK_AMOUNT": 24,
|
"KEEP_BLOCK_AMOUNT": 24,
|
||||||
"BITCOIN_NODE_HOST": "localhost",
|
"BITCOIN_NODE_HOST": "localhost",
|
||||||
"BITCOIN_NODE_PORT": 18332,
|
"BITCOIN_NODE_PORT": 18332,
|
||||||
|
@ -1,29 +1,13 @@
|
|||||||
|
const config = require('../../mempool-config.json');
|
||||||
import { ITransaction, IProjectedBlock, IMempool, IProjectedBlockInternal } from '../interfaces';
|
import { ITransaction, IProjectedBlock, IMempool, IProjectedBlockInternal } from '../interfaces';
|
||||||
|
|
||||||
class ProjectedBlocks {
|
class ProjectedBlocks {
|
||||||
private projectedBlocks: IProjectedBlockInternal[] = [];
|
private transactionsSorted: ITransaction[] = [];
|
||||||
|
|
||||||
constructor() {}
|
constructor() {}
|
||||||
|
|
||||||
public getProjectedBlocks(txId?: string): IProjectedBlock[] {
|
|
||||||
return this.projectedBlocks.map((projectedBlock) => {
|
|
||||||
return {
|
|
||||||
blockSize: projectedBlock.blockSize,
|
|
||||||
blockWeight: projectedBlock.blockWeight,
|
|
||||||
nTx: projectedBlock.nTx,
|
|
||||||
minFee: projectedBlock.minFee,
|
|
||||||
maxFee: projectedBlock.maxFee,
|
|
||||||
minWeightFee: projectedBlock.minWeightFee,
|
|
||||||
maxWeightFee: projectedBlock.maxWeightFee,
|
|
||||||
medianFee: projectedBlock.medianFee,
|
|
||||||
fees: projectedBlock.fees,
|
|
||||||
hasMytx: txId ? projectedBlock.txIds.some((tx) => tx === txId) : false
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public getProjectedBlockFeesForBlock(index: number) {
|
public getProjectedBlockFeesForBlock(index: number) {
|
||||||
const projectedBlock = this.projectedBlocks[index];
|
const projectedBlock = this.getProjectedBlocksInternal()[index];
|
||||||
|
|
||||||
if (!projectedBlock) {
|
if (!projectedBlock) {
|
||||||
throw new Error('No projected block for that index');
|
throw new Error('No projected block for that index');
|
||||||
@ -42,20 +26,34 @@ class ProjectedBlocks {
|
|||||||
memPoolArray.push(latestMempool[i]);
|
memPoolArray.push(latestMempool[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
memPoolArray.sort((a, b) => b.feePerWeightUnit - a.feePerWeightUnit);
|
||||||
if (!memPoolArray.length) {
|
this.transactionsSorted = memPoolArray.filter((tx) => tx.feePerWeightUnit);
|
||||||
this.projectedBlocks = [];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
memPoolArray.sort((a, b) => b.feePerWeightUnit - a.feePerWeightUnit);
|
public getProjectedBlocks(txId?: string, numberOfBlocks: number = config.DEFAULT_PROJECTED_BLOCKS_AMOUNT): IProjectedBlock[] {
|
||||||
const memPoolArrayFiltered = memPoolArray.filter((tx) => tx.feePerWeightUnit);
|
return this.getProjectedBlocksInternal(numberOfBlocks).map((projectedBlock) => {
|
||||||
const projectedBlocks: any = [];
|
return {
|
||||||
|
blockSize: projectedBlock.blockSize,
|
||||||
|
blockWeight: projectedBlock.blockWeight,
|
||||||
|
nTx: projectedBlock.nTx,
|
||||||
|
minFee: projectedBlock.minFee,
|
||||||
|
maxFee: projectedBlock.maxFee,
|
||||||
|
minWeightFee: projectedBlock.minWeightFee,
|
||||||
|
maxWeightFee: projectedBlock.maxWeightFee,
|
||||||
|
medianFee: projectedBlock.medianFee,
|
||||||
|
fees: projectedBlock.fees,
|
||||||
|
hasMytx: txId ? projectedBlock.txIds.some((tx) => tx === txId) : false
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private getProjectedBlocksInternal(numberOfBlocks: number = config.DEFAULT_PROJECTED_BLOCKS_AMOUNT): IProjectedBlockInternal[] {
|
||||||
|
const projectedBlocks: IProjectedBlockInternal[] = [];
|
||||||
let blockWeight = 0;
|
let blockWeight = 0;
|
||||||
let blockSize = 0;
|
let blockSize = 0;
|
||||||
let transactions: ITransaction[] = [];
|
let transactions: ITransaction[] = [];
|
||||||
memPoolArrayFiltered.forEach((tx) => {
|
this.transactionsSorted.forEach((tx) => {
|
||||||
if (blockWeight + tx.vsize * 4 < 4000000 || projectedBlocks.length === 3) {
|
if (blockWeight + tx.vsize * 4 < 4000000 || projectedBlocks.length === numberOfBlocks) {
|
||||||
blockWeight += tx.vsize * 4;
|
blockWeight += tx.vsize * 4;
|
||||||
blockSize += tx.size;
|
blockSize += tx.size;
|
||||||
transactions.push(tx);
|
transactions.push(tx);
|
||||||
@ -69,7 +67,7 @@ class ProjectedBlocks {
|
|||||||
if (transactions.length) {
|
if (transactions.length) {
|
||||||
projectedBlocks.push(this.dataToProjectedBlock(transactions, blockSize, blockWeight));
|
projectedBlocks.push(this.dataToProjectedBlock(transactions, blockSize, blockWeight));
|
||||||
}
|
}
|
||||||
this.projectedBlocks = projectedBlocks;
|
return projectedBlocks;
|
||||||
}
|
}
|
||||||
|
|
||||||
private dataToProjectedBlock(transactions: ITransaction[], blockSize: number, blockWeight: number): IProjectedBlockInternal {
|
private dataToProjectedBlock(transactions: ITransaction[], blockSize: number, blockWeight: number): IProjectedBlockInternal {
|
||||||
|
@ -44,7 +44,9 @@ export class ApiService {
|
|||||||
this.memPoolService.blocks$.next(response.block);
|
this.memPoolService.blocks$.next(response.block);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response.projectedBlocks) {
|
if (response.projectedBlocks && response.projectedBlocks.length) {
|
||||||
|
const mempoolWeight = response.projectedBlocks.map((block: any) => block.blockWeight).reduce((a: any, b: any) => a + b);
|
||||||
|
this.memPoolService.mempoolWeight$.next(mempoolWeight);
|
||||||
this.memPoolService.projectedBlocks$.next(response.projectedBlocks);
|
this.memPoolService.projectedBlocks$.next(response.projectedBlocks);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,11 +62,6 @@ export class ApiService {
|
|||||||
this.memPoolService.conversions$.next(response.conversions);
|
this.memPoolService.conversions$.next(response.conversions);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response.projectedBlocks) {
|
|
||||||
const mempoolWeight = response.projectedBlocks.map((block: any) => block.blockWeight).reduce((a: any, b: any) => a + b);
|
|
||||||
this.memPoolService.mempoolWeight$.next(mempoolWeight);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (response['track-tx']) {
|
if (response['track-tx']) {
|
||||||
let txTrackingEnabled;
|
let txTrackingEnabled;
|
||||||
let txTrackingBlockHeight;
|
let txTrackingBlockHeight;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user