Skip to content
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

Add GET /api/core/v3/committee/ route #1055

Merged
merged 34 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
8b975e4
Update info response and related structs
Aug 16, 2023
c4aac92
display
Aug 16, 2023
7f229d8
fix wasm, no_std and test
Aug 16, 2023
ec0a0f9
fix one more test
Aug 17, 2023
89b3616
Merge branch '2.0' into feat/info-response
Aug 17, 2023
3f11a3b
Merge branch '2.0' into feat/info-response
Aug 18, 2023
d729d29
Merge branch '2.0' into feat/info-response
Aug 18, 2023
7c2dec2
Implement mapped params, epoch index, helpers
Aug 21, 2023
c342573
fix tests, wasm
Aug 21, 2023
4c0d9ab
Add GET /api/core/v3/committee/ route
Aug 21, 2023
f8010d1
copy/paste oopsie
Aug 22, 2023
ab9e87e
Merge branch '2.0' into feat/info-response
Aug 22, 2023
4a3c845
tangle time
Aug 22, 2023
a96ad21
suggestions
Aug 22, 2023
c3da95e
more renames
Aug 22, 2023
1818887
Merge branch '2.0' into feat/info-response
Aug 22, 2023
7e11228
More cleanup
Aug 23, 2023
5a038fb
Merge branch 'feat/info-response' into feat/committee
Aug 23, 2023
1bab1db
Merge branch '2.0' into feat/info-response
Aug 23, 2023
70c39f3
Merge branch '2.0' into feat/info-response
Aug 23, 2023
e938ae9
Merge branch 'feat/info-response' into feat/committee
Aug 23, 2023
d682450
as -> to
Aug 23, 2023
e4cc3a5
harmony and peace
Aug 23, 2023
13b2a7c
derive
Aug 23, 2023
668b190
suggestion
Aug 23, 2023
ecb3212
another missed derive
Aug 23, 2023
2f77a9c
oops
Aug 23, 2023
bf7d87b
Always get v3 params for now. Add flexible epoch index calculation fo…
Aug 23, 2023
b58353a
fix wasm
Aug 23, 2023
f0564dc
Merge branch 'feat/info-response' into feat/committee
Aug 24, 2023
ece5480
Merge branch '2.0' into feat/committee
Aug 25, 2023
82aa357
fix merge
Aug 25, 2023
4ad33cd
PR suggestions
Aug 28, 2023
263fb63
revert order
Aug 28, 2023
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
21 changes: 18 additions & 3 deletions sdk/src/client/node_api/core/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ use crate::{
},
types::{
api::core::response::{
BlockMetadataResponse, CongestionResponse, InfoResponse, IssuanceBlockHeaderResponse, ManaRewardsResponse,
PeerResponse, RoutesResponse, SubmitBlockResponse, UtxoChangesResponse,
BlockMetadataResponse, CommitteeResponse, CongestionResponse, InfoResponse, IssuanceBlockHeaderResponse,
ManaRewardsResponse, PeerResponse, RoutesResponse, SubmitBlockResponse, UtxoChangesResponse,
},
block::{
output::{dto::OutputDto, AccountId, Output, OutputId, OutputMetadata},
payload::transaction::TransactionId,
slot::{SlotCommitment, SlotCommitmentId, SlotIndex},
slot::{EpochIndex, SlotCommitment, SlotCommitmentId, SlotIndex},
Block, BlockDto, BlockId,
},
TryFromDto,
Expand Down Expand Up @@ -122,6 +122,21 @@ impl ClientInner {
.await
}

/// Returns the information of committee members at the given epoch index. If epoch index is not provided, the
/// current committee members are returned.
/// GET /api/core/v3/committee/?epochIndex
pub async fn get_committee(&self, epoch_index: impl Into<Option<EpochIndex>>) -> Result<CommitteeResponse> {
const PATH: &str = "api/core/v3/committee";

let epoch_index = epoch_index.into().map(|i| format!("epochIndex={i}"));

self.node_manager
.read()
.await
.get_request(PATH, epoch_index.as_deref(), self.get_timeout().await, false, false)
.await
}

// Blocks routes.

/// Returns information that is ideal for attaching a block in the network.
Expand Down
47 changes: 44 additions & 3 deletions sdk/src/types/api/core/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use alloc::{boxed::Box, collections::BTreeMap, string::String, vec::Vec};

use crate::types::block::{
output::{dto::OutputDto, OutputId, OutputMetadata, OutputWithMetadata},
output::{dto::OutputDto, AccountId, OutputId, OutputMetadata, OutputWithMetadata},
parent::{ShallowLikeParents, StrongParents, WeakParents},
protocol::ProtocolParameters,
semantic::TransactionFailureReason,
Expand Down Expand Up @@ -185,8 +185,49 @@ pub struct BaseTokenResponse {
pub use_metric_prefix: bool,
}

/// Response of
/// - GET /api/core/v3/blocks/issuance
/// Response of GET /api/core/v3/committee
/// The validator information of the committee.
#[derive(Clone, Debug, Eq, PartialEq)]
#[cfg_attr(
feature = "serde",
derive(serde::Serialize, serde::Deserialize),
serde(rename_all = "camelCase")
)]
pub struct CommitteeResponse {
/// The epoch index of the committee.
pub epoch_index: EpochIndex,
thibault-martinez marked this conversation as resolved.
Show resolved Hide resolved
/// The total amount of delegated and staked IOTA tokens in the selected committee.
#[serde(with = "crate::utils::serde::string")]
pub total_stake: u64,
/// The total amount of staked IOTA tokens in the selected committee.
#[serde(with = "crate::utils::serde::string")]
pub total_validator_stake: u64,
/// The validators of the committee.
pub committee: Box<[CommitteeMember]>,
}

/// Validator information.
#[derive(Clone, Debug, Eq, PartialEq)]
#[cfg_attr(
feature = "serde",
derive(serde::Serialize, serde::Deserialize),
serde(rename_all = "camelCase")
)]
pub struct CommitteeMember {
/// The account identifier of the validator
pub account_id: AccountId,
/// The total stake of the pool, including delegators.
#[serde(with = "crate::utils::serde::string")]
pub pool_stake: u64,
/// The stake of a validator.
#[serde(with = "crate::utils::serde::string")]
pub validator_stake: u64,
/// The fixed cost of the validator, which it receives as part of its Mana rewards.
#[serde(with = "crate::utils::serde::string")]
pub fixed_cost: u64,
}

/// Response of GET /api/core/v3/blocks/issuance
/// Information that is ideal for attaching a block in the network.
#[derive(Clone, Debug, Eq, PartialEq)]
#[cfg_attr(
Expand Down
Loading