1- import express , { Express } from "express" ;
21import cors from "cors" ;
2+ import express , { NextFunction , Request , Response } from "express" ;
3+ import { Joi , schema , validate , ValidationError } from "express-validation" ;
4+ import { Server } from "http" ;
5+ import { StatusCodes } from "http-status-codes" ;
36import morgan from "morgan" ;
47import responseTime from "response-time" ;
5- import { Request , Response , NextFunction } from "express " ;
8+ import { DurationInMs , DurationInSec } from "./helpers " ;
69import { PriceStore } from "./listen" ;
710import { logger } from "./logging" ;
811import { PromClient } from "./promClient" ;
9- import { DurationInMs , DurationInSec } from "./helpers" ;
10- import { StatusCodes } from "http-status-codes" ;
11- import { validate , ValidationError , Joi , schema } from "express-validation" ;
12- import { Server } from "http" ;
1312
1413const MORGAN_LOG_FORMAT =
1514 ':remote-addr - :remote-user ":method :url HTTP/:http-version"' +
@@ -135,13 +134,16 @@ export class RestAPI {
135134 ids : Joi . array ( )
136135 . items ( Joi . string ( ) . regex ( / ^ ( 0 x ) ? [ a - f 0 - 9 ] { 64 } $ / ) )
137136 . required ( ) ,
137+ verbose : Joi . boolean ( ) ,
138138 } ) . required ( ) ,
139139 } ;
140140 app . get (
141141 "/api/latest_price_feeds" ,
142142 validate ( latestPriceFeedsInputSchema ) ,
143143 ( req : Request , res : Response ) => {
144144 let priceIds = req . query . ids as string [ ] ;
145+ // verbose is optional, default to false
146+ let verbose = req . query . verbose === "true" ;
145147
146148 let responseJson = [ ] ;
147149
@@ -167,7 +169,18 @@ export class RestAPI {
167169 freshness
168170 ) ;
169171
170- responseJson . push ( latestPriceInfo . priceFeed . toJson ( ) ) ;
172+ if ( verbose ) {
173+ responseJson . push ( {
174+ ...latestPriceInfo . priceFeed . toJson ( ) ,
175+ metadata : {
176+ emitter_chain : latestPriceInfo . emitterChainId ,
177+ attestation_time : latestPriceInfo . attestationTime ,
178+ sequence_number : latestPriceInfo . seqNum ,
179+ } ,
180+ } ) ;
181+ } else {
182+ responseJson . push ( latestPriceInfo . priceFeed . toJson ( ) ) ;
183+ }
171184 }
172185
173186 if ( notFoundIds . length > 0 ) {
@@ -180,18 +193,16 @@ export class RestAPI {
180193 endpoints . push (
181194 "api/latest_price_feeds?ids[]=<price_feed_id>&ids[]=<price_feed_id_2>&.."
182195 ) ;
183-
184- app . get (
185- "/api/price_feed_ids" ,
186- ( req : Request , res : Response ) => {
187- const availableIds = this . priceFeedVaaInfo . getPriceIds ( ) ;
188- res . json ( [ ...availableIds ] ) ;
189- }
190- ) ;
191196 endpoints . push (
192- "api/price_feed_ids "
197+ "api/latest_price_feeds?ids[]=<price_feed_id>&ids[]=<price_feed_id_2>&..&verbose=true "
193198 ) ;
194199
200+ app . get ( "/api/price_feed_ids" , ( req : Request , res : Response ) => {
201+ const availableIds = this . priceFeedVaaInfo . getPriceIds ( ) ;
202+ res . json ( [ ...availableIds ] ) ;
203+ } ) ;
204+ endpoints . push ( "api/price_feed_ids" ) ;
205+
195206 app . get ( "/ready" , ( _ , res : Response ) => {
196207 if ( this . isReady ! ( ) ) {
197208 res . sendStatus ( StatusCodes . OK ) ;
0 commit comments