XTZAmount

public class XTZAmount : TokenAmount

A subclass of TokenAmount to make it more explict when functions require XTZ (such as network fees). It also serves as a means to more quickly create TokenAmount‘s conforming to XTZ.

  • Set the internal balance, using a RPC string (most likely directly from the RPC node response). e.g. “1 XTZ” to the user = “1000000” to the RPC, as there are no such thing as decimal places on the network

    Declaration

    Swift

    public init?(fromRpcAmount rpcAmount: String)

    Parameters

    fromRpcAmount

    A string conforming to the RPC standard for XTZ.

  • Set the internal balance, using a decimal version of an RPC amount. e.g. “1 XTZ” to the user = “1000000” to the RPC, as there are no such thing as decimal places on the network

    Declaration

    Swift

    public convenience init?(fromRpcAmount rpcAmount: Decimal)

    Parameters

    fromRpcAmount

    A decimal conforming to the RPC standard for XTZ. Decimal places will be ignored.

  • Set the internal balance, using a decimal version of a normalised amount. e.g. if the amount is 1.5 and the token is xtz, internally it will be stored as 1500000

    Declaration

    Swift

    public init(fromNormalisedAmount normalisedAmount: Decimal)

    Parameters

    fromNormalisedAmount

    A decimal containing an amount for XTZ. Anything over the given decimal places for the token will be ignored.

  • Set the internal balance, using a normalised amount string. e.g. if the amount is 1.5 and the token is xtz, internally it will be stored as 1500000

    Declaration

    Swift

    public convenience init?(fromNormalisedAmount normalisedAmount: String, decimalPlaces: Int)

    Parameters

    fromNormalisedAmount

    A string containing an amount for XTZ. Anything over the given decimal places for the token will be ignored.

  • Quickly create a XTZAmount with zero balance.

    Declaration

    Swift

    public override class func zero() -> XTZAmount

Codable

  • Token Amounts need an amount and to know the number of decimal places. When downloading from an API, the balance may be presented without the decimal info, where as when we encode, we have the info. This coder attempts to handle both states, first checking if its possible to extract both, if not, defaulting the decimal palces to zero, expecting the calling application to provide this information later on from another proptery or even another API call (such as a metadata query)

    Declaration

    Swift

    required public init(from decoder: Decoder) throws

Arithmetic

  • Overload + operator to allow users to add two Token amounts of the same type, together.

    Declaration

    Swift

    public static func + (lhs: XTZAmount, rhs: XTZAmount) -> XTZAmount
  • Overload += operator to allow users to add two Token amounts of the same type, together in place.

    Declaration

    Swift

    public static func += (lhs: inout XTZAmount, rhs: XTZAmount)
  • Overload - operator to allow users to subtract two Token amounts of the same type.

    Declaration

    Swift

    public static func - (lhs: XTZAmount, rhs: XTZAmount) -> XTZAmount
  • Overload -= operator to allow users to subtract one Token amount of the same type from another, together in place.

    Declaration

    Swift

    public static func -= (lhs: inout XTZAmount, rhs: XTZAmount)
  • Overload multiplcation operator to allow users to multiple a token by a dollar value, and return the localCurrency value of the token.

    Declaration

    Swift

    public static func * (lhs: XTZAmount, rhs: Decimal) -> Decimal
  • Overload multiplcation operator to allow users to multiple a token by an Int. Useful for fee caluclation

    Declaration

    Swift

    public static func * (lhs: XTZAmount, rhs: Int) -> XTZAmount