Coin & Coins
Coin
- class terra_sdk.core.coin.Coin(denom, amount)[source]
Represents a (denom, amount) pairing, analagous to
sdk.Coin
andsdk.DecCoin
in Cosmos SDK. Used for representing Terra native assets.- add(addend)[source]
Creates a new
Coin
with the sum as amount. If theaddend
is aCoin
, itsdenom
must match.
- amount: Union[int, terra_sdk.core.numeric.Dec]
Coin’s amount – can be a
int
orDec
- denom: str
Coin’s denomination, ex
uusd
,uluna
, etc.
- div(divisor)[source]
Creates a new
Coin
with the quotient as amount. Thedivisor
argument is first coerced to either anint
orDec
.- Parameters
divisor (Numeric.Input) – divisor
- Returns
quotient
- Return type
- classmethod from_amino(data)[source]
Deserializes a
Coin
object from its amino-codec representation.- Parameters
data (dict) – data object
- Return type
- classmethod from_data(data)[source]
Deserializes a
Coin
object from its JSON data representation.- Parameters
data (dict) – data object
- Return type
- classmethod from_str(string)[source]
Creates a new
Coin
from a coin-format string. Must match the format:283923uusd
(int
-Coin) or23920.23020uusd
(Dec
-Coin).>>> int_coin = Coin.from_str("230920uusd") >>> int_coin.denom 'uusd' >>> int_coin.amount 230920 >>> dec_coin = Coin.from_str("203922.223uluna") >>> dec_coin.denom 'uluna' >>> dec_coin.amount Dec('203922.223')
- Parameters
string (str) – string to convert
- Raises
ValueError – if string is in wrong format
- Returns
converted string
- Return type
- mod(modulo)[source]
Creates a new
Coin
with the modulus as amount.- Parameters
modulo (Numeric.Input) – modulo
- Returns
modulo
- Return type
- mul(multiplier)[source]
Creates a new
Coin
with the product as amount. Themultiplier
argument is first coerced to either anint
orDec
.- Parameters
multiplier (Numeric.Input) – multiplier
- Returns
product
- Return type
- sub(subtrahend)[source]
Creates a new
Coin
with the difference as amount. If thesubtrahend
is aCoin
, itsdenom
must match.
- to_data()[source]
Converts the object to its JSON-serializable Python data representation.
- Return type
dict
Coins
- class terra_sdk.core.coins.Coins(arg={}, **denoms)[source]
Represents an unordered collection of
Coin
objects – analagous tosdk.Coins
andsdk.DecCoins
in Cosmos SDK. If one of the input coins would beDec
-amount type coin, the resultant Coins is converted toDec
-amount coins.- Parameters
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
Coins
object.alias of
Union
[Iterable
[terra_sdk.core.coin.Coin
],str
,Dict
[str
,Union
[str
,int
,float
,decimal.Decimal
,terra_sdk.core.numeric.Dec
]],Dict
[str
,terra_sdk.core.coin.Coin
]]
- add(addend)[source]
Performs addition, which combines the sets of Coin objects. Coins of similar denoms will be merged into one Coin representing the denom.
- div(divisor)[source]
Performs division, which divides all the Coin objects in the set by a divisor.
- Parameters
divisor (Numeric.Input) – divisor
- Return type
- filter(predicate)[source]
Creates a new
Coins
collection which filters out all Coin objects that do not meet the predicate.
- classmethod from_amino(amino)[source]
Converts list of Coin-amino objects to
Coins
.- Parameters
amino (list) – list of Coin-data objects
- Return type
- classmethod from_data(data)[source]
Converts list of Coin-data objects to
Coins
.- Parameters
data (list) – list of Coin-data objects
- Return type
- classmethod from_proto(proto)[source]
Converts list of Coin-data objects to
Coins
.- Parameters
data (list) – list of Coin-data objects
- Return type
- classmethod from_str(s)[source]
Converts a comma-separated list of Coin-format strings to
Coins
.>>> Coins.from_str('1000uluna,1234ukrw') Coins("1000uluna,1234ukrw")
- Parameters
s (str) – string to convert
- Return type
- get(denom)[source]
Get the Coin with the denom contained in the Coins set.
- Parameters
denom (str) – denom
- Returns
result (can be
None
)- Return type
Optional[Coin]
- map(fn)[source]
Creates an iterable which applies the function to all coins in the set, ordered by denomination.
- Parameters
fn (Callable[[Coin], Any]) – function to apply
- Returns
coin map
- Return type
Iterator[Any]
- Yields
Iterator[Any] – coin map
- mul(multiplier)[source]
Performs multiplicaiton, which multiplies all the Coin objects in the set by a multiplier.
- Parameters
multiplier (Numeric.Input) – multiplier
- Return type
- sub(subtrahend)[source]
Performs subtraction, which combines the sets of Coin objects. Coins of similar denoms will be merged into one Coin representing the denom.
- to_data()[source]
Converts the object to its JSON-serializable Python data representation.
- Return type
List
[dict
]