-
Notifications
You must be signed in to change notification settings - Fork 54
/
TrackedTxSubmitProvider.ts
37 lines (29 loc) · 1.34 KB
/
TrackedTxSubmitProvider.ts
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
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$);
}
}