Skip to content
This repository has been archived by the owner on May 19, 2023. It is now read-only.

Commit

Permalink
fix: ws emits to be emitted for confirmation service
Browse files Browse the repository at this point in the history
  • Loading branch information
AuHau committed Jun 10, 2020
1 parent 06d2399 commit cb8b852
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

- [Supported services](#supported-services)
- [RIF Storage](#rif-storage)
- [RNS](#rns)
- [Rates](#rates)
- [Confirmations](#confirmations)
- [Configuration](#configuration)
- [Environment variables overview](#environment-variables-overview)
- [Database](#database)
Expand Down
19 changes: 17 additions & 2 deletions src/blockchain/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Eth from 'web3-eth'
import config from 'config'

import ConfirmationService from './confirmation.service'
import { Application } from '../definitions'
import { Application, ServiceAddresses } from '../definitions'
import { loggingFactory } from '../logger'

const logger = loggingFactory('blockchain')
Expand All @@ -14,8 +14,23 @@ export function ethFactory (): Eth {
return new Eth(provider)
}

const CHANNEL_NAME = 'confirmations'

function channelSetup (app: Application): void {
if (typeof app.channel !== 'function') {
// If no real-time functionality has been configured just return
return
}
app.on('connection', (connection: any) => {
app.channel(CHANNEL_NAME).join(connection)
})
app.service(ServiceAddresses.CONFIRMATIONS).publish(() => app.channel(CHANNEL_NAME))
}

export default function (app: Application): void {
const eth = ethFactory()
app.set('eth', eth)
app.use('/confirmations', new ConfirmationService(eth))
app.use(ServiceAddresses.CONFIRMATIONS, new ConfirmationService(eth))

channelSetup(app)
}

0 comments on commit cb8b852

Please sign in to comment.