terra_sdk.core.coin
Coin Objects
_2@attr.s(frozen=True)_2class 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_2def parse(arg: Union[Coin, str, dict]) -> Coin
Converts the argument into a coin.
Arguments:
argUnion[Coin, str, dict] - value to be converted to coin
is_int_coin
_1def is_int_coin() -> bool
Checks whether the coin's amount is of type int.
is_dec_coin
_1def is_dec_coin() -> bool
Checks whether the coin's amount is of type :class:Dec.
to_int_coin
_1def to_int_coin() -> Coin
Creates a new :class:Coin with an int amount.
to_int_ceil_coin
_1def to_int_ceil_coin() -> Coin
Turns the :class:coin into an int coin with ceiling the amount.
to_dec_coin
_1def to_dec_coin() -> Coin
Creates a new :class:Coin with a :class:Dec amount.
from_str
_2@classmethod_2def 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:
stringstr - string to convert
Raises:
ValueError- if string is in wrong format
Returns:
Coin- converted string
add
_1def 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:
addendUnion[Numeric.Input, Coin] - addend
Raises:
ArithmeticError- if addedend has differentdenom
Returns:
Coin- sum
sub
_1def 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:
subtrahendUnion[Numeric.Input, Coin] - subtrahend
Returns:
Coin- difference
mul
_1def 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:
multiplierNumeric.Input - multiplier
Returns:
Coin- product
div
_1def 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:
divisorNumeric.Input - divisor
Returns:
Coin- quotient
mod
_1def mod(modulo: Numeric.Input) -> Coin
Creates a new :class:Coin with the modulus as amount.
Arguments:
moduloNumeric.Input - modulo
Returns:
Coin- modulo
from_data
_2@classmethod_2def from_data(cls, data: dict) -> Coin
Deserializes a :class:Coin object from its JSON data representation.
Arguments:
datadict - data object
from_amino
_2@classmethod_2def from_amino(cls, data: dict) -> Coin
Deserializes a :class:Coin object from its amino-codec representation.
Arguments:
datadict - data object