All files / src/NetworkInfo NetworkInfoHttpService.ts

100% Statements 12/12
100% Branches 1/1
100% Functions 1/1
100% Lines 12/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 5835x     35x 35x 35x             35x         4x   4x       4x             4x             4x       4x             4x                  
import { HttpService } from '../Http';
import { Logger } from 'ts-log';
import { NetworkInfoProvider } from '@cardano-sdk/core';
import { ServiceNames } from '../Program/programs/types';
import { providerHandler } from '../util';
import express from 'express';
 
export interface NetworkInfoServiceDependencies {
  logger: Logger;
  networkInfoProvider: NetworkInfoProvider;
}
 
export class NetworkInfoHttpService extends HttpService {
  constructor(
    { networkInfoProvider, logger }: NetworkInfoServiceDependencies,
    router: express.Router = express.Router()
  ) {
    super(ServiceNames.NetworkInfo, networkInfoProvider, router, __dirname, logger);
 
    router.post(
      '/stake',
      providerHandler(networkInfoProvider.stake.bind(networkInfoProvider))(HttpService.routeHandler(logger), logger)
    );
    router.post(
      '/lovelace-supply',
      providerHandler(networkInfoProvider.lovelaceSupply.bind(networkInfoProvider))(
        HttpService.routeHandler(logger),
        logger
      )
    );
    router.post(
      '/era-summaries',
      providerHandler(networkInfoProvider.eraSummaries.bind(networkInfoProvider))(
        HttpService.routeHandler(logger),
        logger
      )
    );
    router.post(
      '/ledger-tip',
      providerHandler(networkInfoProvider.ledgerTip.bind(networkInfoProvider))(HttpService.routeHandler(logger), logger)
    );
    router.post(
      '/protocol-parameters',
      providerHandler(networkInfoProvider.protocolParameters.bind(networkInfoProvider))(
        HttpService.routeHandler(logger),
        logger
      )
    );
    router.post(
      '/genesis-parameters',
      providerHandler(networkInfoProvider.genesisParameters.bind(networkInfoProvider))(
        HttpService.routeHandler(logger),
        logger
      )
    );
  }
}