iota_types/stardust/address.rs
1// Copyright (c) 2024 IOTA Stiftung
2// SPDX-License-Identifier: Apache-2.0
3
4use iota_stardust_sdk::types::block::address::Address;
5
6use crate::{base_types::IotaAddress, object::Owner};
7
8/// Converts a ["Stardust" `Address`](Address) to a [`IotaAddress`].
9///
10/// This is intended as the only conversion function to go from Stardust to IOTA
11/// addresses, so there is only one place to potentially update it if we decide
12/// to change it later.
13pub fn stardust_to_iota_address(
14 stardust_address: impl Into<Address>,
15) -> anyhow::Result<IotaAddress> {
16 stardust_address.into().to_string().parse()
17}
18
19/// Converts a ["Stardust" `Address`](Address) to a [`IotaAddress`] and then
20/// wraps it into an [`Owner`] which is either address- or object-owned
21/// depending on the stardust address.
22pub fn stardust_to_iota_address_owner(
23 stardust_address: impl Into<Address>,
24) -> anyhow::Result<Owner> {
25 stardust_to_iota_address(stardust_address.into()).map(Owner::AddressOwner)
26}