Module stardust::nft_output
- Struct
NftOutput
- Constants
- Function
extract_assets
- Function
load_nft
- Function
attach_nft
- Function
receive
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;
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.
Constants
The NFT dynamic field name.
const NFT_NAME: vector<u8> = vector[110, 102, 116];
Function 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)
}
Function load_nft
Loads the related Nft
object.
fun load_nft<T>(output: &mut stardust::nft_output::NftOutput<T>): stardust::nft::Nft
Implementation
Function 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)
}
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(package) fun receive<T>(parent: &mut iota::object::UID, nft: iota::transfer::Receiving<stardust::nft_output::NftOutput<T>>): stardust::nft_output::NftOutput<T>