Module 0xa5::token_id
use 0x1::ascii;
use 0x1::option;
use 0x1::string;
use 0x1::type_name;
use 0x1::vector;
use 0x2::address;
use 0x2::bcs;
use 0x2::coin;
use 0x2::hash;
use 0xa5::coin_info;
use 0xa5::coin_management;
Struct TokenId
struct TokenId has copy, drop, store
Fields
-
id: address
-
Struct UnregisteredTokenId
struct UnregisteredTokenId has copy, drop, store
Fields
-
id: address
-
Constants
const PREFIX_SUI_TOKEN_ID: u256 = 51987410952749076494360794653925130127106954452592680304183314258196508032931;
Function from_address
public fun from_address(id: address): token_id::TokenId
Implementation
public fun from_address(id: address): TokenId {
TokenId { id }
}
Function from_u256
public fun from_u256(id: u256): token_id::TokenId
Implementation
public fun from_u256(id: u256): TokenId {
TokenId { id: address::from_u256(id) }
}
Function to_u256
public fun to_u256(token_id: &token_id::TokenId): u256
Implementation
public fun to_u256(token_id: &TokenId): u256 {
address::to_u256(token_id.id)
}
Function from_info
public fun from_info<T>(name: &string::String, symbol: &ascii::String, decimals: &u8, has_metadata: &bool, has_treasury: &bool): token_id::TokenId
Implementation
public fun from_info<T>(
name: &String,
symbol: &ascii::String,
decimals: &u8,
has_metadata: &bool,
has_treasury: &bool,
): TokenId {
let mut vec = address::from_u256(PREFIX_SUI_TOKEN_ID).to_bytes();
vec.append(bcs::to_bytes(&type_name::get<T>()));
vec.append(bcs::to_bytes(name));
vec.append(bcs::to_bytes(symbol));
vec.append(bcs::to_bytes(decimals));
vec.append(bcs::to_bytes(has_metadata));
vec.append(bcs::to_bytes(has_treasury));
TokenId { id: address::from_bytes(keccak256(&vec)) }
}
Function from_coin_data
public(friend) fun from_coin_data<T>(coin_info: &coin_info::CoinInfo<T>, coin_management: &coin_management::CoinManagement<T>): token_id::TokenId
Implementation
public(package) fun from_coin_data<T>(
coin_info: &CoinInfo<T>,
coin_management: &CoinManagement<T>,
): TokenId {
from_info<T>(
&coin_info.name(),
&coin_info.symbol(),
&coin_info.decimals(),
&option::is_some(coin_info.metadata()),
&coin_management.has_capability(),
)
}
Function unregistered_token_id
public fun unregistered_token_id(symbol: &ascii::String, decimals: u8): token_id::UnregisteredTokenId
Implementation
public fun unregistered_token_id(
symbol: &ascii::String,
decimals: u8,
): UnregisteredTokenId {
let mut v = vector[decimals];
v.append(*ascii::as_bytes(symbol));
let id = address::from_bytes(keccak256(&v));
UnregisteredTokenId { id }
}