diff --git a/README.md b/README.md index c2cd7b1f..e44f991b 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/src/blockchain/index.ts b/src/blockchain/index.ts index 66fd2885..0409785e 100644 --- a/src/blockchain/index.ts +++ b/src/blockchain/index.ts @@ -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') @@ -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) }