Skip to main content

Module stardust::basic_output

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

Module Functions

pub(pkg) receive

Utility function to receive a basic output in other stardust modules. Since BasicOutput only has key, it can not be received via public_receive. The private receiver must be implemented in its defining module (here). Other modules in the Stardust package can call this function to receive a basic output (alias, NFT).

public(package) fun receive<T>(parent: &mut iota::object::UID, output: iota::transfer::Receiving<stardust::basic_output::BasicOutput<T>>): stardust::basic_output::BasicOutput<T>

Implementation

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

Structs

struct BasicOutput

A basic output that has unlock conditions/features.

  • basic outputs with expiration unlock condition must be a shared object, since that's the only way to handle the two possible addresses that can unlock the output.
  • notice that there is no store ability and there is no custom transfer function:
  • you can call extract_assets,
  • or you can call receive in other models to receive a BasicOutput.

public struct BasicOutput<phantom T> has key

Fields
id: iota::object::UID

Hash of the outputId that was migrated.

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.

metadata: std::option::Option<vector<u8>>

The metadata feature.

tag: std::option::Option<vector<u8>>

The tag feature.

sender: std::option::Option<address>

The sender feature.

pub extract_assets

Extract the assets stored inside the output, respecting the unlock conditions.

  • The object will be deleted.
  • The StorageDepositReturnUnlockCondition will return the deposit.
  • Remaining assets (coins and native tokens) will be returned.

public fun extract_assets<T>(output: stardust::basic_output::BasicOutput<T>, ctx: &mut iota::tx_context::TxContext): (iota::balance::Balance<T>, iota::bag::Bag)

Implementation

public fun extract_assets<T>(output: BasicOutput<T>, ctx: &mut TxContext): (Balance<T>, Bag) {     // Unpack the output into its basic part.     let BasicOutput {         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,         sender: _,         metadata: _,         tag: _,     } = 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 an 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 unlock conditions.     option::destroy_none(timelock_uc);     option::destroy_none(expiration_uc);     option::destroy_none(storage_deposit_return_uc);     // Delete the output.     object::delete(id);     return (balance, native_tokens) }