29
29
} ,
30
30
} ;
31
31
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.
32
36
#[ derive( Debug , Clone , Deref , DerefMut ) ]
33
37
pub struct PriceIdInput ( [ u8 ; 32 ] ) ;
34
38
// TODO: Use const generics instead of macro.
@@ -42,6 +46,7 @@ impl From<PriceIdInput> for PriceIdentifier {
42
46
43
47
pub enum RestError {
44
48
UpdateDataNotFound ,
49
+ CcipUpdateDataNotFound ,
45
50
}
46
51
47
52
impl IntoResponse for RestError {
@@ -50,10 +55,26 @@ impl IntoResponse for RestError {
50
55
RestError :: UpdateDataNotFound => {
51
56
( StatusCode :: NOT_FOUND , "Update data not found" ) . into_response ( )
52
57
}
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
+ }
53
68
}
54
69
}
55
70
}
56
71
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
+ }
57
78
58
79
#[ derive( Debug , serde:: Deserialize ) ]
59
80
pub struct LatestVaasQueryParams {
@@ -173,7 +194,7 @@ pub async fn get_vaa_ccip(
173
194
let price_feeds_with_update_data = state
174
195
. store
175
196
. get_price_feeds_with_update_data ( vec ! [ price_id] , RequestTime :: FirstAfter ( publish_time) )
176
- . map_err ( |_| RestError :: UpdateDataNotFound ) ?;
197
+ . map_err ( |_| RestError :: CcipUpdateDataNotFound ) ?;
177
198
178
199
let vaa = price_feeds_with_update_data
179
200
. update_data
@@ -199,6 +220,7 @@ pub async fn live() -> Result<impl IntoResponse, std::convert::Infallible> {
199
220
pub async fn index ( ) -> impl IntoResponse {
200
221
Json ( [
201
222
"/live" ,
223
+ "/api/price_feed_ids" ,
202
224
"/api/latest_price_feeds?ids[]=<price_feed_id>&ids[]=<price_feed_id_2>&.." ,
203
225
"/api/latest_vaas?ids[]=<price_feed_id>&ids[]=<price_feed_id_2>&..." ,
204
226
"/api/get_vaa?id=<price_feed_id>&publish_time=<publish_time_in_unix_timestamp>" ,
0 commit comments