iota_grpc_client/api/ledger/
service_info.rs

1// Copyright (c) 2026 IOTA Stiftung
2// SPDX-License-Identifier: Apache-2.0
3
4//! High-level API for service info queries.
5
6use iota_grpc_types::v1::ledger_service::{GetServiceInfoRequest, GetServiceInfoResponse};
7
8use crate::{
9    Client,
10    api::{GET_SERVICE_INFO_READ_MASK, MetadataEnvelope, Result, field_mask_with_default},
11};
12
13impl Client {
14    /// Get service info from the node.
15    ///
16    /// Returns the [`GetServiceInfoResponse`] proto type with fields populated
17    /// according to the `read_mask`.
18    ///
19    /// # Available Read Mask Fields
20    ///
21    /// The optional `read_mask` parameter controls which fields the server
22    /// returns. If `None`, uses [`GET_SERVICE_INFO_READ_MASK`].
23    ///
24    /// ## Network Fields
25    /// - `chain_id` - the ID of the chain, which can be used to identify the
26    ///   network
27    /// - `chain` - the chain identifier, which can be used to identify the
28    ///   network
29    ///
30    /// ## Current State Fields
31    /// - `epoch` - the current epoch
32    /// - `executed_checkpoint_height` - the height of the last executed
33    ///   checkpoint
34    /// - `executed_checkpoint_timestamp` - the timestamp of the last executed
35    ///   checkpoint
36    ///
37    /// ## Availability Fields
38    /// - `lowest_available_checkpoint` - lowest available checkpoint for which
39    ///   transaction and checkpoint data can be requested
40    /// - `lowest_available_checkpoint_objects` - lowest available checkpoint
41    ///   for which object data can be requested
42    ///
43    /// ## Server Fields
44    /// - `server` - the server version
45    ///
46    /// # Example
47    ///
48    /// ```no_run
49    /// # use iota_grpc_client::Client;
50    /// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
51    /// let client = Client::connect("http://localhost:9000").await?;
52    ///
53    /// // Get service info with default fields
54    /// let info = client.get_service_info(None).await?;
55    /// println!("Chain ID: {:?}", info.body().chain_id);
56    /// println!("Epoch: {:?}", info.body().epoch);
57    ///
58    /// // Get service info with all fields
59    /// let info = client
60    ///     .get_service_info(Some(
61    ///         "chain_id,chain,epoch,executed_checkpoint_height,\
62    ///          executed_checkpoint_timestamp,lowest_available_checkpoint,\
63    ///          lowest_available_checkpoint_objects,server",
64    ///     ))
65    ///     .await?;
66    /// # Ok(())
67    /// # }
68    /// ```
69    pub async fn get_service_info(
70        &self,
71        read_mask: Option<&str>,
72    ) -> Result<MetadataEnvelope<GetServiceInfoResponse>> {
73        let request = GetServiceInfoRequest::default().with_read_mask(field_mask_with_default(
74            read_mask,
75            GET_SERVICE_INFO_READ_MASK,
76        ));
77
78        let mut client = self.ledger_service_client();
79        let response = client.get_service_info(request).await?;
80
81        Ok(MetadataEnvelope::from(response))
82    }
83}