Skip to main content

Module 0x107a::basic_output

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

Resource 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.

struct BasicOutput<T> has key

Fields
id: object::UID

Hash of the outputId that was migrated.

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.

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

The metadata feature.

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

The tag feature.

sender: option::Option<address>

The sender feature.

Function 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: basic_output::BasicOutput<T>, ctx: &mut tx_context::TxContext): (balance::Balance<T>, 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) }

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

Implementation

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