mempool/backend/src/api/services/acceleration.ts

30 lines
923 B
TypeScript
Raw Normal View History

2023-05-30 19:35:39 -04:00
import { query } from '../../utils/axios-query';
import config from '../../config';
2023-06-03 16:54:12 -04:00
import { BlockExtended, PoolTag } from '../../mempool.interfaces';
2023-05-30 19:35:39 -04:00
export interface Acceleration {
txid: string,
feeDelta: number,
pools: number[],
2023-05-30 19:35:39 -04:00
}
class AccelerationApi {
2023-06-03 16:54:12 -04:00
public async $fetchAccelerations(): Promise<Acceleration[]> {
2023-05-30 19:35:39 -04:00
if (config.MEMPOOL_SERVICES.ACCELERATIONS) {
const response = await query(`${config.MEMPOOL_SERVICES.API}/accelerations`);
return (response as Acceleration[]) || [];
} else {
return [];
}
}
2023-06-03 16:54:12 -04:00
public isAcceleratedBlock(block: BlockExtended, accelerations: Acceleration[]): boolean {
let anyAccelerated = false;
for (let i = 0; i < accelerations.length && !anyAccelerated; i++) {
anyAccelerated = anyAccelerated || accelerations[i].pools?.includes(block.extras.pool.id);
2023-06-03 16:54:12 -04:00
}
return anyAccelerated;
2023-06-03 16:54:12 -04:00
}
2023-05-30 19:35:39 -04:00
}
export default new AccelerationApi();