Skip to main content

Module 0x107a::alias_output

use 0x107a::alias; use 0x2::bag; use 0x2::balance; use 0x2::dynamic_object_field; use 0x2::object; use 0x2::transfer;

Resource AliasOutput

Owned Object controlled by the Governor Address.

struct AliasOutput<T> has key

Fields
id: object::UID

This is a "random" UID, not the AliasID 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>.

Constants

The Alias dynamic object field name.

const ALIAS_NAME: vector<u8> = [97, 108, 105, 97, 115];

Function extract_assets

The function extracts assets from a legacy AliasOutput.

  • returns the coin Balance,
  • the native tokens Bag,
  • and the Alias object that persists the AliasID=ObjectID from Stardust.

public fun extract_assets<T>(output: alias_output::AliasOutput<T>): (balance::Balance<T>, bag::Bag, alias::Alias)

Implementation

public fun extract_assets<T>(mut output: AliasOutput<T>): (Balance<T>, Bag, Alias) { // Load the related alias object. let alias = load_alias(&mut output);

// Unpack the output into its basic part. let AliasOutput { id, balance, native_tokens } = output;

// Delete the output. object::delete(id);

(balance, native_tokens, alias) }

Function receive

Utility function to receive an AliasOutput object in other Stardust modules. Other modules in the Stardust package can call this function to receive an AliasOutput object (nft).

public(friend) fun receive<T>(parent: &mut object::UID, output: transfer::Receiving<alias_output::AliasOutput<T>>): alias_output::AliasOutput<T>

Implementation

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

Function attach_alias

Utility function to attach an Alias to an AliasOutput.

public fun attach_alias<T>(output: &mut alias_output::AliasOutput<T>, alias: alias::Alias)

Implementation

public fun attach_alias<T>(output: &mut AliasOutput<T>, alias: Alias) { dynamic_object_field::add(&mut output.id, ALIAS_NAME, alias) }

Function load_alias

Loads the Alias object from the dynamic object field.

fun load_alias<T>(output: &mut alias_output::AliasOutput<T>): alias::Alias

Implementation

fun load_alias<T>(output: &mut AliasOutput<T>): Alias { dynamic_object_field::remove(&mut output.id, ALIAS_NAME) }