iota_json_rpc_types/
iota_indexer.rs

1// Copyright (c) 2025 IOTA Stiftung
2// SPDX-License-Identifier: Apache-2.0
3
4use std::collections::BTreeMap;
5
6use iota_names::registry::NameRecord;
7use iota_types::base_types::{IotaAddress, ObjectID};
8use schemars::JsonSchema;
9use serde::{Deserialize, Serialize};
10use serde_with::serde_as;
11
12/// A single record in the registry.
13#[serde_as]
14#[derive(Serialize, Deserialize, Debug, Clone, JsonSchema)]
15#[serde(rename_all = "camelCase")]
16pub struct IotaNameRecord {
17    /// The ID of the registration NFT assigned to this record.
18    ///
19    /// The owner of the corresponding NFT has the rights to
20    /// be able to change and adjust the `target_address` of this domain.
21    ///
22    /// It is possible that the ID changes if the record expires and is
23    /// purchased by someone else.
24    pub nft_id: ObjectID,
25    /// Timestamp in milliseconds when the record expires.
26    pub expiration_timestamp_ms: u64,
27    /// The target address that this domain points to
28    pub target_address: Option<IotaAddress>,
29    /// Additional data which may be stored in a record
30    pub data: BTreeMap<String, String>,
31}
32
33impl From<NameRecord> for IotaNameRecord {
34    fn from(record: NameRecord) -> Self {
35        Self {
36            nft_id: record.nft_id.bytes,
37            expiration_timestamp_ms: record.expiration_timestamp_ms,
38            target_address: record.target_address,
39            data: record
40                .data
41                .contents
42                .into_iter()
43                .map(|entry| (entry.key.to_string(), entry.value.to_string()))
44                .collect(),
45        }
46    }
47}