Skip to main content

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