-
Notifications
You must be signed in to change notification settings - Fork 84
refactor: Tx fees granting rework #413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Visit the preview URL for this PR (updated for commit 6748ca3): https://fetch-docs-preview--pr413-refactor-tx-fees-5frisnzj.web.app (expires Sat, 24 May 2025 13:36:27 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 Sign: f2de39fd4e81249941960b74fbab0a62d90d69f8 |
cosmpy/aerial/tx.py
Outdated
class TxFee: | ||
"""Cosmos SDK TxFee abstraction.""" | ||
|
||
def __init__( | ||
self, | ||
amount: List["Coin"], # type: ignore # noqa: F821 | ||
gas_limit: int, | ||
granter: Optional[Address] = None, | ||
payer: Optional[Address] = None, | ||
): | ||
"""Init the Transaction fee class. | ||
|
||
:param amount: tx fee amount | ||
:param gas_limit: gas limit | ||
:param granter: transaction fee granter, defaults to None | ||
:param payer: transaction fee payer, defaults to None | ||
:returns initialised TxFee | ||
""" | ||
self.amount = amount | ||
self.gas_limit = gas_limit | ||
self.granter = granter | ||
self.payer = payer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class TxFee: | |
"""Cosmos SDK TxFee abstraction.""" | |
def __init__( | |
self, | |
amount: List["Coin"], # type: ignore # noqa: F821 | |
gas_limit: int, | |
granter: Optional[Address] = None, | |
payer: Optional[Address] = None, | |
): | |
"""Init the Transaction fee class. | |
:param amount: tx fee amount | |
:param gas_limit: gas limit | |
:param granter: transaction fee granter, defaults to None | |
:param payer: transaction fee payer, defaults to None | |
:returns initialised TxFee | |
""" | |
self.amount = amount | |
self.gas_limit = gas_limit | |
self.granter = granter | |
self.payer = payer | |
@dataclass | |
class TxFee: | |
"""Cosmos SDK TxFee abstraction.""" | |
amount: Option[List["Coin"]] # type: ignore # noqa: F821 | |
gas_limit: Option[int] | |
granter: Optional[Address] = None | |
payer: Optional[Address] = None |
cosmpy/aerial/tx.py
Outdated
def from_fixed_amount( | ||
cls, | ||
amount: str, | ||
gas_limit: int = 0, | ||
granter: Optional[Address] = None, | ||
payer: Optional[Address] = None, | ||
) -> "TxFee": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def from_fixed_amount( | |
cls, | |
amount: str, | |
gas_limit: int = 0, | |
granter: Optional[Address] = None, | |
payer: Optional[Address] = None, | |
) -> "TxFee": | |
def from_gas_price( | |
cls, | |
gas_price: float, | |
gas_limit: int, | |
granter: Optional[Address] = None, | |
payer: Optional[Address] = None, | |
) -> "TxFee": |
cosmpy/aerial/tx.py
Outdated
@classmethod | ||
def from_simulation( | ||
cls, | ||
client: "LedgerClient", # type: ignore # noqa: F821 | ||
tx: "Transaction", # type: ignore # noqa: F821 | ||
sender: "Wallet", # type: ignore # noqa: F821 | ||
amount: Optional[str] = None, | ||
granter: Optional[Address] = None, | ||
payer: Optional[Address] = None, | ||
account: Optional["Account"] = None, # type: ignore # noqa: F821 | ||
memo: Optional[str] = None, | ||
) -> Tuple["TxFee", Optional["Account"]]: # type: ignore # noqa: F821 | ||
"""Estimate transaction fees based on either a provided amount, gas limit, or simulation. | ||
|
||
:param client: Ledger client | ||
:param tx: The transaction | ||
:param sender: The transaction sender | ||
:param amount: Transaction fee amount, defaults to None | ||
:param granter: Transaction fee granter, defaults to None | ||
:param payer: Transaction fee payer, defaults to None | ||
:param account: The account | ||
:param memo: Transaction memo, defaults to None | ||
:return: Tuple[TxFee, Optional[Account]] | ||
""" | ||
# Ensure we have the account info | ||
account = account or client.query_account(sender.address()) | ||
|
||
# Simulate transaction to get gas and amount | ||
gas_limit, estimated_amount = simulate_tx(client, tx, sender, account, memo) | ||
|
||
# Use estimated amount if not provided | ||
amount = amount or estimated_amount | ||
|
||
fee = cls( | ||
amount=parse_coins(amount), | ||
gas_limit=gas_limit, | ||
granter=granter, | ||
payer=payer, | ||
) | ||
|
||
return fee, account |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would relocate this method to the Tx
class - it feels like it would fit there better than here.
cosmpy/aerial/tx.py
Outdated
payer: Optional[Address] = None, | ||
account: Optional["Account"] = None, # type: ignore # noqa: F821 | ||
memo: Optional[str] = None, | ||
) -> Tuple["TxFee", Optional["Account"]]: # type: ignore # noqa: F821 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would add the Tx
instance to the returned tuple = the return value would contain modified & sealed Tx
instance with filled in Fee
instance from simulation.
) -> Tuple["TxFee", Optional["Account"]]: # type: ignore # noqa: F821 | |
) -> Tuple[Tx, "TxFee", Optional["Account"]]: # type: ignore # noqa: F821 |
cosmpy/aerial/tx.py
Outdated
@@ -172,19 +233,61 @@ def add_message(self, msg: Any) -> "Transaction": | |||
self._msgs.append(msg) | |||
return self | |||
|
|||
def online_seal( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method can be extended to be able to use multiple senders - it would require multiple senders and accounts. If we do that we should consider where to store queried accounts to avoid unnecessary querying.
Closed in favour of #415 |
Proposed Changes
[describe the changes here...]
Linked Issues
[if applicable, add links to issues resolved by this PR]
Types of changes
What type of change does this pull request make (put an
x
in the boxes that apply)?Checklist
Put an
x
in the boxes that apply:If applicable
Further comments
[if this is a relatively large or complex change, kick off a discussion by explaining why you chose the solution you did, what alternatives you considered, etc...]