Class Asset

java.lang.Object
org.stellar.sdk.Asset
All Implemented Interfaces:
Comparable<Asset>
Direct Known Subclasses:
AssetTypeCreditAlphaNum, AssetTypeNative

public abstract class Asset extends Object implements Comparable<Asset>
Base Asset class.
See Also:
  • Method Details

    • create

      public static Asset create(String canonicalForm)
      Parses an asset string and returns the equivalent Asset instance. The asset string is expected to either be "native" or a string of Alpha4 or Alpha12 asset code as "CODE:ISSUER"
      Parameters:
      canonicalForm - Canonical string representation of an Alpha4 or Alpha12 asset
      Returns:
      Asset or throws IllegalArgumentException if not Alpha4 or Alpha12 asset code
      Throws:
      IllegalArgumentException - if the asset string is invalid
    • create

      public static Asset create(String type, String code, String issuer)
      Creates Asset for Alpha4/Alpha12/Native
      Parameters:
      type - the type of asset. 'native' will generate its respective asset sub-class, if null or any other value will attempt to derive the asset sub-class from code and issuer.
      code - the asset code or null
      issuer - the asset issuer or null
      Returns:
      Asset
    • fromXdr

      public static Asset fromXdr(Asset xdr)
      Generates Asset object from a given XDR object
      Parameters:
      xdr - XDR object
    • getType

      public abstract AssetType getType()
      Returns asset type.
    • toXdr

      public abstract Asset toXdr()
      Generates XDR object from a given Asset object
    • equals

      public abstract boolean equals(Object object)
      Overrides:
      equals in class Object
    • compareTo

      public abstract int compareTo(@NonNull @NonNull Asset other)
      Compares two assets.
      1. First compare the type (eg. native before alphanum4 before alphanum12).
      2. If the types are equal, compare the assets codes.
      3. If the asset codes are equal, compare the issuers.
      Specified by:
      compareTo in interface Comparable<Asset>
      Parameters:
      other - the object to be compared.
      Returns:
      a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
    • createNonNativeAsset

      public static Asset createNonNativeAsset(@NonNull @NonNull String code, @NonNull @NonNull String issuer)
      Creates a new non-native asset.
      Parameters:
      code - The asset code.
      issuer - The issuer account ID.
      Returns:
      Asset (alphanum4 or alphanum12)
      Throws:
      IllegalArgumentException - if the asset code is invalid
    • createNativeAsset

      public static Asset createNativeAsset()
      Creates a new native asset.
      Returns:
      Asset (native)
    • getContractId

      public String getContractId(Network network)
      Returns the contract Id for the asset contract.
      Parameters:
      network - The network where the asset is located.
      Returns:
      The contract Id for the asset contract.