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