-
Notifications
You must be signed in to change notification settings - Fork 65
ssv-network: SSV-node API support #415
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
Open
iurii-ssv
wants to merge
7
commits into
Commit-Boost:main
Choose a base branch
from
iurii-ssv:ssv-network-ssv-node-api-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
250814b
ssv-network: SSV-node API support
iurii-ssv 9ff2cd0
Clippy and some naming clarification
jclapis 6e583b2
Changed SSV config to have both node and public URLs
jclapis f1dffff
Added a unit test for the SSV node mock
jclapis 0183a74
Added a unit test for failover from local SSV node to public API
jclapis aa32aaf
Fixed some missing type renames
jclapis 31fcc26
Merge branch 'main' into pr-415
jclapis 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,24 +1,52 @@ | ||
| use std::time::Duration; | ||
|
|
||
| use alloy::primitives::U256; | ||
| use eyre::Context; | ||
| use serde_json::json; | ||
| use url::Url; | ||
|
|
||
| use crate::{config::safe_read_http_response, interop::ssv::types::SSVResponse}; | ||
| use crate::{ | ||
| config::safe_read_http_response, | ||
| interop::ssv::types::{SSVNodeResponse, SSVPublicResponse}, | ||
| }; | ||
|
|
||
| pub async fn fetch_ssv_pubkeys_from_url( | ||
| pub async fn request_ssv_pubkeys_from_ssv_node( | ||
| url: Url, | ||
| node_operator_id: U256, | ||
| http_timeout: Duration, | ||
| ) -> eyre::Result<SSVResponse> { | ||
| ) -> eyre::Result<SSVNodeResponse> { | ||
| let client = reqwest::ClientBuilder::new().timeout(http_timeout).build()?; | ||
| let body = json!({ | ||
| "operators": [node_operator_id] | ||
| }); | ||
| let response = client.get(url).json(&body).send().await.map_err(|e| { | ||
| if e.is_timeout() { | ||
| eyre::eyre!("Request to SSV node timed out: {e}") | ||
| } else { | ||
| eyre::eyre!("Error sending request to SSV node: {e}") | ||
| } | ||
| })?; | ||
|
|
||
| // Parse the response as JSON | ||
| let body_bytes = safe_read_http_response(response).await?; | ||
| serde_json::from_slice::<SSVNodeResponse>(&body_bytes).wrap_err("failed to parse SSV response") | ||
| } | ||
|
|
||
| pub async fn request_ssv_pubkeys_from_public_api( | ||
| url: Url, | ||
| http_timeout: Duration, | ||
| ) -> eyre::Result<SSVPublicResponse> { | ||
| let client = reqwest::ClientBuilder::new().timeout(http_timeout).build()?; | ||
| let response = client.get(url).send().await.map_err(|e| { | ||
| if e.is_timeout() { | ||
| eyre::eyre!("Request to SSV network API timed out: {e}") | ||
| eyre::eyre!("Request to SSV public API timed out: {e}") | ||
| } else { | ||
| eyre::eyre!("Error sending request to SSV network API: {e}") | ||
| eyre::eyre!("Error sending request to SSV public API: {e}") | ||
| } | ||
| })?; | ||
|
|
||
| // Parse the response as JSON | ||
| let body_bytes = safe_read_http_response(response).await?; | ||
| serde_json::from_slice::<SSVResponse>(&body_bytes).wrap_err("failed to parse SSV response") | ||
| serde_json::from_slice::<SSVPublicResponse>(&body_bytes) | ||
| .wrap_err("failed to parse SSV response") | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| { | ||
| "data": [ | ||
| { | ||
| "public_key": "aa370f6250d421d00437b9900407a7ad93b041aeb7259d99b55ab8b163277746680e93e841f87350737bceee46aa104d", | ||
| "index": "1311498", | ||
| "status": "active_ongoing", | ||
| "activation_epoch": "273156", | ||
| "exit_epoch": "18446744073709551615", | ||
| "owner": "5e33db0b37622f7e6b2f0654aa7b985d854ea9cb", | ||
| "committee": [ | ||
| 1, | ||
| 2, | ||
| 3, | ||
| 4 | ||
| ], | ||
| "quorum": 0, | ||
| "partial_quorum": 0, | ||
| "graffiti": "", | ||
| "liquidated": false | ||
| } | ||
| ] | ||
| } |
File renamed without changes.
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 |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| pub mod mock_relay; | ||
| pub mod mock_ssv; | ||
| pub mod mock_ssv_node; | ||
| pub mod mock_ssv_public; | ||
| pub mod mock_validator; | ||
| pub mod utils; |
Oops, something went wrong.
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.