@@ -125,6 +125,42 @@ pub async fn latest_price_feeds(
125125 ) )
126126}
127127
128+ #[ derive( Debug , serde:: Deserialize ) ]
129+ pub struct GetPriceFeedQueryParams {
130+ id : PriceIdInput ,
131+ publish_time : UnixTimestamp ,
132+ #[ serde( default ) ]
133+ verbose : bool ,
134+ #[ serde( default ) ]
135+ binary : bool ,
136+ }
137+
138+ pub async fn get_price_feed (
139+ State ( state) : State < super :: State > ,
140+ QsQuery ( params) : QsQuery < GetPriceFeedQueryParams > ,
141+ ) -> Result < Json < RpcPriceFeed > , RestError > {
142+ let price_id: PriceIdentifier = params. id . into ( ) ;
143+
144+ let price_feeds_with_update_data = state
145+ . store
146+ . get_price_feeds_with_update_data (
147+ vec ! [ price_id] ,
148+ RequestTime :: FirstAfter ( params. publish_time ) ,
149+ )
150+ . await
151+ . map_err ( |_| RestError :: UpdateDataNotFound ) ?;
152+
153+ Ok ( Json ( RpcPriceFeed :: from_price_feed_update (
154+ price_feeds_with_update_data
155+ . price_feeds
156+ . into_iter ( )
157+ . next ( )
158+ . ok_or ( RestError :: UpdateDataNotFound ) ?,
159+ params. verbose ,
160+ params. binary ,
161+ ) ) )
162+ }
163+
128164#[ derive( Debug , serde:: Deserialize ) ]
129165pub struct GetVaaQueryParams {
130166 id : PriceIdInput ,
@@ -133,9 +169,9 @@ pub struct GetVaaQueryParams {
133169
134170#[ derive( Debug , serde:: Serialize ) ]
135171pub struct GetVaaResponse {
136- pub vaa : String ,
172+ vaa : String ,
137173 #[ serde( rename = "publishTime" ) ]
138- pub publish_time : UnixTimestamp ,
174+ publish_time : UnixTimestamp ,
139175}
140176
141177pub async fn get_vaa (
@@ -228,6 +264,7 @@ pub async fn index() -> impl IntoResponse {
228264 "/api/price_feed_ids" ,
229265 "/api/latest_price_feeds?ids[]=<price_feed_id>&ids[]=<price_feed_id_2>&..(&verbose=true)(&binary=true)" ,
230266 "/api/latest_vaas?ids[]=<price_feed_id>&ids[]=<price_feed_id_2>&..." ,
267+ "/api/get_price_feed?id=<price_feed_id>&publish_time=<publish_time_in_unix_timestamp>(&verbose=true)(&binary=true)" ,
231268 "/api/get_vaa?id=<price_feed_id>&publish_time=<publish_time_in_unix_timestamp>" ,
232269 "/api/get_vaa_ccip?data=<0x<price_feed_id_32_bytes>+<publish_time_unix_timestamp_be_8_bytes>>" ,
233270 ] )
0 commit comments