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

38 lines
1.1 KiB
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,
}
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 async $fetchPools(): Promise<PoolTag[]> {
if (config.MEMPOOL_SERVICES.ACCELERATIONS) {
const response = await query(`${config.MEMPOOL_SERVICES.API}/partners`);
return (response as PoolTag[]) || [];
} else {
return [];
}
}
public async $isAcceleratedBlock(block: BlockExtended): Promise<boolean> {
const pools = await this.$fetchPools();
if (block?.extras?.pool?.id == null) {
return false;
}
return pools.reduce((match, tag) => match || tag.uniqueId === block.extras.pool.id, false);
}
2023-05-30 19:35:39 -04:00
}
export default new AccelerationApi();