Skip to content

Commit 29dad7a

Browse files
authored
[hermes] Add get_price_feed endpoint (#883)
1 parent f394d9e commit 29dad7a

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

hermes/src/api.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ pub async fn run(store: Arc<Store>, mut update_rx: Receiver<()>, rpc_addr: Strin
4848
.route("/ws", get(ws::ws_route_handler))
4949
.route("/api/latest_price_feeds", get(rest::latest_price_feeds))
5050
.route("/api/latest_vaas", get(rest::latest_vaas))
51+
.route("/api/get_price_feed", get(rest::get_price_feed))
5152
.route("/api/get_vaa", get(rest::get_vaa))
5253
.route("/api/get_vaa_ccip", get(rest::get_vaa_ccip))
5354
.route("/api/price_feed_ids", get(rest::price_feed_ids))

hermes/src/api/rest.rs

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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)]
129165
pub struct GetVaaQueryParams {
130166
id: PriceIdInput,
@@ -133,9 +169,9 @@ pub struct GetVaaQueryParams {
133169

134170
#[derive(Debug, serde::Serialize)]
135171
pub struct GetVaaResponse {
136-
pub vaa: String,
172+
vaa: String,
137173
#[serde(rename = "publishTime")]
138-
pub publish_time: UnixTimestamp,
174+
publish_time: UnixTimestamp,
139175
}
140176

141177
pub 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

Comments
 (0)