2929 } ,
3030} ;
3131
32+ /// PriceIdInput is a wrapper around a 32-byte hex string.
33+ /// that supports a flexible deserialization from a hex string.
34+ /// It supports both 0x-prefixed and non-prefixed hex strings,
35+ /// and also supports both lower and upper case characters.
3236#[ derive( Debug , Clone , Deref , DerefMut ) ]
3337pub struct PriceIdInput ( [ u8 ; 32 ] ) ;
3438// TODO: Use const generics instead of macro.
@@ -42,6 +46,7 @@ impl From<PriceIdInput> for PriceIdentifier {
4246
4347pub enum RestError {
4448 UpdateDataNotFound ,
49+ CcipUpdateDataNotFound ,
4550}
4651
4752impl IntoResponse for RestError {
@@ -50,10 +55,26 @@ impl IntoResponse for RestError {
5055 RestError :: UpdateDataNotFound => {
5156 ( StatusCode :: NOT_FOUND , "Update data not found" ) . into_response ( )
5257 }
58+ RestError :: CcipUpdateDataNotFound => {
59+ // Returning Bad Gateway error because CCIP expects a 5xx error if it needs to
60+ // retry or try other endpoints. Bad Gateway seems the best choice here as this
61+ // is not an internal error and could happen on two scenarios:
62+ // 1. DB Api is not responding well (Bad Gateway is appropriate here)
63+ // 2. Publish time is a few seconds before current time and a VAA
64+ // Will be available in a few seconds. So we want the client to retry.
65+
66+ ( StatusCode :: BAD_GATEWAY , "CCIP update data not found" ) . into_response ( )
67+ }
5368 }
5469 }
5570}
5671
72+ pub async fn price_feed_ids (
73+ State ( state) : State < super :: State > ,
74+ ) -> Result < Json < Vec < PriceIdentifier > > , RestError > {
75+ let price_feeds = state. store . get_price_feed_ids ( ) ;
76+ Ok ( Json ( price_feeds) )
77+ }
5778
5879#[ derive( Debug , serde:: Deserialize ) ]
5980pub struct LatestVaasQueryParams {
@@ -173,7 +194,7 @@ pub async fn get_vaa_ccip(
173194 let price_feeds_with_update_data = state
174195 . store
175196 . get_price_feeds_with_update_data ( vec ! [ price_id] , RequestTime :: FirstAfter ( publish_time) )
176- . map_err ( |_| RestError :: UpdateDataNotFound ) ?;
197+ . map_err ( |_| RestError :: CcipUpdateDataNotFound ) ?;
177198
178199 let vaa = price_feeds_with_update_data
179200 . update_data
@@ -199,6 +220,7 @@ pub async fn live() -> Result<impl IntoResponse, std::convert::Infallible> {
199220pub async fn index ( ) -> impl IntoResponse {
200221 Json ( [
201222 "/live" ,
223+ "/api/price_feed_ids" ,
202224 "/api/latest_price_feeds?ids[]=<price_feed_id>&ids[]=<price_feed_id_2>&.." ,
203225 "/api/latest_vaas?ids[]=<price_feed_id>&ids[]=<price_feed_id_2>&..." ,
204226 "/api/get_vaa?id=<price_feed_id>&publish_time=<publish_time_in_unix_timestamp>" ,
0 commit comments