import { FastifyRequest , FastifyReply } from "fastify" ; import { sendInvalidParamError } from "./errors" ; import { sanitizeHex } from "./utilities" ; import { convertStringToNumber } from "./bignumber" ; import { RequestWithAddressQuerystring , RequestWithChainIdQuerystring , RequestWithContractQuerystring , RequestWithDataQuerystring , RequestWithFiatQueryString , } from "./rest" ; export function verifyParam < R = any > ( req , res , param , expectedType , sanitizer ) { const value = sanitizer ( req . query [ param ] ) ; if ( ! value || typeof value !== expectedType ) { sendInvalidParamError ( res , param ) ; } return value ; } export function verifyAddress ( req , res ) { return verifyParam ( req , res , "address" , "string" , sanitizeHex ) ; } export function verifyChainId ( req , res ) { return verifyParam ( req , res , "chainId" , "number" , convertStringToNumber ) ; } export function verifyContractAddress ( req , res ) { return verifyParam ( req , res , "contractAddress" , "string" , sanitizeHex ) ; } export function verifyData ( req , res ) { const sanitizeData = ( ) => sanitizeHex ( req . query . data ) || "0x" ; return verifyParam ( req , res , "data" , "number" , sanitizeData ) ; } export function verifyFiat ( req , res ) { return verifyParam ( req , res , "fiat" , "string" , sanitizeHex ) ; }