Kaynağa Gözat

fix hermes v2 openapi schemas (#1298)

* fix docs

* address comment

* bump

* fix from implementation of RpcPriceIdentifier
Daniel Chew 1 yıl önce
ebeveyn
işleme
e14a82c61a

+ 1 - 1
hermes/Cargo.lock

@@ -1574,7 +1574,7 @@ checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
 
 [[package]]
 name = "hermes"
-version = "0.5.0"
+version = "0.5.1"
 dependencies = [
  "anyhow",
  "async-trait",

+ 1 - 1
hermes/Cargo.toml

@@ -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"
 

+ 5 - 0
hermes/src/api.rs

@@ -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(

+ 1 - 1
hermes/src/api/rest/price_feed_ids.rs

@@ -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();
 

+ 13 - 5
hermes/src/api/types.rs

@@ -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")]
@@ -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,
@@ -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,
@@ -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,