iota_sdk/apis/
governance.rs1use std::sync::Arc;
6
7use iota_json_rpc_api::GovernanceReadApiClient;
8use iota_json_rpc_types::{DelegatedStake, DelegatedTimelockedStake, IotaCommittee, ValidatorApys};
9use iota_types::{
10 base_types::IotaAddress, iota_serde::BigInt,
11 iota_system_state::iota_system_state_summary::IotaSystemStateSummary,
12};
13
14use crate::{RpcClient, error::IotaRpcResult};
15
16#[derive(Debug, Clone)]
18pub struct GovernanceApi {
19 api: Arc<RpcClient>,
20}
21
22impl GovernanceApi {
23 pub(crate) fn new(api: Arc<RpcClient>) -> Self {
24 Self { api }
25 }
26
27 pub async fn get_stakes(&self, owner: IotaAddress) -> IotaRpcResult<Vec<DelegatedStake>> {
29 Ok(self.api.http.get_stakes(owner).await?)
30 }
31
32 pub async fn get_timelocked_stakes(
34 &self,
35 owner: IotaAddress,
36 ) -> IotaRpcResult<Vec<DelegatedTimelockedStake>> {
37 Ok(self.api.http.get_timelocked_stakes(owner).await?)
38 }
39
40 pub async fn get_committee_info(
57 &self,
58 epoch: impl Into<Option<BigInt<u64>>>,
59 ) -> IotaRpcResult<IotaCommittee> {
60 Ok(self.api.http.get_committee_info(epoch.into()).await?)
61 }
62
63 #[allow(deprecated)]
69 pub async fn get_latest_iota_system_state(&self) -> IotaRpcResult<IotaSystemStateSummary> {
70 if self.api.info.iota_system_state_v2_support {
71 Ok(self.api.http.get_latest_iota_system_state_v2().await?)
72 } else {
73 Ok(self
75 .api
76 .http
77 .get_latest_iota_system_state()
78 .await
79 .map(IotaSystemStateSummary::from)?)
80 }
81 }
82
83 pub async fn get_reference_gas_price(&self) -> IotaRpcResult<u64> {
85 Ok(*self.api.http.get_reference_gas_price().await?)
86 }
87
88 pub async fn get_validators_apy(&self) -> IotaRpcResult<ValidatorApys> {
90 Ok(self.api.http.get_validators_apy().await?)
91 }
92}