#[non_exhaustive]pub enum AssetInfoBase<T: AddressLike> {
Native(String),
Cw20(T),
}
Expand description
Represents the type of an fungible asset.
Each asset info instance can be one of three variants:
- Native SDK coins. To create an asset info instance of this type, provide the denomination.
- CW20 tokens. To create an asset info instance of this type, provide the contract address.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
Implementations§
Source§impl<T: AddressLike> AssetInfoBase<T>
impl<T: AddressLike> AssetInfoBase<T>
Source§impl AssetInfoBase<Addr>
impl AssetInfoBase<Addr>
Source§impl AssetInfoBase<String>
impl AssetInfoBase<String>
Sourcepub fn check(
&self,
api: &dyn Api,
optional_whitelist: Option<&[&str]>,
) -> Result<AssetInfo, AssetError>
pub fn check( &self, api: &dyn Api, optional_whitelist: Option<&[&str]>, ) -> Result<AssetInfo, AssetError>
Validate data contained in an unchecked asset info instance; return a new checked asset info instance:
- For CW20 tokens, assert the contract address is valid;
- For SDK coins, assert that the denom is included in a given whitelist; skip if the whitelist is not provided.
use cosmwasm_std::{Addr, Api, StdResult};
use cw_asset::{AssetInfo, AssetInfoUnchecked};
fn validate_asset_info(api: &dyn Api, info_unchecked: &AssetInfoUnchecked) {
match info_unchecked.check(api, Some(&["uatom", "uluna"])) {
Ok(info) => println!("asset info is valid: {}", info.to_string()),
Err(err) => println!("asset is invalid! reason: {}", err),
}
}
Source§impl AssetInfoBase<Addr>
impl AssetInfoBase<Addr>
Sourcepub fn query_balance<T: Into<String>>(
&self,
querier: &QuerierWrapper<'_>,
address: T,
) -> Result<Uint128, AssetError>
pub fn query_balance<T: Into<String>>( &self, querier: &QuerierWrapper<'_>, address: T, ) -> Result<Uint128, AssetError>
Query an address’ balance of the asset
use cosmwasm_std::{Addr, Deps, Uint128};
use cw_asset::{AssetError, AssetInfo};
fn query_uusd_balance(deps: Deps, account_addr: &Addr) -> Result<Uint128, AssetError> {
let info = AssetInfo::native("uusd");
info.query_balance(&deps.querier, "account_addr")
}
Trait Implementations§
Source§impl<T: Clone + AddressLike> Clone for AssetInfoBase<T>
impl<T: Clone + AddressLike> Clone for AssetInfoBase<T>
Source§fn clone(&self) -> AssetInfoBase<T>
fn clone(&self) -> AssetInfoBase<T>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl<T: Debug + AddressLike> Debug for AssetInfoBase<T>
impl<T: Debug + AddressLike> Debug for AssetInfoBase<T>
Source§impl<'de, T> Deserialize<'de> for AssetInfoBase<T>where
T: Deserialize<'de> + AddressLike,
impl<'de, T> Deserialize<'de> for AssetInfoBase<T>where
T: Deserialize<'de> + AddressLike,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl From<&AssetInfoBase<Addr>> for AssetInfoUnchecked
impl From<&AssetInfoBase<Addr>> for AssetInfoUnchecked
Source§impl From<AssetInfoBase<Addr>> for AssetInfoUnchecked
impl From<AssetInfoBase<Addr>> for AssetInfoUnchecked
Source§impl<T: Hash + AddressLike> Hash for AssetInfoBase<T>
impl<T: Hash + AddressLike> Hash for AssetInfoBase<T>
Source§impl<T: AddressLike + JsonSchema> JsonSchema for AssetInfoBase<T>
impl<T: AddressLike + JsonSchema> JsonSchema for AssetInfoBase<T>
Source§fn schema_name() -> String
fn schema_name() -> String
The name of the generated JSON Schema. Read more
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Returns a string that uniquely identifies the schema produced by this type. Read more
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Generates a JSON Schema for this type. Read more
Source§fn is_referenceable() -> bool
fn is_referenceable() -> bool
Whether JSON Schemas generated for this type should be re-used where possible using the
$ref
keyword. Read moreSource§impl<T: Ord + AddressLike> Ord for AssetInfoBase<T>
impl<T: Ord + AddressLike> Ord for AssetInfoBase<T>
Source§fn cmp(&self, other: &AssetInfoBase<T>) -> Ordering
fn cmp(&self, other: &AssetInfoBase<T>) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl<T: PartialEq + AddressLike> PartialEq for AssetInfoBase<T>
impl<T: PartialEq + AddressLike> PartialEq for AssetInfoBase<T>
Source§impl<T: PartialOrd + AddressLike> PartialOrd for AssetInfoBase<T>
impl<T: PartialOrd + AddressLike> PartialOrd for AssetInfoBase<T>
Source§impl<T> Serialize for AssetInfoBase<T>where
T: Serialize + AddressLike,
impl<T> Serialize for AssetInfoBase<T>where
T: Serialize + AddressLike,
impl<T: Eq + AddressLike> Eq for AssetInfoBase<T>
impl<T: AddressLike> StructuralPartialEq for AssetInfoBase<T>
Auto Trait Implementations§
impl<T> Freeze for AssetInfoBase<T>where
T: Freeze,
impl<T> RefUnwindSafe for AssetInfoBase<T>where
T: RefUnwindSafe,
impl<T> Send for AssetInfoBase<T>where
T: Send,
impl<T> Sync for AssetInfoBase<T>where
T: Sync,
impl<T> Unpin for AssetInfoBase<T>where
T: Unpin,
impl<T> UnwindSafe for AssetInfoBase<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more