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,
|
2024-04-04 09:42:49 +00:00
|
|
|
added: number,
|
|
|
|
effectiveVsize: number,
|
|
|
|
effectiveFee: number,
|
2023-05-30 19:35:39 -04:00
|
|
|
feeDelta: number,
|
2023-06-13 17:03:36 -04:00
|
|
|
pools: number[],
|
2024-02-02 02:25:49 +00:00
|
|
|
positions?: {
|
|
|
|
[pool: number]: {
|
|
|
|
block: number,
|
|
|
|
vbytes: number,
|
|
|
|
},
|
|
|
|
},
|
2024-03-11 21:19:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export interface AccelerationHistory {
|
|
|
|
txid: string,
|
|
|
|
status: string,
|
|
|
|
feePaid: number,
|
|
|
|
added: number,
|
|
|
|
lastUpdated: number,
|
|
|
|
baseFee: number,
|
|
|
|
vsizeFee: number,
|
|
|
|
effectiveFee: number,
|
|
|
|
effectiveVsize: number,
|
|
|
|
feeDelta: number,
|
|
|
|
blockHash: string,
|
|
|
|
blockHeight: number,
|
|
|
|
pools: {
|
|
|
|
pool_unique_id: number,
|
|
|
|
username: string,
|
|
|
|
}[],
|
|
|
|
};
|
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
|
|
|
|
2024-03-11 21:19:03 +00:00
|
|
|
public async $fetchAccelerationHistory(page?: number, status?: string): Promise<AccelerationHistory[] | null> {
|
|
|
|
if (config.MEMPOOL_SERVICES.ACCELERATIONS) {
|
|
|
|
try {
|
|
|
|
const response = await axios.get(`${config.MEMPOOL_SERVICES.API}/accelerator/accelerations/history`, {
|
|
|
|
responseType: 'json',
|
|
|
|
timeout: 10000,
|
|
|
|
params: {
|
|
|
|
page,
|
|
|
|
status,
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return response.data as AccelerationHistory[];
|
|
|
|
} catch (e) {
|
|
|
|
logger.warn('Failed to fetch acceleration history from the mempool services backend: ' + (e instanceof Error ? e.message : e));
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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();
|