[hermes] Finish up docs (#1002)

* docs

* stuff

* comment
This commit is contained in:
Jayant Krishnamurthy 2023-08-03 09:24:31 -07:00 committed by GitHub
parent cb49236a58
commit 99f1b6e950
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 47 additions and 13 deletions

2
hermes/Cargo.lock generated
View File

@ -1764,7 +1764,7 @@ checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
[[package]] [[package]]
name = "hermes" name = "hermes"
version = "0.1.6" version = "0.1.7"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"axum", "axum",

View File

@ -1,6 +1,6 @@
[package] [package]
name = "hermes" name = "hermes"
version = "0.1.6" version = "0.1.7"
edition = "2021" edition = "2021"
[dependencies] [dependencies]

View File

@ -5,6 +5,7 @@ use {
RpcPriceIdentifier, RpcPriceIdentifier,
}, },
crate::{ crate::{
doc_examples,
impl_deserialize_for_hex_string_wrapper, impl_deserialize_for_hex_string_wrapper,
store::types::{ store::types::{
RequestTime, RequestTime,
@ -111,7 +112,7 @@ pub struct LatestVaasQueryParams {
get, get,
path = "/api/latest_vaas", path = "/api/latest_vaas",
responses( responses(
(status = 200, description = "VAAs retrieved successfully", body = Vec<String>) (status = 200, description = "VAAs retrieved successfully", body = Vec<String>, example=json!([doc_examples::vaa_example()]))
), ),
params( params(
LatestVaasQueryParams LatestVaasQueryParams
@ -199,7 +200,7 @@ pub struct GetPriceFeedQueryParams {
id: PriceIdInput, id: PriceIdInput,
/// The unix timestamp in seconds. This endpoint will return the first update /// The unix timestamp in seconds. This endpoint will return the first update
/// whose publish_time is >= the provided value. /// whose publish_time is >= the provided value.
#[param(value_type = i64, example=1690576641)] #[param(value_type = i64, example=doc_examples::timestamp_example)]
publish_time: UnixTimestamp, publish_time: UnixTimestamp,
/// If true, include the `metadata` field in the response with additional metadata about /// If true, include the `metadata` field in the response with additional metadata about
/// the price update. /// the price update.
@ -264,6 +265,7 @@ pub struct GetVaaQueryParams {
#[derive(Debug, serde::Serialize, ToSchema)] #[derive(Debug, serde::Serialize, ToSchema)]
pub struct GetVaaResponse { pub struct GetVaaResponse {
/// The VAA binary represented as a base64 string. /// The VAA binary represented as a base64 string.
#[schema(example=doc_examples::vaa_example)]
vaa: String, vaa: String,
#[serde(rename = "publishTime")] #[serde(rename = "publishTime")]
#[schema(value_type = i64, example=1690576641)] #[schema(value_type = i64, example=1690576641)]

View File

@ -1,5 +1,6 @@
use { use {
crate::{ crate::{
doc_examples,
impl_deserialize_for_hex_string_wrapper, impl_deserialize_for_hex_string_wrapper,
store::types::{ store::types::{
PriceFeedUpdate, PriceFeedUpdate,
@ -19,23 +20,21 @@ use {
Deref, Deref,
DerefMut, DerefMut,
}, },
hex::FromHexError,
pyth_sdk::PriceIdentifier, pyth_sdk::PriceIdentifier,
utoipa::ToSchema, utoipa::ToSchema,
wormhole_sdk::Chain, wormhole_sdk::Chain,
}; };
/// A price id is a 32-byte hex string, optionally prefixed with "0x". /// A price id is a 32-byte hex string, optionally prefixed with "0x".
/// Price ids are case insensitive. /// Price ids are case insensitive.
/// ///
/// Examples: /// Examples:
/// * 0x63f341689d98a12ef60a5cff1d7f85c70a9e17bf1575f0e7c0b2512d48b1c8b3 /// * 0xe62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43
/// * 63f341689d98a12ef60a5cff1d7f85c70a9e17bf1575f0e7c0b2512d48b1c8b3 /// * e62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43
/// ///
/// See https://pyth.network/developers/price-feed-ids for a list of all price feed ids. /// See https://pyth.network/developers/price-feed-ids for a list of all price feed ids.
#[derive(Debug, Clone, Deref, DerefMut, ToSchema)] #[derive(Debug, Clone, Deref, DerefMut, ToSchema)]
#[schema(value_type=String, example="63f341689d98a12ef60a5cff1d7f85c70a9e17bf1575f0e7c0b2512d48b1c8b3")] #[schema(value_type=String, example=doc_examples::price_feed_id_example)]
pub struct PriceIdInput([u8; 32]); pub struct PriceIdInput([u8; 32]);
// TODO: Use const generics instead of macro. // TODO: Use const generics instead of macro.
impl_deserialize_for_hex_string_wrapper!(PriceIdInput, 32); impl_deserialize_for_hex_string_wrapper!(PriceIdInput, 32);
@ -54,7 +53,7 @@ pub struct RpcPriceFeedMetadata {
pub slot: Slot, pub slot: Slot,
#[schema(example = 26)] #[schema(example = 26)]
pub emitter_chain: u16, pub emitter_chain: u16,
#[schema(value_type = i64, example=1690576641)] #[schema(value_type = i64, example=doc_examples::timestamp_example)]
pub price_service_receive_time: UnixTimestamp, pub price_service_receive_time: UnixTimestamp,
} }
@ -67,7 +66,7 @@ pub struct RpcPriceFeed {
pub metadata: Option<RpcPriceFeedMetadata>, pub metadata: Option<RpcPriceFeedMetadata>,
/// The VAA binary represented as a base64 string. /// The VAA binary represented as a base64 string.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
#[schema(value_type = Option<String>, example="UE5BVQEAAAADuAEAAAADDQC1H7meY5fTed0FsykIb8dt+7nKpbuzfvU2DplDi+dcUl8MC+UIkS65+rkiq+zmNBxE2gaxkBkjdIicZ/fBo+X7AAEqp+WtlWb84np8jJfLpuQ2W+l5KXTigsdAhz5DyVgU3xs+EnaIZxBwcE7EKzjMam+V9rlRy0CGsiQ1kjqqLzfAAQLsoVO0Vu5gVmgc8XGQ7xYhoz36rsBgMjG+e3l/B01esQi/KzPuBf/Ar8Sg5aSEOvEU0muSDb+KIr6d8eEC+FtcAAPZEaBSt4ysXVL84LUcJemQD3SiG30kOfUpF8o7/wI2M2Jf/LyCsbKEQUyLtLbZqnJBSfZJR5AMsrnHDqngMLEGAAY4UDG9GCpRuPvg8hOlsrXuPP3zq7yVPqyG0SG+bNo8rEhP5b1vXlHdG4bZsutX47d5VZ6xnFROKudx3T3/fnWUAQgAU1+kUFc3e0ZZeX1dLRVEryNIVyxMQIcxWwdey+jlIAYowHRM0fJX3Scs80OnT/CERwh5LMlFyU1w578NqxW+AQl2E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c_examples::vaa_example)]
pub vaa: Option<Base64String>, pub vaa: Option<Base64String>,
} }
@ -141,7 +140,7 @@ pub struct RpcPrice {
pub expo: i32, pub expo: i32,
/// When the price was published. The `publish_time` is a unix timestamp, i.e., the number of /// When the price was published. The `publish_time` is a unix timestamp, i.e., the number of
/// seconds since the Unix epoch (00:00:00 UTC on 1 Jan 1970). /// seconds since the Unix epoch (00:00:00 UTC on 1 Jan 1970).
#[schema(value_type = i64, example=1690576641)] #[schema(value_type = i64, example=doc_examples::timestamp_example)]
pub publish_time: UnixTimestamp, pub publish_time: UnixTimestamp,
} }
@ -163,7 +162,7 @@ pub struct RpcPrice {
ToSchema, ToSchema,
)] )]
#[repr(C)] #[repr(C)]
#[schema(value_type = String, example = "e62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43")] #[schema(value_type = String, example = doc_examples::price_feed_id_example)]
pub struct RpcPriceIdentifier(#[serde(with = "hex")] [u8; 32]); pub struct RpcPriceIdentifier(#[serde(with = "hex")] [u8; 32]);
impl RpcPriceIdentifier { impl RpcPriceIdentifier {

View File

@ -0,0 +1,32 @@
use crate::store::types::UnixTimestamp;
// Example values for the utoipa API docs.
// Note that each of these expressions is only evaluated once when the documentation is created,
// so the examples don't auto-update over time. We may want to adjust these examples for
// stable/beta in the future so that the example values in the docs work for both hermes and hermes-beta.
// (Currently all example values are for stable.)
/// Example value for a price feed id
pub fn price_feed_id_example() -> &'static str {
return "e62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43";
}
/// Example value for a unix timestamp
pub fn timestamp_example() -> UnixTimestamp {
use std::time::{
SystemTime,
UNIX_EPOCH,
};
let start = SystemTime::now();
let since_the_epoch = start
.duration_since(UNIX_EPOCH)
.expect("Time went backwards");
return since_the_epoch.as_secs() as UnixTimestamp;
}
/// Example value for a VAA
pub fn vaa_example() -> &'static str {
return "UE5BVQEAAAADuAEAAAADDQC1H7meY5fTed0FsykIb8dt+7nKpbuzfvU2D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C8OPFpyKYcp6iD5l7cO/gRDTamLFyhiUBwKKMP07FAWTEJv8AAAAAABrhAfrtrFhR4yubI7X5QRqMK6xKrj7U3XuBHdGnLqSqcQAAAAAAGp0GAUFVV1YAAAAAAAUYUmIAACcQBsfKUtr4PgZbIXRxRESU79PjE4IBAFUA5i32yLSoX+GmfbRNwS3l2zMPesZrctxliv7fD0pBW0MAAAKqqMJFwAAAAAAqE/NX////+AAAAABkxCb7AAAAAGTEJvoAAAKqIcWxYAAAAAAlR5m4CP/mPsh1IezjYpDlJ4GRb5q4fTs2LjtyO6M0XgVimrIQ4kSh1qg7JKW4gbGkyRntVFR9JO/GNd3FPDit0BK6M+JzXh/h12YNCz9wxlZTvXrNtWNbzqT+91pvl5cphhSPMfAHyEzTPaGR9tKDy9KNu56pmhaY32d2vfEWQmKo22guegeR98oDxs67MmnUraco46a3zEnac2Bm80pasUgMO24=";
}

View File

@ -10,6 +10,7 @@ use {
mod api; mod api;
mod config; mod config;
mod doc_examples;
mod macros; mod macros;
mod network; mod network;
mod store; mod store;