Skip to main content

Module stardust::utilities

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 std::address; use std::ascii; use std::bcs; use std::option; use std::string; use std::type_name; use std::vector;

Constants

Returned when trying to extract a Balance<T> from a Bag and the balance is zero.

const EZeroNativeTokenBalance: u64 = 0;

Function extract_and_send_to

Extract a Balance<T> from a Bag, create a Coin out of it and send it to the address. NOTE: We return the Bag by value so the function can be called repeatedly in a PTB.

public fun extract_and_send_to<T>(bag: iota::bag::Bag, to: address, ctx: &mut iota::tx_context::TxContext): iota::bag::Bag

Implementation

public fun extract_and_send_to<T>(mut bag: Bag, to: address, ctx: &mut TxContext): Bag { let coin = coin::from_balance(extract_<T>(&mut bag), ctx); transfer::public_transfer(coin, to); bag }

Function extract

Extract a Balance<T> from a Bag and return it. Caller can decide what to do with it. NOTE: We return the Bag by value so the function can be called repeatedly in a PTB.

public fun extract<T>(bag: iota::bag::Bag): (iota::bag::Bag, iota::balance::Balance<T>)

Implementation

public fun extract<T>(mut bag: Bag): (Bag, Balance<T>) { let balance = extract_<T>(&mut bag); (bag, balance) }

Function extract_

Get a Balance<T> from a Bag. Aborts if the balance is zero or if there is no balance for the type T.

fun extract_<T>(bag: &mut iota::bag::Bag): iota::balance::Balance<T>

Implementation

fun extract_<T>(bag: &mut Bag): Balance<T> { let key = type_name::get<T>().into_string(); // This call aborts if the key doesn't exist. let balance: Balance<T> = bag.remove(key); assert!(balance.value() != 0, EZeroNativeTokenBalance); balance }