Skip to main content

Module stardust::nft_output

use iota::address; use iota::bag; use iota::balance; use iota::coin; use iota::config; use iota::deny_list; use iota::display; use iota::dynamic_field; use iota::dynamic_object_field; use iota::event; use iota::hex; use iota::object; use iota::package; use iota::transfer; use iota::tx_context; use iota::types; use iota::url; use iota::vec_map; use stardust::expiration_unlock_condition; use stardust::irc27; use stardust::nft; use stardust::storage_deposit_return_unlock_condition; use stardust::timelock_unlock_condition; use std::address; use std::ascii; use std::bcs; use std::fixed_point32; use std::option; use std::string; use std::type_name; use std::vector;

Module Functions

pub(pkg) receive

Utility function to receive an NftOutput in other Stardust modules. Other modules in the stardust package can call this function to receive an NftOutput (alias).

public(package) fun receive<T>(parent: &mut iota::object::UID, nft: iota::transfer::Receiving<stardust::nft_output::NftOutput<T>>): stardust::nft_output::NftOutput<T>

Implementation

public(package) fun receive<T>(parent: &mut UID, nft: Receiving<NftOutput<T>>): NftOutput<T> {     transfer::receive(parent, nft) }

Structs

struct NftOutput

The Stardust NFT output representation.

public struct NftOutput<phantom T> has key

Fields
id: iota::object::UID

This is a "random" UID, not the NFTID from Stardust.

balance: iota::balance::Balance<T>

The amount of coins held by the output.

native_tokens: iota::bag::Bag

The Bag holds native tokens, key-ed by the stringified type of the asset. Example: key: "0xabcded:🔜:SOON", value: Balance<0xabcded::soon::SOON>.

storage_deposit_return_uc: std::option::Option<stardust::storage_deposit_return_unlock_condition::StorageDepositReturnUnlockCondition>

The storage deposit return unlock condition.

timelock_uc: std::option::Option<stardust::timelock_unlock_condition::TimelockUnlockCondition>

The timelock unlock condition.

expiration_uc: std::option::Option<stardust::expiration_unlock_condition::ExpirationUnlockCondition>

The expiration unlock condition.

pub attach_nft

Utility function to attach an Nft to an NftOutput.

public fun attach_nft<T>(output: &mut stardust::nft_output::NftOutput<T>, nft: stardust::nft::Nft)

Implementation

public fun attach_nft<T>(output: &mut NftOutput<T>, nft: Nft) {     dynamic_object_field::add(&mut output.id, NFT_NAME, nft) }

pub extract_assets

The function extracts assets from a legacy NFT output.

public fun extract_assets<T>(output: stardust::nft_output::NftOutput<T>, ctx: &mut iota::tx_context::TxContext): (iota::balance::Balance<T>, iota::bag::Bag, stardust::nft::Nft)

Implementation

public fun extract_assets<T>(     mut output: NftOutput<T>,     ctx: &mut TxContext, ): (Balance<T>, Bag, Nft) {     // Load the related Nft object.     let nft = load_nft(&mut output);     // Unpuck the output.     let NftOutput {         id,         balance: mut balance,         native_tokens,         storage_deposit_return_uc: mut storage_deposit_return_uc,         timelock_uc: mut timelock_uc,         expiration_uc: mut expiration_uc,     } = output;     // If the output has a timelock unlock condition, then we need to check if the timelock_uc has expired.     if (timelock_uc.is_some()) {         timelock_uc.extract().unlock(ctx);     };     // If the output has an expiration unlock condition, then we need to check who can unlock the output.     if (expiration_uc.is_some()) {         expiration_uc.extract().unlock(ctx);     };     // If the output has a storage deposit return unlock condition, then we need to return the deposit.     if (storage_deposit_return_uc.is_some()) {         storage_deposit_return_uc.extract().unlock(&mut balance, ctx);     };     // Destroy the output.     option::destroy_none(timelock_uc);     option::destroy_none(expiration_uc);     option::destroy_none(storage_deposit_return_uc);     object::delete(id);     return (balance, native_tokens, nft) }

prv load_nft

Loads the related Nft object.

fun load_nft<T>(output: &mut stardust::nft_output::NftOutput<T>): stardust::nft::Nft

Implementation

fun load_nft<T>(output: &mut NftOutput<T>): Nft {     dynamic_object_field::remove(&mut output.id, NFT_NAME) }

Constants

const NFT_NAME

The NFT dynamic field name.

const NFT_NAME: vector<u8> = vector[110, 102, 116];