iota_json_rpc_api/
extended.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    AddressMetrics, EpochInfo, EpochMetrics, EpochMetricsPage, EpochPage, MoveCallMetrics,
7    NetworkMetrics, Page, ParticipationMetrics,
8};
9use iota_open_rpc_macros::open_rpc;
10use iota_types::iota_serde::BigInt;
11use jsonrpsee::{core::RpcResult, proc_macros::rpc};
12
13/// Methods served exclusively by the indexer, supporting queries using refined
14/// filters and providing access to system info and metrics.
15#[open_rpc(namespace = "iotax", tag = "Extended API")]
16#[rpc(server, client, namespace = "iotax")]
17pub trait ExtendedApi {
18    /// Return a list of epoch info. Exclusively served by the indexer.
19    #[rustfmt::skip]
20    #[method(name = "getEpochs")]
21    #[schemars(with = "Page<EpochInfo, String>")]
22    async fn get_epochs(
23        &self,
24        /// Optional paging cursor
25        #[schemars(with = "Option<String>")]
26        cursor: Option<BigInt<u64>>,
27        /// Maximum number of items per page
28        limit: Option<usize>,
29        /// Flag to return results in descending order
30        descending_order: Option<bool>,
31    ) -> RpcResult<EpochPage>;
32
33    /// Return a list of epoch metrics, which is a subset of epoch info.
34    /// Exclusively served by the indexer.
35    #[method(name = "getEpochMetrics")]
36    #[schemars(with = "Page<EpochMetrics, String>")]
37    async fn get_epoch_metrics(
38        &self,
39        /// Optional paging cursor
40        #[schemars(with = "Option<String>")]
41        cursor: Option<BigInt<u64>>,
42        /// Maximum number of items per page
43        limit: Option<usize>,
44        /// Flag to return results in descending order
45        descending_order: Option<bool>,
46    ) -> RpcResult<EpochMetricsPage>;
47
48    /// Return current epoch info. Exclusively served by the indexer.
49    #[method(name = "getCurrentEpoch")]
50    async fn get_current_epoch(&self) -> RpcResult<EpochInfo>;
51
52    /// Return Network metrics. Exclusively served by the indexer.
53    #[method(name = "getNetworkMetrics")]
54    async fn get_network_metrics(&self) -> RpcResult<NetworkMetrics>;
55
56    /// Return move call metrics. Exclusively served by the indexer.
57    #[method(name = "getMoveCallMetrics")]
58    async fn get_move_call_metrics(&self) -> RpcResult<MoveCallMetrics>;
59
60    /// Address related metrics. Exclusively served by the indexer.
61    #[method(name = "getLatestAddressMetrics")]
62    async fn get_latest_address_metrics(&self) -> RpcResult<AddressMetrics>;
63
64    /// Address related metrics. Exclusively served by the indexer.
65    #[method(name = "getCheckpointAddressMetrics")]
66    async fn get_checkpoint_address_metrics(&self, checkpoint: u64) -> RpcResult<AddressMetrics>;
67
68    /// Address related metrics. Exclusively served by the indexer.
69    #[method(name = "getAllEpochAddressMetrics")]
70    async fn get_all_epoch_address_metrics(
71        &self,
72        descending_order: Option<bool>,
73    ) -> RpcResult<Vec<AddressMetrics>>;
74
75    /// Return the total number of transactions. Exclusively served by the
76    /// indexer.
77    #[method(name = "getTotalTransactions")]
78    #[schemars(with = "String")]
79    async fn get_total_transactions(&self) -> RpcResult<BigInt<u64>>;
80
81    /// Returns the participation metrics. Participation is defined as the total
82    /// number of unique addresses that have delegated stake in the current
83    /// epoch. Includes both staked and timelocked staked IOTA.
84    /// Exclusively served by the indexer.
85    #[method(name = "getParticipationMetrics")]
86    async fn get_participation_metrics(&self) -> RpcResult<ParticipationMetrics>;
87}