Skip to content

Implement Cardano stake distribution in mithril-client library #1882

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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ As a minor extension, we have adopted a slightly different versioning convention

- Implement the signable and artifact builders for the signed entity type `CardanoStakeDistribution`.
- Implement the HTTP routes related to the signed entity type `CardanoStakeDistribution` on the aggregator REST API.
- Added support in the `mithril-client` library for retrieving `CardanoStakeDistribution` by epoch or by hash, and for listing all available `CardanoStakeDistribution`.

- Crates versions:

Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mithril-client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mithril-client"
version = "0.8.11"
version = "0.8.12"
description = "Mithril client library"
authors = { workspace = true }
edition = { workspace = true }
Expand Down
49 changes: 49 additions & 0 deletions mithril-client/src/aggregator_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use tokio::sync::RwLock;
use mithril_common::entities::{ClientError, ServerError};
use mithril_common::MITHRIL_API_VERSION_HEADER;

use crate::common::Epoch;
use crate::{MithrilError, MithrilResult};

/// Error tied with the Aggregator client
Expand Down Expand Up @@ -92,6 +93,24 @@ pub enum AggregatorRequest {
/// Lists the aggregator [Cardano transaction snapshot][crate::CardanoTransactionSnapshot]
#[cfg(feature = "unstable")]
ListCardanoTransactionSnapshots,

/// Get a specific [Cardano stake distribution][crate::CardanoStakeDistribution] from the aggregator by hash
#[cfg(feature = "unstable")]
GetCardanoStakeDistribution {
/// Hash of the Cardano stake distribution to retrieve
hash: String,
},

/// Get a specific [Cardano stake distribution][crate::CardanoStakeDistribution] from the aggregator by epoch
#[cfg(feature = "unstable")]
GetCardanoStakeDistributionByEpoch {
/// Epoch at the end of which the Cardano stake distribution is computed by the Cardano node
epoch: Epoch,
},

/// Lists the aggregator [Cardano stake distribution][crate::CardanoStakeDistribution]
#[cfg(feature = "unstable")]
ListCardanoStakeDistributions,
}

impl AggregatorRequest {
Expand Down Expand Up @@ -130,6 +149,18 @@ impl AggregatorRequest {
AggregatorRequest::ListCardanoTransactionSnapshots => {
"artifact/cardano-transactions".to_string()
}
#[cfg(feature = "unstable")]
AggregatorRequest::GetCardanoStakeDistribution { hash } => {
format!("artifact/cardano-stake-distribution/{hash}")
}
#[cfg(feature = "unstable")]
AggregatorRequest::GetCardanoStakeDistributionByEpoch { epoch } => {
format!("artifact/cardano-stake-distribution/epoch/{epoch}")
}
#[cfg(feature = "unstable")]
AggregatorRequest::ListCardanoStakeDistributions => {
"artifact/cardano-stake-distributions".to_string()
}
}
}

Expand Down Expand Up @@ -542,6 +573,24 @@ mod tests {
"artifact/cardano-transactions".to_string(),
AggregatorRequest::ListCardanoTransactionSnapshots.route()
);

assert_eq!(
"artifact/cardano-stake-distribution/abc".to_string(),
AggregatorRequest::GetCardanoStakeDistribution {
hash: "abc".to_string()
}
.route()
);

assert_eq!(
"artifact/cardano-stake-distribution/epoch/123".to_string(),
AggregatorRequest::GetCardanoStakeDistributionByEpoch { epoch: Epoch(123) }.route()
);

assert_eq!(
"artifact/cardano-stake-distributions".to_string(),
AggregatorRequest::ListCardanoStakeDistributions.route()
);
}
}

Expand Down
Loading
Loading