Skip to content

Commit

Permalink
fix: some renames
Browse files Browse the repository at this point in the history
  • Loading branch information
guibescos committed Sep 4, 2024
1 parent 37c33d3 commit 863c5e8
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 2 deletions.
114 changes: 114 additions & 0 deletions apps/hermes/server/src/api/rest/v2/latest_publisher_stake_caps.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
use {
crate::{
api::{
rest::RestError,
types::{
BinaryUpdate,
EncodingType,
ParsedPublisherStakeCapsUpdate,
},
ApiState,
},
state::Aggregates,
},
anyhow::Result,
axum::{
extract::State,
Json,
},
base64::{
engine::general_purpose::STANDARD as base64_standard_engine,
Engine as _,
},
serde::{
Deserialize,
Serialize,
},
serde_qs::axum::QsQuery,
utoipa::{
IntoParams,
ToSchema,
},
};


#[derive(Debug, Deserialize, IntoParams)]
#[into_params(parameter_in=Query)]
pub struct LatestPublisherStakeCapsUpdateData {
/// Get the most recent publisher stake caps update data.

/// Optional encoding type. If true, return the message in the encoding specified by the encoding parameter. Default is `hex`.
#[serde(default)]
encoding: EncodingType,

/// If true, include the parsed update in the `parsed` field of each returned feed. Default is `true`.
#[serde(default = "default_true")]
parsed: bool,
}

fn default_true() -> bool {
true
}

#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct LatestPublisherStakeCapsUpdateDataResponse {
pub binary: BinaryUpdate,
#[serde(skip_serializing_if = "Option::is_none")]
pub parsed: Option<Vec<ParsedPublisherStakeCapsUpdate>>,
}

/// Get the most recent publisher stake caps update data.
#[utoipa::path(
get,
path = "/v2/updates/publisher_stake_caps/latest",
responses(
(status = 200, description = "Publisher stake caps update data retrieved succesfully", body = Vec<PriceFeedMetadata>)
),
params(
LatestPublisherStakeCapsUpdateData
)
)]
pub async fn latest_publisher_stake_caps<S>(
State(state): State<ApiState<S>>,
QsQuery(params): QsQuery<LatestPublisherStakeCapsUpdateData>,
) -> Result<Json<LatestPublisherStakeCapsUpdateDataResponse>, RestError>
where
S: Aggregates,
{
let state = &*state.state;
let publisher_stake_caps_with_update_data =
Aggregates::get_latest_publisher_stake_caps_with_update_data(state)
.await
.map_err(|e| {
tracing::warn!(
"Error getting publisher stake caps with update data: {:?}",
e
);
RestError::UpdateDataNotFound
})?;

let encoded_data: Vec<String> = publisher_stake_caps_with_update_data
.update_data
.into_iter()
.map(|data| match params.encoding {
EncodingType::Base64 => base64_standard_engine.encode(data),
EncodingType::Hex => hex::encode(data),
})
.collect();

let binary = BinaryUpdate {
encoding: params.encoding,
data: encoded_data,
};

let parsed: Option<Vec<ParsedPublisherStakeCapsUpdate>> = if params.parsed {
Some(publisher_stake_caps_with_update_data.publisher_stake_caps)
} else {
None
};

Ok(Json(LatestPublisherStakeCapsUpdateDataResponse {
binary,
parsed,
}))
}
4 changes: 2 additions & 2 deletions apps/hermes/server/src/state/aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ where
price_ids: &[PriceIdentifier],
request_time: RequestTime,
) -> Result<PriceFeedsWithUpdateData>;
async fn get_publisher_stake_caps_with_update_data(
async fn get_latest_publisher_stake_caps_with_update_data(
&self,
) -> Result<PublisherStakeCapsWithUpdateData>;
}
Expand Down Expand Up @@ -417,7 +417,7 @@ where
}
}

async fn get_publisher_stake_caps_with_update_data(
async fn get_latest_publisher_stake_caps_with_update_data(
&self,
) -> Result<PublisherStakeCapsWithUpdateData> {
let messages = self
Expand Down

0 comments on commit 863c5e8

Please sign in to comment.