11import { Db , Collection } from 'mongodb'
2+ import * as Pino from 'pino'
3+
4+ import { TransactionAnchorRetryInfo } from 'Interfaces'
25
36export const isOkOne = ( { ok } : { ok : number } ) => ok === 1
47
5- interface HealthObject {
8+ export interface HealthObject {
69 readonly mongoIsConnected : boolean
710 readonly ipfsInfo : object
811 readonly walletInfo : object
912 readonly blockchainInfo : object
1013 readonly networkInfo : object
1114 readonly estimatedSmartFeeInfo : object
1215 readonly ipfsRetryInfo : object
16+ readonly transactionAnchorRetryInfo : TransactionAnchorRetryInfo
1317}
1418
1519export interface Dependencies {
1620 readonly db : Db
21+ readonly logger : Pino . Logger
1722}
1823
1924export interface Arguments {
2025 readonly dependencies : Dependencies
2126}
2227
28+ interface EmptyTransactionAnchorRetryInfo {
29+ transactionAnchorRetryInfo : TransactionAnchorRetryInfo
30+ }
31+
32+ const emptyTransactionAnchorRetryInfo : EmptyTransactionAnchorRetryInfo = {
33+ transactionAnchorRetryInfo : [ ] ,
34+ }
35+
2336export class HealthController {
2437 private readonly db : Db
2538 private readonly collection : Collection
39+ private readonly logger : Pino . Logger
2640
2741 constructor ( {
2842 dependencies : {
2943 db,
44+ logger,
3045 } ,
3146 } : Arguments ) {
3247 this . db = db
3348 this . collection = this . db . collection ( 'health' )
49+ this . logger = logger
3450 }
3551
3652 private async checkMongo ( ) : Promise < boolean > {
@@ -100,6 +116,30 @@ export class HealthController {
100116 }
101117 }
102118
119+ private async getTransactionRetryInfo ( ) : Promise < TransactionAnchorRetryInfo > {
120+ this . logger . child ( { message : 'getTransactionRetryInfo' } )
121+ this . logger . trace ( 'retrieving TransactionAnchorRetryInfo' )
122+ try {
123+ const transactionAnchorRetryResults = await this . collection . findOne (
124+ {
125+ name : 'transactionAnchorRetryInfo' ,
126+ } ,
127+ {
128+ fields :
129+ {
130+ _id : false ,
131+ name : false ,
132+ } ,
133+ } ,
134+ ) || emptyTransactionAnchorRetryInfo
135+ this . logger . trace ( { transactionAnchorRetryResults } , 'getTransactionRetryInfo results' )
136+ return transactionAnchorRetryResults . transactionAnchorRetryInfo
137+ } catch ( error ) {
138+ this . logger . error ( { error } , 'error retrieving TransactionAnchorRetryInfo' )
139+ return [ ]
140+ }
141+ }
142+
103143 async getHealth ( ) : Promise < HealthObject > {
104144 const mongoIsConnected = await this . checkMongo ( )
105145 const ipfsInfo = await this . getIPFSInfo ( )
@@ -108,6 +148,7 @@ export class HealthController {
108148 const networkInfo = await this . getNetworkInfo ( )
109149 const estimatedSmartFeeInfo = await this . getEstimatedSmartFeeInfo ( )
110150 const ipfsRetryInfo = await this . getIPFSRetryInfo ( )
151+ const transactionAnchorRetryInfo = await this . getTransactionRetryInfo ( )
111152 return {
112153 mongoIsConnected,
113154 ipfsInfo,
@@ -116,6 +157,7 @@ export class HealthController {
116157 networkInfo,
117158 estimatedSmartFeeInfo,
118159 ipfsRetryInfo,
160+ transactionAnchorRetryInfo,
119161 }
120162 }
121163}
0 commit comments