-
Notifications
You must be signed in to change notification settings - Fork 300
feat: update hermes to support publisher stake caps #1866
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
guibescos
merged 13 commits into
main
from
feat/update-hermes-to-support-publisher-stake-caps
Sep 4, 2024
Merged
Changes from 8 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
87f155c
go
guibescos 7872ba4
go
guibescos 7dc0c8a
works
guibescos 49cc664
go
guibescos b031a34
add this file too
guibescos bb71c4b
rename
guibescos 0a23da5
cleanup
guibescos d4066bf
udno dependency update
guibescos e6ca3c8
fix: use v2 routes
guibescos 37c33d3
fix: move response struct
guibescos 863c5e8
fix: some renames
guibescos c4dbd1a
fix: get_price_feed_ids
guibescos 8619750
bump: hermes
guibescos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
apps/hermes/server/src/api/rest/get_publisher_stake_caps_update_data.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
use { | ||
crate::{ | ||
api::{ | ||
rest::RestError, | ||
types::{ | ||
BinaryUpdate, | ||
EncodingType, | ||
GetPublisherStakeCapsUpdateDataResponse, | ||
ParsedPublisherStakeCapsUpdate, | ||
}, | ||
ApiState, | ||
}, | ||
state::Aggregates, | ||
}, | ||
anyhow::Result, | ||
axum::{ | ||
extract::State, | ||
Json, | ||
}, | ||
base64::{ | ||
engine::general_purpose::STANDARD as base64_standard_engine, | ||
Engine as _, | ||
}, | ||
serde::Deserialize, | ||
serde_qs::axum::QsQuery, | ||
utoipa::IntoParams, | ||
}; | ||
|
||
|
||
#[derive(Debug, Deserialize, IntoParams)] | ||
#[into_params(parameter_in=Query)] | ||
pub struct GetPublisherStakeCapsUpdateData { | ||
/// 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 | ||
} | ||
|
||
|
||
/// Get the publisher stake caps update data | ||
#[utoipa::path( | ||
get, | ||
path = "/api/get_publisher_stake_caps_update_data", | ||
responses( | ||
(status = 200, description = "Publisher stake caps update data retrieved succesfully", body = Vec<PriceFeedMetadata>) | ||
), | ||
params( | ||
GetPublisherStakeCapsUpdateData | ||
) | ||
)] | ||
pub async fn get_publisher_stake_caps_update_data<S>( | ||
State(state): State<ApiState<S>>, | ||
QsQuery(params): QsQuery<GetPublisherStakeCapsUpdateData>, | ||
) -> Result<Json<GetPublisherStakeCapsUpdateDataResponse>, RestError> | ||
where | ||
S: Aggregates, | ||
{ | ||
let state = &*state.state; | ||
let publisher_stake_caps_with_update_data = | ||
Aggregates::get_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(GetPublisherStakeCapsUpdateDataResponse { | ||
binary, | ||
parsed, | ||
})) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.