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 | 2x 2x 2x 2x 2x 2x 10x 10x 10x 10x 10x 10x | import * as Queries from './queries';
import { Cardano } from '@cardano-sdk/core';
import { Logger } from 'ts-log';
import { Pool, QueryResult } from 'pg';
export class RewardsFixtureBuilder {
#db: Pool;
#logger: Logger;
constructor(db: Pool, logger: Logger) {
this.#db = db;
this.#logger = logger;
}
public async getRewardAccounts(desiredQty: number): Promise<Cardano.RewardAccount[]> {
this.#logger.debug(`About to fetch up to the last ${desiredQty} reward accounts`);
const result: QueryResult<{ address: string }> = await this.#db.query(Queries.stakeAddress, [desiredQty]);
const resultsQty = result.rows.length;
Iif (result.rows.length === 0) {
throw new Error('No accounts found');
} else Iif (resultsQty < desiredQty) {
this.#logger.warn(`${desiredQty} reward accounts desired, only ${resultsQty} results found`);
}
return result.rows.map(({ address }) => address as unknown as Cardano.RewardAccount);
}
}
|