import * as express from 'express' ; import * as _ from 'lodash' ; import { CHAIN_ID } from '../config' ; import { ValidationError } from '../errors' ; /**
 * Parses URL params and stores them on the request object
 */ export function urlParamsParsing ( req , _res , next ) { const chainId = parseChainId ( req . query . chainId ) ; ( req as any ) . chainId = chainId ; next ( ) ; } function parseChainId ( chainIdStrIfExists ? ) { if ( chainIdStrIfExists === undefined ) { return CHAIN_ID ; } else { const chainId = _ . parseInt ( chainIdStrIfExists ) ; if ( chainId !== CHAIN_ID ) { const validationErrorItem = { field : 'chainId' , code : 1004 , reason : `Incorrect Chain ID: ${ chainIdStrIfExists }` , } ; throw new ValidationError ( [ validationErrorItem ] ) ; } return chainId ; } }