All files / src/services/ProviderTracker TrackedDrepProvider.ts

72.72% Statements 16/22
100% Branches 0/0
50% Functions 5/10
87.5% Lines 14/16

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 3643x 43x     43x 130x 130x     119x 119x                   43x 130x           130x 130x   130x 130x 193x      
import { BehaviorSubject } from 'rxjs';
import { CLEAN_FN_STATS, ProviderFnStats, ProviderTracker } from './ProviderTracker';
import { DRepProvider } from '@cardano-sdk/core';
 
export class DrepProviderStats {
  readonly healthCheck$ = new BehaviorSubject<ProviderFnStats>(CLEAN_FN_STATS);
  readonly getDRepInfo$ = new BehaviorSubject<ProviderFnStats>(CLEAN_FN_STATS);
 
  shutdown() {
    this.healthCheck$.complete();
    this.getDRepInfo$.complete();
  }
 
  reset() {
    this.healthCheck$.next(CLEAN_FN_STATS);
    this.getDRepInfo$.next(CLEAN_FN_STATS);
  }
}
 
/** Wraps a DRepProvider, tracking # of calls of each function */
export class TrackedDrepProvider extends ProviderTracker implements DRepProvider {
  readonly stats = new DrepProviderStats();
  readonly healthCheck: DRepProvider['healthCheck'];
  readonly getDRepInfo: DRepProvider['getDRepInfo'];
  readonly getDRepsInfo: DRepProvider['getDRepsInfo'];
 
  constructor(drepProvider: DRepProvider) {
    super();
    drepProvider = drepProvider;
 
    this.healthCheck = () => this.trackedCall(() => drepProvider.healthCheck(), this.stats.healthCheck$);
    this.getDRepInfo = (args) => this.trackedCall(() => drepProvider.getDRepInfo(args), this.stats.getDRepInfo$);
    this.getDRepsInfo = (args) => this.trackedCall(() => drepProvider.getDRepsInfo(args), this.stats.getDRepInfo$);
  }
}