0xa5::coin_info
Defines the CoinInfo
type which allows to store information about a coin:
either derived from CoinMetadata
or manually provided.
CoinInfo
from_info
from_metadata
name
symbol
decimals
remote_decimals
scaling
metadata
use 0x1::ascii;
use 0x1::option;
use 0x1::string;
use 0x2::coin;
use 0xa5::utils;
CoinInfo
struct CoinInfo<T> has store
name: string::String
symbol: ascii::String
decimals: u8
remote_decimals: u8
metadata: option::Option<coin::CoinMetadata<T>>
from_info
Create a new coin info from the given name, symbol and decimals.
public fun from_info<T>(name: string::String, symbol: ascii::String, decimals: u8, remote_decimals: u8): coin_info::CoinInfo<T>
public fun from_info<T>(
name: String,
symbol: ascii::String,
decimals: u8,
remote_decimals: u8,
): CoinInfo<T> {
CoinInfo {
name,
symbol,
decimals,
remote_decimals,
metadata: option::none(),
}
}
from_metadata
Create a new coin info from the given CoinMetadata
object.
public fun from_metadata<T>(metadata: coin::CoinMetadata<T>, remote_decimals: u8): coin_info::CoinInfo<T>
public fun from_metadata<T>(
metadata: CoinMetadata<T>,
remote_decimals: u8,
): CoinInfo<T> {
CoinInfo {
name: metadata.get_name(),
symbol: metadata.get_symbol(),
decimals: metadata.get_decimals(),
remote_decimals,
metadata: option::some(metadata),
}
}
name
public fun name<T>(self: &coin_info::CoinInfo<T>): string::String
symbol
public fun symbol<T>(self: &coin_info::CoinInfo<T>): ascii::String
public fun symbol<T>(self: &CoinInfo<T>): ascii::String {
self.symbol
}
decimals
public fun decimals<T>(self: &coin_info::CoinInfo<T>): u8
remote_decimals
public fun remote_decimals<T>(self: &coin_info::CoinInfo<T>): u8
public fun remote_decimals<T>(self: &CoinInfo<T>): u8 {
self.remote_decimals
}
scaling
public fun scaling<T>(self: &coin_info::CoinInfo<T>): u256
public fun scaling<T>(self: &CoinInfo<T>): u256 {
utils::pow(10, self.remote_decimals - self.decimals)
}
metadata
public fun metadata<T>(self: &coin_info::CoinInfo<T>): &option::Option<coin::CoinMetadata<T>>