All files / src/ChainHistoryProvider chainHistoryHttpProvider.ts

90% Statements 9/10
60% Branches 3/5
100% Functions 2/2
88.88% Lines 8/9

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 3411x 11x 11x     11x                         11x     10x       3x     3x          
import { ChainHistoryProvider, HttpProviderConfigPaths, ProviderError, ProviderFailure } from '@cardano-sdk/core';
import { CreateHttpProviderConfig, createHttpProvider } from '../HttpProvider';
import { apiVersion } from '../version';
 
/** The ChainHistoryProvider endpoint paths. */
const paths: HttpProviderConfigPaths<ChainHistoryProvider> = {
  blocksByHashes: '/blocks/by-hashes',
  healthCheck: '/health',
  transactionsByAddresses: '/txs/by-addresses',
  transactionsByHashes: '/txs/by-hashes'
};
 
/**
 * Connect to a Cardano Services HttpServer instance with the service available
 *
 * @param config The configuration object fot the NetworkInfoProvider Provider.
 * @returns {ChainHistoryProvider} ChainHistoryProvider
 */
export const chainHistoryHttpProvider = (
  config: CreateHttpProviderConfig<ChainHistoryProvider>
): ChainHistoryProvider =>
  createHttpProvider<ChainHistoryProvider>({
    ...config,
    apiVersion: config.apiVersion || apiVersion.chainHistory,
    mapError: (error, method) => {
      Iif (method === 'healthCheck' && !error) {
        return { ok: false };
      }
      throw new ProviderError(ProviderFailure.Unknown, error);
    },
    paths,
    serviceSlug: 'chain-history'
  });