Type Alias cw_asset::AssetUnchecked

source ·
pub type AssetUnchecked = AssetBase<String>;

Aliased Type§

struct AssetUnchecked {
    pub info: AssetInfoBase<String>,
    pub amount: Uint128,
}

Fields§

§info: AssetInfoBase<String>

Specifies the asset’s type (CW20 or native)

§amount: Uint128

Specifies the asset’s amount

Implementations§

source§

impl AssetUnchecked

source

pub fn from_sdk_string(s: &str) -> Result<Self, AssetError>

Parse a string of the format {amount}{denom} into an AssetUnchecked object. This is the format that Cosmos SDK uses to stringify native coins. For example:

  • 12345uatom
  • 69420ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2
  • 88888factory/osmo1z926ax906k0ycsuckele6x5hh66e2m4m6ry7dn

Since native coin denoms can only start with a non-numerial character, while its amount can only contain numerical characters, we simply consider the first non-numerical character and all that comes after as the denom, while all that comes before it as the amount. This is the approach used in the Steak Hub contract.

source

pub fn check( &self, api: &dyn Api, optional_whitelist: Option<&[&str]> ) -> Result<Asset, AssetError>

Validate data contained in an unchecked asset instnace, return a new checked asset 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};
use cw_asset::{Asset, AssetUnchecked};

fn validate_asset(api: &dyn Api, asset_unchecked: &AssetUnchecked) {
    match asset_unchecked.check(api, Some(&["uatom", "uluna"])) {
        Ok(asset) => println!("asset is valid: {}", asset.to_string()),
        Err(err) => println!("asset is invalid! reason: {}", err),
    }
}

Trait Implementations§

source§

impl From<AssetBase<Addr>> for AssetUnchecked

source§

fn from(asset: Asset) -> Self

Converts to this type from the input type.
source§

impl FromStr for AssetUnchecked

§

type Err = AssetError

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more