Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | 37x 37x 37x 37x 37x 1x 1x 37x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 1x | import { CustomError } from 'ts-custom-error';
import { MissingProgramOption } from '../Program/errors/MissingProgramOption';
import { POOL_DELIST_SCHEDULE, PoolDelistedEntity } from '@cardano-sdk/projection-typeorm';
import { WorkerHandlerFactory } from './types';
import { createSmashStakePoolDelistedService } from '../StakePool/HttpStakePoolMetadata/SmashStakePoolDelistedService';
const createService = (smashUrl: string | undefined) => {
Iif (!smashUrl) throw new MissingProgramOption(POOL_DELIST_SCHEDULE, 'smash-url');
return createSmashStakePoolDelistedService(smashUrl);
};
export const stakePoolBatchDelistHandlerFactory: WorkerHandlerFactory = (options) => {
const { logger, smashUrl, dataSource } = options;
const service = createService(smashUrl);
const repo = dataSource.getRepository(PoolDelistedEntity);
return async (_data: unknown) => {
logger.info(`Getting list of delisted stake pools from ${smashUrl}`);
const delists = await service.getDelistedStakePoolIds();
Iif (delists instanceof CustomError) {
logger.error(`Failed to get the list of delisted stake pools from ${smashUrl}`);
throw delists;
} else {
logger.info(`Got the list of delisted stake pools from ${smashUrl}, size:${delists.length}`);
if (delists.length > 0) {
await dataSource.manager.transaction(async (transaction) => {
logger.info('Updating delisted stake pools data');
await transaction.clear(PoolDelistedEntity);
await transaction.save(delists.map((stakePoolId) => repo.create({ stakePoolId })));
});
} else E{
logger.info('Clearing delisted stake pools data');
await repo.clear();
}
logger.info('Delisted stake pools data is updated');
}
};
};
|