Skip to content

Commit

Permalink
fix hermes v2 openapi schemas (#1298)
Browse files Browse the repository at this point in the history
* fix docs

* address comment

* bump

* fix from implementation of RpcPriceIdentifier
  • Loading branch information
cctdaniel authored Feb 15, 2024
1 parent 5c1e83a commit e14a82c
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion hermes/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion hermes/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hermes"
version = "0.5.0"
version = "0.5.1"
description = "Hermes is an agent that provides Verified Prices from the Pythnet Pyth Oracle."
edition = "2021"

Expand Down
5 changes: 5 additions & 0 deletions hermes/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ pub async fn run(opts: RunOptions, state: ApiState) -> Result<()> {
types::RpcPriceFeed,
types::RpcPriceFeedMetadata,
types::RpcPriceIdentifier,
types::EncodingType,
types::PriceUpdate,
types::BinaryPriceUpdate,
types::ParsedPriceUpdate,
types::RpcPriceFeedMetadataV2,
)
),
tags(
Expand Down
2 changes: 1 addition & 1 deletion hermes/src/api/rest/price_feed_ids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub async fn price_feed_ids(
) -> Result<Json<Vec<RpcPriceIdentifier>>, RestError> {
let price_feed_ids = crate::aggregate::get_price_feed_ids(&*state.state)
.await
.iter()
.into_iter()
.map(RpcPriceIdentifier::from)
.collect();

Expand Down
18 changes: 13 additions & 5 deletions hermes/src/api/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,21 @@ impl RpcPriceIdentifier {
pub fn new(bytes: [u8; 32]) -> RpcPriceIdentifier {
RpcPriceIdentifier(bytes)
}
}

pub fn from(id: &PriceIdentifier) -> RpcPriceIdentifier {
impl From<RpcPriceIdentifier> for PriceIdentifier {
fn from(id: RpcPriceIdentifier) -> Self {
PriceIdentifier::new(id.0)
}
}

impl From<PriceIdentifier> for RpcPriceIdentifier {
fn from(id: PriceIdentifier) -> Self {
RpcPriceIdentifier(id.to_bytes())
}
}

#[derive(Clone, Copy, Debug, Default, serde::Deserialize, serde::Serialize)]
#[derive(Clone, Copy, Debug, Default, serde::Deserialize, serde::Serialize, ToSchema)]
pub enum EncodingType {
#[default]
#[serde(rename = "hex")]
Expand All @@ -222,7 +230,7 @@ pub struct BinaryPriceUpdate {

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)]
pub struct ParsedPriceUpdate {
pub id: PriceIdentifier,
pub id: RpcPriceIdentifier,
pub price: RpcPrice,
pub ema_price: RpcPrice,
pub metadata: RpcPriceFeedMetadataV2,
Expand All @@ -233,7 +241,7 @@ impl From<PriceFeedUpdate> for ParsedPriceUpdate {
let price_feed = price_feed_update.price_feed;

Self {
id: price_feed.id,
id: RpcPriceIdentifier::from(price_feed.id),
price: RpcPrice {
price: price_feed.get_price_unchecked().price,
conf: price_feed.get_price_unchecked().conf,
Expand Down Expand Up @@ -271,7 +279,7 @@ impl TryFrom<PriceUpdate> for PriceFeedsWithUpdateData {
.map(|parsed_price_update| {
Ok(PriceFeedUpdate {
price_feed: PriceFeed::new(
parsed_price_update.id,
parsed_price_update.id.into(),
Price {
price: parsed_price_update.price.price,
conf: parsed_price_update.price.conf,
Expand Down

0 comments on commit e14a82c

Please sign in to comment.