Skip to main content

Module 0x107a::nft_output

use 0x107a::expiration_unlock_condition; use 0x107a::nft; use 0x107a::storage_deposit_return_unlock_condition; use 0x107a::timelock_unlock_condition; use 0x1::option; use 0x2::bag; use 0x2::balance; use 0x2::dynamic_object_field; use 0x2::object; use 0x2::transfer; use 0x2::tx_context;

Resource NftOutput

The Stardust NFT output representation.

struct NftOutput<T> has key

Fields
id: object::UID

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

balance: balance::Balance<T>

The amount of coins held by the output.

native_tokens: 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: option::Option<storage_deposit_return_unlock_condition::StorageDepositReturnUnlockCondition>

The storage deposit return unlock condition.

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

The timelock unlock condition.

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

The expiration unlock condition.

Constants

The NFT dynamic field name.

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

Function extract_assets

The function extracts assets from a legacy NFT output.

public fun extract_assets<T>(output: nft_output::NftOutput<T>, ctx: &mut tx_context::TxContext): (balance::Balance<T>, bag::Bag, 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) }

Function load_nft

Loads the related Nft object.

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

Implementation

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

Function attach_nft

Utility function to attach an Alias to an AliasOutput.

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

Implementation

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

Function 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(friend) fun receive<T>(parent: &mut object::UID, nft: transfer::Receiving<nft_output::NftOutput<T>>): nft_output::NftOutput<T>

Implementation

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