Skip to content

Commit 6c73263

Browse files
authored
feat(Health): inject ipfsHashTxId into Health module (#838)
References #838, #832, #707
1 parent 3a1ef7d commit 6c73263

File tree

6 files changed

+33
-2
lines changed

6 files changed

+33
-2
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export interface ExchangeConfiguration {
22
readonly getHealth?: string
33
readonly claimsNotDownloaded?: string
4+
readonly ipfsHashTxId?: string
45
}

src/Health/Health.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export class Health {
5151
this.ipfsDirectoryHashInfoCollection = this.dbConnection.collection('ipfsDirectoryHashInfo')
5252

5353
const exchangesMessaging = pick(
54-
['getHealth', 'claimsNotDownloaded'],
54+
['getHealth', 'claimsNotDownloaded', 'ipfsHashTxId'],
5555
this.configuration.exchanges,
5656
)
5757
this.messaging = new Messaging(this.configuration.rabbitmqUrl, exchangesMessaging)

src/Messaging/ExchangeConfiguration.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ export interface ExchangeConfiguration {
22
readonly poetAnchorDownloaded?: string
33
readonly claimsDownloaded?: string
44
readonly claimsNotDownloaded?: string
5+
readonly ipfsHashTxId?: string
56
}

src/Messaging/Messages.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ export interface LightBlock {
1212
readonly height: number
1313
}
1414

15+
export interface IPFSHashTxId {
16+
readonly ipfsDirectoryHash: string
17+
readonly txId: string
18+
}
19+
1520
const PoetBlockAnchorJoiSchema = Joi.object({
1621
prefix: Joi.string().required(),
1722
version: Joi.number().required(),
@@ -29,5 +34,13 @@ const BlockDownloadedJoiSchema = Joi.object({
2934
.optional(),
3035
})
3136

37+
const IPFSHashTxIdJoiSchema = Joi.object({
38+
ipfsDirectoryHash: Joi.string().required(),
39+
txId: Joi.string().required(),
40+
})
41+
3242
export const isBlockDownloaded = (messageContent: any): messageContent is BlockDownloaded =>
3343
Joi.validate(messageContent, BlockDownloadedJoiSchema).error === null
44+
45+
export const isIPFSHashTxId = (messageContent: any): messageContent is IPFSHashTxId =>
46+
Joi.validate(messageContent, IPFSHashTxIdJoiSchema).error === null

src/Messaging/Messaging.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Connection, connect, Channel } from 'amqplib'
44
import { ClaimIPFSHashPair, isClaimIPFSHashPair, IPFSHashFailure, isIPFSHashFailure } from 'Interfaces'
55

66
import { ExchangeConfiguration } from './ExchangeConfiguration'
7-
import { BlockDownloaded, isBlockDownloaded } from './Messages'
7+
import { BlockDownloaded, IPFSHashTxId, isBlockDownloaded, isIPFSHashTxId } from './Messages'
88

99
export class Messaging {
1010
private readonly connectionUrl: string
@@ -71,6 +71,21 @@ export class Messaging {
7171
})
7272
}
7373

74+
publishIPFSHashTxId = async (hashTxId: IPFSHashTxId) => {
75+
return this.publish(this.exchanges.ipfsHashTxId, hashTxId)
76+
}
77+
78+
consumeIPFSHashTxId = async (consume: (hashTxId: IPFSHashTxId) => void) => {
79+
await this.consume(this.exchanges.ipfsHashTxId, (message: any) => {
80+
const messageContent = message.content.toString()
81+
const hashTxId = JSON.parse(messageContent) as unknown
82+
83+
if (!isIPFSHashTxId(hashTxId)) return
84+
85+
consume(hashTxId)
86+
})
87+
}
88+
7489
publishClaimsDownloaded = async (claimIPFSHashPairs: ReadonlyArray<ClaimIPFSHashPair>) => {
7590
return this.publish(this.exchanges.claimsDownloaded, claimIPFSHashPairs)
7691
}

src/app.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ export async function app(localVars: any = {}) {
244244
exchanges: {
245245
getHealth: configuration.exchangeGetHealth,
246246
claimsNotDownloaded: configuration.exchangeClaimsNotDownloaded,
247+
ipfsHashTxId: configuration.exchangeIpfsHashTxId,
247248
},
248249
})
249250

0 commit comments

Comments
 (0)