iota_json_rpc_api/
governance.rs

1// Copyright (c) Mysten Labs, Inc.
2// Modifications Copyright (c) 2024 IOTA Stiftung
3// SPDX-License-Identifier: Apache-2.0
4
5use iota_json_rpc_types::{DelegatedStake, DelegatedTimelockedStake, IotaCommittee, ValidatorApys};
6use iota_open_rpc_macros::open_rpc;
7use iota_types::{
8    base_types::{IotaAddress, ObjectID},
9    iota_serde::BigInt,
10    iota_system_state::iota_system_state_summary::{
11        IotaSystemStateSummary, IotaSystemStateSummaryV1,
12    },
13};
14use jsonrpsee::{core::RpcResult, proc_macros::rpc};
15
16/// Provides access to validator and staking-related data such as current
17/// committee info, delegated stakes, and APY.
18#[open_rpc(namespace = "iotax", tag = "Governance Read API")]
19#[rpc(server, client, namespace = "iotax")]
20pub trait GovernanceReadApi {
21    /// Return one or more [DelegatedStake]. If a Stake was withdrawn its status
22    /// will be Unstaked.
23    #[method(name = "getStakesByIds")]
24    async fn get_stakes_by_ids(
25        &self,
26        staked_iota_ids: Vec<ObjectID>,
27    ) -> RpcResult<Vec<DelegatedStake>>;
28
29    /// Return all [DelegatedStake].
30    #[method(name = "getStakes")]
31    async fn get_stakes(&self, owner: IotaAddress) -> RpcResult<Vec<DelegatedStake>>;
32
33    /// Return one or more [DelegatedTimelockedStake]. If a Stake was withdrawn
34    /// its status will be Unstaked.
35    #[method(name = "getTimelockedStakesByIds")]
36    async fn get_timelocked_stakes_by_ids(
37        &self,
38        timelocked_staked_iota_ids: Vec<ObjectID>,
39    ) -> RpcResult<Vec<DelegatedTimelockedStake>>;
40
41    /// Return all [DelegatedTimelockedStake].
42    #[method(name = "getTimelockedStakes")]
43    async fn get_timelocked_stakes(
44        &self,
45        owner: IotaAddress,
46    ) -> RpcResult<Vec<DelegatedTimelockedStake>>;
47
48    /// Return the committee information for the asked `epoch`.
49    #[method(name = "getCommitteeInfo")]
50    async fn get_committee_info(
51        &self,
52        /// The epoch of interest. If None, default to the latest epoch
53        epoch: Option<BigInt<u64>>,
54    ) -> RpcResult<IotaCommittee>;
55
56    /// Return the latest IOTA system state object on networks supporting
57    /// protocol version `>= 5`. These are networks with node software release
58    /// version `>= 0.11`.
59    #[method(name = "getLatestIotaSystemStateV2")]
60    async fn get_latest_iota_system_state_v2(&self) -> RpcResult<IotaSystemStateSummary>;
61
62    /// Return the latest IOTA system state object on networks supporting
63    /// protocol version `< 5`. These are networks with node software release
64    /// version `< 0.11`.
65    #[method(name = "getLatestIotaSystemState")]
66    #[deprecated(since = "0.11.0", note = "Use get_latest_iota_system_state_v2 instead")]
67    async fn get_latest_iota_system_state(&self) -> RpcResult<IotaSystemStateSummaryV1>;
68
69    /// Return the reference gas price for the network
70    #[method(name = "getReferenceGasPrice")]
71    async fn get_reference_gas_price(&self) -> RpcResult<BigInt<u64>>;
72
73    /// Return the validator APY
74    #[method(name = "getValidatorsApy")]
75    async fn get_validators_apy(&self) -> RpcResult<ValidatorApys>;
76}