Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions hermes/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pub async fn run(store: Arc<Store>, 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))
Expand Down
41 changes: 39 additions & 2 deletions hermes/src/api/rest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<super::State>,
QsQuery(params): QsQuery<GetPriceFeedQueryParams>,
) -> Result<Json<RpcPriceFeed>, 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,
Expand All @@ -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(
Expand Down Expand Up @@ -228,6 +264,7 @@ pub async fn index() -> impl IntoResponse {
"/api/price_feed_ids",
"/api/latest_price_feeds?ids[]=<price_feed_id>&ids[]=<price_feed_id_2>&..(&verbose=true)(&binary=true)",
"/api/latest_vaas?ids[]=<price_feed_id>&ids[]=<price_feed_id_2>&...",
"/api/get_price_feed?id=<price_feed_id>&publish_time=<publish_time_in_unix_timestamp>(&verbose=true)(&binary=true)",
"/api/get_vaa?id=<price_feed_id>&publish_time=<publish_time_in_unix_timestamp>",
"/api/get_vaa_ccip?data=<0x<price_feed_id_32_bytes>+<publish_time_unix_timestamp_be_8_bytes>>",
])
Expand Down