All files / src/services/ProviderTracker TrackedRewardAccountInfoProvider.ts

70.83% Statements 17/24
100% Branches 0/0
50% Functions 5/10
77.27% Lines 17/22

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 44 45 46 47 4842x 42x     42x 133x 133x 133x     120x 120x 120x                     42x 133x           133x   133x   133x 214x 214x       133x              
import { BehaviorSubject } from 'rxjs';
import { CLEAN_FN_STATS, ProviderFnStats, ProviderTracker } from './ProviderTracker';
import { RewardAccountInfoProvider } from '@cardano-sdk/core';
 
export class RewardAccountInfoProviderStats {
  readonly healthCheck$ = new BehaviorSubject<ProviderFnStats>(CLEAN_FN_STATS);
  readonly rewardAccountInfo$ = new BehaviorSubject<ProviderFnStats>(CLEAN_FN_STATS);
  readonly delegationPortfolio$ = new BehaviorSubject<ProviderFnStats>(CLEAN_FN_STATS);
 
  shutdown() {
    this.healthCheck$.complete();
    this.rewardAccountInfo$.complete();
    this.delegationPortfolio$.complete();
  }
 
  reset() {
    this.healthCheck$.next(CLEAN_FN_STATS);
    this.rewardAccountInfo$.next(CLEAN_FN_STATS);
    this.delegationPortfolio$.next(CLEAN_FN_STATS);
  }
}
 
/** Wraps a RewardAccountInfoProvider, tracking # of calls of each function */
export class TrackedRewardAccountInfoProvider extends ProviderTracker implements RewardAccountInfoProvider {
  readonly stats = new RewardAccountInfoProviderStats();
  readonly healthCheck: RewardAccountInfoProvider['healthCheck'];
  readonly rewardAccountInfo: RewardAccountInfoProvider['rewardAccountInfo'];
  readonly delegationPortfolio: RewardAccountInfoProvider['delegationPortfolio'];
 
  constructor(rewardAccountInfoProvider: RewardAccountInfoProvider) {
    super();
 
    this.healthCheck = () => this.trackedCall(() => rewardAccountInfoProvider.healthCheck(), this.stats.healthCheck$);
 
    this.rewardAccountInfo = (rewardAccount, localEpoch) =>
      this.trackedCall(
        () => rewardAccountInfoProvider.rewardAccountInfo(rewardAccount, localEpoch),
        this.stats.rewardAccountInfo$
      );
 
    this.delegationPortfolio = (rewardAccount) =>
      this.trackedCall(
        () => rewardAccountInfoProvider.delegationPortfolio(rewardAccount),
        this.stats.delegationPortfolio$
      );
  }
}