2023-05-30 19:35:39 -04:00
|
|
|
import config from '../../config';
|
2023-12-06 12:09:46 +00:00
|
|
|
import logger from '../../logger';
|
2023-06-03 16:54:12 -04:00
|
|
|
import { BlockExtended, PoolTag } from '../../mempool.interfaces';
|
2023-12-06 12:09:46 +00:00
|
|
|
import axios from 'axios';
|
2023-05-30 19:35:39 -04:00
|
|
|
|
|
|
|
export interface Acceleration {
|
|
|
|
txid: string,
|
|
|
|
feeDelta: number,
|
2023-06-13 17:03:36 -04:00
|
|
|
pools: number[],
|
2023-05-30 19:35:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
class AccelerationApi {
|
2023-12-06 12:09:46 +00:00
|
|
|
public async $fetchAccelerations(): Promise<Acceleration[] | null> {
|
2023-05-30 19:35:39 -04:00
|
|
|
if (config.MEMPOOL_SERVICES.ACCELERATIONS) {
|
2023-12-06 12:09:46 +00:00
|
|
|
try {
|
|
|
|
const response = await axios.get(`${config.MEMPOOL_SERVICES.API}/accelerator/accelerations`, { responseType: 'json', timeout: 10000 });
|
|
|
|
return response.data as Acceleration[];
|
|
|
|
} catch (e) {
|
|
|
|
logger.warn('Failed to fetch current accelerations from the mempool services backend: ' + (e instanceof Error ? e.message : e));
|
|
|
|
return null;
|
|
|
|
}
|
2023-05-30 19:35:39 -04:00
|
|
|
} else {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
}
|
2023-06-03 16:54:12 -04:00
|
|
|
|
2023-06-13 17:03:36 -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
|
|
|
}
|
2023-06-13 17:03:36 -04:00
|
|
|
return anyAccelerated;
|
2023-06-03 16:54:12 -04:00
|
|
|
}
|
2023-05-30 19:35:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export default new AccelerationApi();
|