Refactor accelerated audits

This commit is contained in:
Mononaut
2023-06-03 16:54:12 -04:00
parent 20b3ceab1e
commit 083bfdba06
5 changed files with 50 additions and 21 deletions

View File

@@ -1,5 +1,6 @@
import { query } from '../../utils/axios-query';
import config from '../../config';
import { BlockExtended, PoolTag } from '../../mempool.interfaces';
export interface Acceleration {
txid: string,
@@ -7,7 +8,7 @@ export interface Acceleration {
}
class AccelerationApi {
public async fetchAccelerations$(): Promise<Acceleration[]> {
public async $fetchAccelerations(): Promise<Acceleration[]> {
if (config.MEMPOOL_SERVICES.ACCELERATIONS) {
const response = await query(`${config.MEMPOOL_SERVICES.API}/accelerations`);
return (response as Acceleration[]) || [];
@@ -15,6 +16,23 @@ class AccelerationApi {
return [];
}
}
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);
}
}
export default new AccelerationApi();