1
- import express , { Express } from "express" ;
2
1
import 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" ;
3
6
import morgan from "morgan" ;
4
7
import responseTime from "response-time" ;
5
- import { Request , Response , NextFunction } from "express " ;
8
+ import { DurationInMs , DurationInSec } from "./helpers " ;
6
9
import { PriceStore } from "./listen" ;
7
10
import { logger } from "./logging" ;
8
11
import { 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" ;
13
12
14
13
const MORGAN_LOG_FORMAT =
15
14
':remote-addr - :remote-user ":method :url HTTP/:http-version"' +
@@ -135,13 +134,16 @@ export class RestAPI {
135
134
ids : Joi . array ( )
136
135
. items ( Joi . string ( ) . regex ( / ^ ( 0 x ) ? [ a - f 0 - 9 ] { 64 } $ / ) )
137
136
. required ( ) ,
137
+ verbose : Joi . boolean ( ) ,
138
138
} ) . required ( ) ,
139
139
} ;
140
140
app . get (
141
141
"/api/latest_price_feeds" ,
142
142
validate ( latestPriceFeedsInputSchema ) ,
143
143
( req : Request , res : Response ) => {
144
144
let priceIds = req . query . ids as string [ ] ;
145
+ // verbose is optional, default to false
146
+ let verbose = req . query . verbose === "true" ;
145
147
146
148
let responseJson = [ ] ;
147
149
@@ -167,7 +169,18 @@ export class RestAPI {
167
169
freshness
168
170
) ;
169
171
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
+ }
171
184
}
172
185
173
186
if ( notFoundIds . length > 0 ) {
@@ -180,18 +193,16 @@ export class RestAPI {
180
193
endpoints . push (
181
194
"api/latest_price_feeds?ids[]=<price_feed_id>&ids[]=<price_feed_id_2>&.."
182
195
) ;
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
- ) ;
191
196
endpoints . push (
192
- "api/price_feed_ids "
197
+ "api/latest_price_feeds?ids[]=<price_feed_id>&ids[]=<price_feed_id_2>&..&verbose=true "
193
198
) ;
194
199
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
+
195
206
app . get ( "/ready" , ( _ , res : Response ) => {
196
207
if ( this . isReady ! ( ) ) {
197
208
res . sendStatus ( StatusCodes . OK ) ;
0 commit comments