Skip to main content

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_sdk_types::{Address, ObjectId};
8use schemars::JsonSchema;
9use serde::{Deserialize, Serialize};
10use serde_with::serde_as;
11
12use crate::iota_primitives::{Address as AddressSchema, ObjectId as ObjectIdSchema};
13
14/// A single record in the registry.
15#[serde_as]
16#[derive(Serialize, Deserialize, Debug, Clone, JsonSchema)]
17#[serde(rename_all = "camelCase")]
18pub struct IotaNameRecord {
19    /// The ID of the registration NFT assigned to this record.
20    ///
21    /// The owner of the corresponding NFT has the rights to
22    /// be able to change and adjust the `target_address` of this name.
23    ///
24    /// It is possible that the ID changes if the record expires and is
25    /// purchased by someone else.
26    #[serde_as(as = "ObjectIdSchema")]
27    #[schemars(with = "ObjectIdSchema")]
28    pub nft_id: ObjectId,
29    /// Timestamp in milliseconds when the record expires.
30    pub expiration_timestamp_ms: u64,
31    /// The target address that this name points to
32    #[serde_as(as = "Option<AddressSchema>")]
33    #[schemars(with = "Option<AddressSchema>")]
34    pub target_address: Option<Address>,
35    /// Additional data which may be stored in a record
36    pub data: BTreeMap<String, String>,
37}
38
39impl From<NameRecord> for IotaNameRecord {
40    fn from(record: NameRecord) -> Self {
41        Self {
42            nft_id: record.nft_id.bytes,
43            expiration_timestamp_ms: record.expiration_timestamp_ms,
44            target_address: record.target_address,
45            data: record
46                .data
47                .contents
48                .into_iter()
49                .map(|entry| (entry.key.to_string(), entry.value))
50                .collect(),
51        }
52    }
53}