diff --git a/pyproject.toml b/pyproject.toml index 2cd4e5fe..b879d6fc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,7 +18,7 @@ license = "MIT" packages = [{ include = "terra_sdk" }] readme = "README.md" repository = "https://github.com/terra-money/terra.py" -version = "2.0.2" +version = "2.0.3" [tool.poetry.dependencies] aiohttp = "^3.8.1" diff --git a/terra_sdk/client/lcd/api/tx.py b/terra_sdk/client/lcd/api/tx.py index 1ebfc3b3..91bf70aa 100644 --- a/terra_sdk/client/lcd/api/tx.py +++ b/terra_sdk/client/lcd/api/tx.py @@ -1,7 +1,6 @@ import base64 import copy -import urllib.parse -from typing import List, Optional, Union, Dict +from typing import List, Optional from multidict import CIMultiDict import attr @@ -14,11 +13,9 @@ SyncTxBroadcastResult, ) from terra_sdk.core.msg import Msg -from terra_sdk.core.block import Block from terra_sdk.core.tx import AuthInfo, Fee, SignerData, SignMode, Tx, TxBody, TxInfo from terra_sdk.util.hash import hash_amino from terra_sdk.util.json import JSONSerializable -from . import tendermint from ._base import BaseAsyncAPI, sync_bind @@ -47,6 +44,7 @@ class CreateTxOptions: fee (Optional[Fee], optional): transaction fee. If ``None``, will be estimated. See more on `fee estimation`_. memo (str, optional): optional short string to include with transaction. + gas (str, optional): gas limit to set per-transaction; set to "auto" to calculate sufficient gas automatically gas_prices (Coins.Input, optional): gas prices for fee estimation. gas_adjustment (Numeric.Input, optional): gas adjustment for fee estimation. fee_denoms (List[str], optional): list of denoms to use for fee after estimation. @@ -62,7 +60,7 @@ class CreateTxOptions: gas: Optional[str] = attr.ib(default=None) gas_prices: Optional[Coins.Input] = attr.ib(default=None) gas_adjustment: Optional[Numeric.Output] = attr.ib( - default=1, converter=Numeric.parse + default=0, converter=Numeric.parse ) fee_denoms: Optional[List[str]] = attr.ib(default=None) account_number: Optional[int] = attr.ib(default=None) @@ -140,15 +138,8 @@ async def create( chain ID, account number, sequence and fee estimation. Args: - sender (AccAddress): transaction sender's account address - msgs (List[Msg]): list of messages to include - fee (Optional[Fee], optional): fee to use (estimates if empty). - memo (str, optional): memo to use. Defaults to "". - gas_prices (Optional[Coins.Input], optional): gas prices for fee estimation. - gas_adjustment (Optional[Numeric.Input], optional): gas adjustment for fee estimation. - fee_denoms (Optional[List[str]], optional): list of denoms to use for gas fee when estimating. - account_number (Optional[int], optional): account number to use. - sequence (Optional[int], optional): sequence number to use. + signers (List[SingerOptions]): options about signers + options (CreateTxOptions): options about creating a tx Returns: Tx: unsigned tx @@ -214,12 +205,12 @@ async def estimate_fee( tx.append_empty_signatures(signers) gas = options.gas - if gas is None or gas == "auto" or gas == 0: + if gas is None or gas == "auto" or int(gas) == 0: opt = copy.deepcopy(options) opt.gas_adjustment = gas_adjustment gas = str(self.estimate_gas(tx, opt)) - fee_amount = gas_prices_coins.mul(gas).to_int_coins() if gas_prices_coins else Coins.from_str('0uusd') + fee_amount = gas_prices_coins.mul(gas).to_int_ceil_coins() if gas_prices_coins else Coins.from_str('0uusd') return Fee(Numeric.parse(gas), fee_amount, "", "") diff --git a/terra_sdk/client/lcd/lcdclient.py b/terra_sdk/client/lcd/lcdclient.py index 6cac7125..d15c5f3b 100644 --- a/terra_sdk/client/lcd/lcdclient.py +++ b/terra_sdk/client/lcd/lcdclient.py @@ -71,7 +71,7 @@ def __init__( default_price, default_adjustment = get_default(chain_id) self.gas_prices = Coins(gas_prices) if gas_prices else default_price - self.gas_adjustment = gas_adjustment if gas_adjustment else gas_adjustment + self.gas_adjustment = gas_adjustment if gas_adjustment else default_adjustment self.auth = AsyncAuthAPI(self) self.bank = AsyncBankAPI(self) diff --git a/terra_sdk/core/coin.py b/terra_sdk/core/coin.py index 46ab1596..3172f863 100644 --- a/terra_sdk/core/coin.py +++ b/terra_sdk/core/coin.py @@ -1,5 +1,6 @@ from __future__ import annotations +import math import re from dataclasses import dataclass from typing import Union @@ -50,6 +51,10 @@ def to_int_coin(self) -> Coin: """Creates a new :class:`Coin` with an ``int`` amount.""" return Coin(self.denom, int(self.amount)) + def to_int_ceil_coin(self) -> Coin: + """Turns the :class:`coin` into an ``int`` coin with ceiling the amount.""" + return Coin(self.denom, int(math.ceil(self.amount))) + def to_dec_coin(self) -> Coin: """Creates a new :class:`Coin` with a :class:`Dec` amount.""" return Coin(self.denom, Dec(self.amount)) diff --git a/terra_sdk/core/coins.py b/terra_sdk/core/coins.py index b5c2d8d3..3674ce90 100644 --- a/terra_sdk/core/coins.py +++ b/terra_sdk/core/coins.py @@ -149,6 +149,10 @@ def to_int_coins(self) -> Coins: """Creates new set of :class:`Coins` that have ``int`` amounts.""" return Coins(c.to_int_coin() for c in self) + def to_int_ceil_coins(self) -> Coins: + """Creates a new :class:`Coins` object with all ``int`` coins with ceiling the amount""" + return Coins(c.to_int_ceil_coin() for c in self) + def add(self, 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.