algokit_transact_ffi/transactions/
asset_freeze.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use crate::*;

/// Represents an asset freeze transaction that freezes or unfreezes asset holdings.
///
/// Asset freeze transactions are used by the asset freeze account to control
/// whether a specific account can transfer a particular asset.
#[ffi_record]
pub struct AssetFreezeTransactionFields {
    /// The ID of the asset being frozen/unfrozen.
    asset_id: u64,

    /// The target account whose asset holdings will be affected.
    freeze_target: String,

    /// The new freeze status.
    ///
    /// `true` to freeze the asset holdings (prevent transfers),
    /// `false` to unfreeze the asset holdings (allow transfers).
    frozen: bool,
}

impl From<algokit_transact::AssetFreezeTransactionFields> for AssetFreezeTransactionFields {
    fn from(tx: algokit_transact::AssetFreezeTransactionFields) -> Self {
        Self {
            asset_id: tx.asset_id,
            freeze_target: tx.freeze_target.to_string(),
            frozen: tx.frozen,
        }
    }
}

impl TryFrom<Transaction> for algokit_transact::AssetFreezeTransactionFields {
    type Error = AlgoKitTransactError;

    fn try_from(tx: Transaction) -> Result<Self, Self::Error> {
        if tx.transaction_type != TransactionType::AssetFreeze || tx.asset_freeze.is_none() {
            return Err(Self::Error::DecodingError {
                message: "Asset Freeze data missing".to_string(),
            });
        }

        let data = tx.clone().asset_freeze.unwrap();
        let header: algokit_transact::TransactionHeader = tx.try_into()?;

        Ok(Self {
            header,
            asset_id: data.asset_id,
            freeze_target: data.freeze_target.parse()?,
            frozen: data.frozen,
        })
    }
}