All files / src/services/ProviderTracker TrackedTxSubmitProvider.ts

100% Statements 20/20
100% Branches 0/0
100% Functions 8/8
100% Lines 17/17

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 3843x 43x     43x   43x 124x 124x     119x 119x       2x 2x         43x 124x         124x 124x   124x   124x 18x      
import { BehaviorSubject } from 'rxjs';
import { CLEAN_FN_STATS, ProviderFnStats, ProviderTracker } from './ProviderTracker';
import { TxSubmitProvider } from '@cardano-sdk/core';
 
export const CLEAN_TX_SUBMIT_STATS: ProviderFnStats = { ...CLEAN_FN_STATS, initialized: true };
 
export class TxSubmitProviderStats {
  readonly healthCheck$ = new BehaviorSubject<ProviderFnStats>(CLEAN_TX_SUBMIT_STATS);
  readonly submitTx$ = new BehaviorSubject<ProviderFnStats>(CLEAN_TX_SUBMIT_STATS);
 
  shutdown() {
    this.submitTx$.complete();
    this.healthCheck$.complete();
  }
 
  reset() {
    this.healthCheck$.next(CLEAN_TX_SUBMIT_STATS);
    this.submitTx$.next(CLEAN_TX_SUBMIT_STATS);
  }
}
 
/** Wraps a TxSubmitProvider, tracking # of calls of each function */
export class TrackedTxSubmitProvider extends ProviderTracker implements TxSubmitProvider {
  readonly stats = new TxSubmitProviderStats();
  readonly healthCheck: TxSubmitProvider['healthCheck'];
  readonly submitTx: TxSubmitProvider['submitTx'];
 
  constructor(txSubmitProvider: TxSubmitProvider) {
    super();
    txSubmitProvider = txSubmitProvider;
 
    this.healthCheck = () => this.trackedCall(() => txSubmitProvider.healthCheck(), this.stats.healthCheck$);
 
    this.submitTx = (signedTransaction) =>
      this.trackedCall(() => txSubmitProvider.submitTx(signedTransaction), this.stats.submitTx$);
  }
}