Skip to content

Commit

Permalink
feat(Health): inject ipfsHashTxId into Health module (#838)
Browse files Browse the repository at this point in the history
References #838, #832, #707
  • Loading branch information
krobi64 authored Dec 3, 2018
1 parent 3a1ef7d commit 6c73263
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/Health/ExchangeConfiguration.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export interface ExchangeConfiguration {
readonly getHealth?: string
readonly claimsNotDownloaded?: string
readonly ipfsHashTxId?: string
}
2 changes: 1 addition & 1 deletion src/Health/Health.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class Health {
this.ipfsDirectoryHashInfoCollection = this.dbConnection.collection('ipfsDirectoryHashInfo')

const exchangesMessaging = pick(
['getHealth', 'claimsNotDownloaded'],
['getHealth', 'claimsNotDownloaded', 'ipfsHashTxId'],
this.configuration.exchanges,
)
this.messaging = new Messaging(this.configuration.rabbitmqUrl, exchangesMessaging)
Expand Down
1 change: 1 addition & 0 deletions src/Messaging/ExchangeConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export interface ExchangeConfiguration {
readonly poetAnchorDownloaded?: string
readonly claimsDownloaded?: string
readonly claimsNotDownloaded?: string
readonly ipfsHashTxId?: string
}
13 changes: 13 additions & 0 deletions src/Messaging/Messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ export interface LightBlock {
readonly height: number
}

export interface IPFSHashTxId {
readonly ipfsDirectoryHash: string
readonly txId: string
}

const PoetBlockAnchorJoiSchema = Joi.object({
prefix: Joi.string().required(),
version: Joi.number().required(),
Expand All @@ -29,5 +34,13 @@ const BlockDownloadedJoiSchema = Joi.object({
.optional(),
})

const IPFSHashTxIdJoiSchema = Joi.object({
ipfsDirectoryHash: Joi.string().required(),
txId: Joi.string().required(),
})

export const isBlockDownloaded = (messageContent: any): messageContent is BlockDownloaded =>
Joi.validate(messageContent, BlockDownloadedJoiSchema).error === null

export const isIPFSHashTxId = (messageContent: any): messageContent is IPFSHashTxId =>
Joi.validate(messageContent, IPFSHashTxIdJoiSchema).error === null
17 changes: 16 additions & 1 deletion src/Messaging/Messaging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Connection, connect, Channel } from 'amqplib'
import { ClaimIPFSHashPair, isClaimIPFSHashPair, IPFSHashFailure, isIPFSHashFailure } from 'Interfaces'

import { ExchangeConfiguration } from './ExchangeConfiguration'
import { BlockDownloaded, isBlockDownloaded } from './Messages'
import { BlockDownloaded, IPFSHashTxId, isBlockDownloaded, isIPFSHashTxId } from './Messages'

export class Messaging {
private readonly connectionUrl: string
Expand Down Expand Up @@ -71,6 +71,21 @@ export class Messaging {
})
}

publishIPFSHashTxId = async (hashTxId: IPFSHashTxId) => {
return this.publish(this.exchanges.ipfsHashTxId, hashTxId)
}

consumeIPFSHashTxId = async (consume: (hashTxId: IPFSHashTxId) => void) => {
await this.consume(this.exchanges.ipfsHashTxId, (message: any) => {
const messageContent = message.content.toString()
const hashTxId = JSON.parse(messageContent) as unknown

if (!isIPFSHashTxId(hashTxId)) return

consume(hashTxId)
})
}

publishClaimsDownloaded = async (claimIPFSHashPairs: ReadonlyArray<ClaimIPFSHashPair>) => {
return this.publish(this.exchanges.claimsDownloaded, claimIPFSHashPairs)
}
Expand Down
1 change: 1 addition & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ export async function app(localVars: any = {}) {
exchanges: {
getHealth: configuration.exchangeGetHealth,
claimsNotDownloaded: configuration.exchangeClaimsNotDownloaded,
ipfsHashTxId: configuration.exchangeIpfsHashTxId,
},
})

Expand Down

0 comments on commit 6c73263

Please sign in to comment.