iota_types/
coin_manager.rs1use iota_sdk_move_types::iota_framework::object::UID;
5use iota_sdk_types::ObjectData;
6use serde::{Deserialize, Serialize};
7
8use crate::{
9 coin::{CoinMetadata, TreasuryCap},
10 error::IotaError,
11 object::Object,
12};
13
14#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq)]
21pub struct CoinManager {
22 pub id: UID,
24 pub treasury_cap: TreasuryCap,
26 pub metadata: Option<CoinMetadata>,
28 pub immutable_metadata: Option<ImmutableCoinMetadata>,
31 pub maximum_supply: Option<u64>,
34 pub supply_immutable: bool,
37 pub metadata_immutable: bool,
40}
41
42impl CoinManager {
43 pub fn from_bcs_bytes(content: &[u8]) -> Result<Self, IotaError> {
44 bcs::from_bytes(content).map_err(|err| IotaError::ObjectDeserialization {
45 error: format!("Unable to deserialize CoinManager object: {err}"),
46 })
47 }
48}
49
50#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq)]
53pub struct ImmutableCoinMetadata {
54 pub decimals: u8,
56 pub name: String,
58 pub symbol: String,
60 pub description: String,
62 pub icon_url: Option<String>,
64}
65
66impl TryFrom<Object> for CoinManager {
67 type Error = IotaError;
68 fn try_from(object: Object) -> Result<Self, Self::Error> {
69 TryFrom::try_from(&object)
70 }
71}
72
73impl TryFrom<&Object> for CoinManager {
74 type Error = IotaError;
75 fn try_from(object: &Object) -> Result<Self, Self::Error> {
76 if let ObjectData::Struct(o) = &object.data {
77 if o.struct_tag().is_coin_manager() {
78 return CoinManager::from_bcs_bytes(o.contents());
79 }
80 }
81
82 Err(IotaError::Type {
83 error: format!("Object type is not a CoinManager: {object:?}"),
84 })
85 }
86}