Description

Representation of an Asset on the network


// represents an asset, either the native asset (`XLM`)
// or an asset code / issuer account ID pair.
pub enum Asset {
	Native,
	Credit(CreditAsset),
}

pub enum CreditAssetType {
    CreditAlphaNum4(String),
    CreditAlphaNum12(String),
}

pub enum CreditAsset {
    AlphaNum4 { code: String, issuer: PublicKey },
    AlphaNum12 { code: String, issuer: PublicKey },
}

Interface Code

pub trait AssetTrait {
		// Create the native asset:
    fn new_native() -> Self;
    // Create the asset with `code` issued by `issuer`.
		fn new_credit<S>(code: S, issuer: PublicKey) -> Result<Self, Box<dyn Error>>
    where
        S: Into<String>;
    //  Returns true if the asset is a Native. Returns false otherwise.
		fn is_native(&self) -> bool;
		// If the asset is a Credit, returns its value
    fn as_credit(&self) -> Option<&CreditAsset>;
    fn as_credit_mut(&mut self) -> Option<&mut CreditAsset>;
		// Returns true if the asset is a Native. Returns false otherwise.
    fn is_credit(&self) -> bool;
		// Convert an asset to XDR obj
    fn to_xdr(&self) -> Result<xdr::Asset, Box<dyn Error>>;
    // Creates an asset from the xdr object.
		fn from_xdr(x: &xdr::Asset) -> Result<Self, Box<dyn Error>>;
}

Interface Code Link

https://github.com/rahul-soshte/rs-stellar-base/blob/main/src/asset.rs