diff --git a/hermes/src/api.rs b/hermes/src/api.rs index d2081b8a32..3812ff2c05 100644 --- a/hermes/src/api.rs +++ b/hermes/src/api.rs @@ -48,6 +48,7 @@ pub async fn run(store: Arc, mut update_rx: Receiver<()>, rpc_addr: Strin .route("/ws", get(ws::ws_route_handler)) .route("/api/latest_price_feeds", get(rest::latest_price_feeds)) .route("/api/latest_vaas", get(rest::latest_vaas)) + .route("/api/get_price_feed", get(rest::get_price_feed)) .route("/api/get_vaa", get(rest::get_vaa)) .route("/api/get_vaa_ccip", get(rest::get_vaa_ccip)) .route("/api/price_feed_ids", get(rest::price_feed_ids)) diff --git a/hermes/src/api/rest.rs b/hermes/src/api/rest.rs index 3d5dc7a318..f3e38d20cd 100644 --- a/hermes/src/api/rest.rs +++ b/hermes/src/api/rest.rs @@ -125,6 +125,42 @@ pub async fn latest_price_feeds( )) } +#[derive(Debug, serde::Deserialize)] +pub struct GetPriceFeedQueryParams { + id: PriceIdInput, + publish_time: UnixTimestamp, + #[serde(default)] + verbose: bool, + #[serde(default)] + binary: bool, +} + +pub async fn get_price_feed( + State(state): State, + QsQuery(params): QsQuery, +) -> Result, RestError> { + let price_id: PriceIdentifier = params.id.into(); + + let price_feeds_with_update_data = state + .store + .get_price_feeds_with_update_data( + vec![price_id], + RequestTime::FirstAfter(params.publish_time), + ) + .await + .map_err(|_| RestError::UpdateDataNotFound)?; + + Ok(Json(RpcPriceFeed::from_price_feed_update( + price_feeds_with_update_data + .price_feeds + .into_iter() + .next() + .ok_or(RestError::UpdateDataNotFound)?, + params.verbose, + params.binary, + ))) +} + #[derive(Debug, serde::Deserialize)] pub struct GetVaaQueryParams { id: PriceIdInput, @@ -133,9 +169,9 @@ pub struct GetVaaQueryParams { #[derive(Debug, serde::Serialize)] pub struct GetVaaResponse { - pub vaa: String, + vaa: String, #[serde(rename = "publishTime")] - pub publish_time: UnixTimestamp, + publish_time: UnixTimestamp, } pub async fn get_vaa( @@ -228,6 +264,7 @@ pub async fn index() -> impl IntoResponse { "/api/price_feed_ids", "/api/latest_price_feeds?ids[]=&ids[]=&..(&verbose=true)(&binary=true)", "/api/latest_vaas?ids[]=&ids[]=&...", + "/api/get_price_feed?id=&publish_time=(&verbose=true)(&binary=true)", "/api/get_vaa?id=&publish_time=", "/api/get_vaa_ccip?data=<0x+>", ])