Skip to main content

terra_sdk.core.coins

Coins Objects


_1
class Coins(JSONSerializable, List[Coin_pb])

Represents an unordered collection of :class:Coin objects -- analagous to sdk.Coins and sdk.DecCoins in Cosmos SDK. If one of the input coins would be Dec-amount type coin, the resultant Coins is converted to Dec-amount coins.

Arguments:

  • arg Optional[Coins.Input], optional - argument to convert. Defaults to {}.

Raises:

  • TypeError - if arg is not an Iterable

Input

Types which can be converted into a :class:Coins object.

from_str


_2
@classmethod
_2
def from_str(cls, s: str) -> Coins

Converts a comma-separated list of Coin-format strings to :class:Coins.

>>> Coins.from_str('1000uluna,1234ukrw') Coins("1000uluna,1234ukrw")

Arguments:

  • s str - string to convert

__init__


_1
def __init__(arg: Optional[Coins.Input] = {}, **denoms)

Converts the argument into a :class:Coins object.

get


_1
def get(denom: str) -> Optional[Coin]

Get the Coin with the denom contained in the Coins set.

Arguments:

  • denom str - denom

Returns:

  • Optional[Coin] - result (can be None)

from_data


_2
@classmethod
_2
def from_data(cls, data: list) -> Coins

Converts list of Coin-data objects to :class:Coins.

Arguments:

  • data list - list of Coin-data objects

from_amino


_2
@classmethod
_2
def from_amino(cls, amino: list) -> Coins

Converts list of Coin-amino objects to :class:Coins.

Arguments:

  • amino list - list of Coin-data objects

from_proto


_2
@classmethod
_2
def from_proto(cls, proto: List[Coin_pb]) -> Coins

Converts list of Coin-data objects to :class:Coins.

Arguments:

  • data list - list of Coin-data objects

denoms


_1
def denoms() -> List[str]

Get the list of denoms for all Coin objects contained.

to_dec_coins


_1
def to_dec_coins() -> Coins

Creates new set of :class:Coins that have :classDec amounts.

to_int_coins


_1
def to_int_coins() -> Coins

Creates new set of :class:Coins that have int amounts.

to_int_ceil_coins


_1
def to_int_ceil_coins() -> Coins

Creates a new :class:Coins object with all int coins with ceiling the amount

add


_1
def add(addend: Union[Coin, Coins]) -> Coins

Performs addition, which combines the sets of Coin objects. Coins of similar denoms will be merged into one Coin representing the denom.

Arguments:

  • addend Union[Coin, Coins] - addend

sub


_1
def sub(subtrahend: Union[Coin, Coins]) -> Coins

Performs subtraction, which combines the sets of Coin objects. Coins of similar denoms will be merged into one Coin representing the denom.

Arguments:

  • subtrahend Union[Coin, Coins] - subtrahend

mul


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

Performs multiplicaiton, which multiplies all the Coin objects in the set by a multiplier.

Arguments:

  • multiplier Numeric.Input - multiplier

div


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

Performs division, which divides all the Coin objects in the set by a divisor.

Arguments:

  • divisor Numeric.Input - divisor

to_list


_1
def to_list() -> List[Coin]

Converts the set of :class:Coin objects contained into a sorted list by denom.

Returns:

  • List[Coin] - list, sorted by denom

filter


_1
def filter(predicate: Callable[[Coin], bool]) -> Coins

Creates a new :class:Coins collection which filters out all Coin objects that do not meet the predicate.

Arguments:

  • predicate Callable[[Coin], bool] - predicate for filtering

map


_1
def map(fn: Callable[[Coin], Any]) -> Iterator[Any]

Creates an iterable which applies the function to all coins in the set, ordered by denomination.

Arguments:

  • fn Callable[[Coin], Any] - function to apply

Returns:

  • Iterator[Any] - coin map

Yields:

  • Iterator[Any] - coin map