Skip to main content

terra_sdk.core.coin

Coin Objects


_2
@attr.s(frozen=True)
_2
class Coin(JSONSerializable)

Represents a (denom, amount) pairing, analagous to sdk.Coin and sdk.DecCoin in Cosmos SDK. Used for representing Fluid native assets.

denom

Coin's denomination, only uluna.

amount

Coin's amount -- can be a int or :class:Dec

parse


_2
@staticmethod
_2
def parse(arg: Union[Coin, str, dict]) -> Coin

Converts the argument into a coin.

Arguments:

  • arg Union[Coin, str, dict] - value to be converted to coin

is_int_coin


_1
def is_int_coin() -> bool

Checks whether the coin's amount is of type int.

is_dec_coin


_1
def is_dec_coin() -> bool

Checks whether the coin's amount is of type :class:Dec.

to_int_coin


_1
def to_int_coin() -> Coin

Creates a new :class:Coin with an int amount.

to_int_ceil_coin


_1
def to_int_ceil_coin() -> Coin

Turns the :class:coin into an int coin with ceiling the amount.

to_dec_coin


_1
def to_dec_coin() -> Coin

Creates a new :class:Coin with a :class:Dec amount.

from_str


_2
@classmethod
_2
def from_str(cls, string: str) -> Coin

Creates a new :class:Coin from a coin-format string. Must match the format: 283923uluna (int-Coin) or 23920.23020uluna (:class:Dec-Coin).

>>> int_coin = Coin.from_str("230920uluna") >>> int_coin.denom 'uluna' >>> int_coin.amount 230920 >>> dec_coin = Coin.from_str("203922.223uluna") >>> dec_coin.denom 'uluna' >>> dec_coin.amount Dec('203922.223')

Arguments:

  • string str - string to convert

Raises:

  • ValueError - if string is in wrong format

Returns:

  • Coin - converted string

add


_1
def add(addend: Union[Numeric.Input, Coin]) -> Coin

Creates a new :class:Coin with the sum as amount. If the addend is a :class:Coin, its denom must match.

Arguments:

  • addend Union[Numeric.Input, Coin] - addend

Raises:

  • ArithmeticError - if addedend has different denom

Returns:

  • Coin - sum

sub


_1
def sub(subtrahend: Union[Numeric.Input, Coin]) -> Coin

Creates a new :class:Coin with the difference as amount. If the subtrahend is a :class:Coin, its denom must match.

Arguments:

  • subtrahend Union[Numeric.Input, Coin] - subtrahend

Returns:

  • Coin - difference

mul


_1
def mul(multiplier: Numeric.Input) -> Coin

Creates a new :class:Coin with the product as amount. The multiplier argument is first coerced to either an int or :class:Dec.

Arguments:

  • multiplier Numeric.Input - multiplier

Returns:

  • Coin - product

div


_1
def div(divisor: Numeric.Input) -> Coin

Creates a new :class:Coin with the quotient as amount. The divisor argument is first coerced to either an int or :class:Dec.

Arguments:

  • divisor Numeric.Input - divisor

Returns:

  • Coin - quotient

mod


_1
def mod(modulo: Numeric.Input) -> Coin

Creates a new :class:Coin with the modulus as amount.

Arguments:

  • modulo Numeric.Input - modulo

Returns:

  • Coin - modulo

from_data


_2
@classmethod
_2
def from_data(cls, data: dict) -> Coin

Deserializes a :class:Coin object from its JSON data representation.

Arguments:

  • data dict - data object

from_amino


_2
@classmethod
_2
def from_amino(cls, data: dict) -> Coin

Deserializes a :class:Coin object from its amino-codec representation.

Arguments:

  • data dict - data object