Skip to content

feat: algokit-utils-py v3 implementation #119

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

Merged
merged 32 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
9389170
refactor: preparing codebase for gradual feature parity sync with uti…
aorumbayev Oct 22, 2024
1c77ad8
feat: TransactionComposer & AppManager implementation; various ongoin…
aorumbayev Nov 4, 2024
6cd11be
feat: AlgorandClientTransaction(Creator|Sender) and AssetManager abst…
aorumbayev Nov 6, 2024
62c121a
feat: AppClient, AppFactory, AppDeployer interface and various refine…
aorumbayev Dec 11, 2024
18744fe
chore: expose new interfaces
aorumbayev Dec 11, 2024
6bf71aa
refactor: further aligning composer class; initial batch of resource …
aorumbayev Dec 13, 2024
ec8cb13
chore: remaining resource packing related tests (#126)
aorumbayev Dec 16, 2024
92774f7
refactor: refining codebase; cleanup for initial beta release (#127)
aorumbayev Dec 20, 2024
8628075
feat: add offline_key_reg transaction to sender/creator/composer abst…
aorumbayev Dec 23, 2024
b3dec7f
docs: initial documentation for beta release (#128)
aorumbayev Dec 23, 2024
8024d37
refactor: refinements to support client generator v3 (#130)
aorumbayev Jan 22, 2025
a0efebc
refactor: remove AlgorandClientProtocol
aorumbayev Jan 22, 2025
06a59a9
refactor: removing AlgorandClientProtocol; extra type narrowing tweaks
aorumbayev Jan 22, 2025
dd75634
refactor: addressing pr comments
aorumbayev Jan 23, 2025
e9a9d63
docs: refining docstrings; enforcing sphinx styled format
aorumbayev Jan 23, 2025
64de8e4
Merge remote-tracking branch 'origin/main' into prerelease/ts-feature…
aorumbayev Jan 23, 2025
5abbed3
feat: refactoring the resource population to support cover appcall it…
aorumbayev Jan 24, 2025
42007ee
fix: further fixes revealed after refreshing generator against app ca…
aorumbayev Jan 25, 2025
8da2dfe
fix: add missing extra_program_pages calculation in method txn creation
aorumbayev Jan 25, 2025
1df5083
refactor: reusing OnSchemaBreak, OnUpdate, OperationPerformed
aorumbayev Jan 26, 2025
d01d90e
refactor: refine dataclasses; moving send and compilation params into…
aorumbayev Jan 26, 2025
b6e21fe
fix: remove skip signature for debug related simulate as it always tr…
aorumbayev Jan 26, 2025
f1036de
refactor: addressing pr comments
aorumbayev Jan 27, 2025
fc17da9
refactor: addressing pr comments
aorumbayev Jan 27, 2025
690b567
refactor: addressing pr comments
aorumbayev Jan 27, 2025
0755c87
docs: further refinements in capabilities .md files
aorumbayev Jan 28, 2025
1bf49e3
refactor: addressing pr comments
aorumbayev Jan 28, 2025
719e140
docs: typo in logic error description
aorumbayev Jan 28, 2025
cf14b5c
fix: improving regex usage in logic error message parser; bumping pyt…
aorumbayev Jan 28, 2025
f8cb58f
docs: refreshing documentation;
aorumbayev Jan 29, 2025
c14941b
docs: add migration note to readme
aorumbayev Jan 29, 2025
9af713d
docs: addressing pr comments
aorumbayev Jan 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: addressing pr comments
  • Loading branch information
aorumbayev committed Jan 27, 2025
commit f1036de744fe1a08b06b30e4d180c078da54040e
2 changes: 2 additions & 0 deletions src/algokit_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

# Core types and utilities that are commonly used
from algokit_utils.models.account import Account
from algokit_utils.models.amount import AlgoAmount
from algokit_utils.applications.app_deployer import OnSchemaBreak, OnUpdate, OperationPerformed
from algokit_utils.applications.app_manager import DELETABLE_TEMPLATE_NAME, UPDATABLE_TEMPLATE_NAME
from algokit_utils.errors.logic_error import LogicError
Expand Down Expand Up @@ -132,6 +133,7 @@
__all__ = [
# Core types and utilities
"Account",
"AlgoAmount",
"LogicError",
"AlgorandClient",
"DELETABLE_TEMPLATE_NAME",
Expand Down
26 changes: 13 additions & 13 deletions src/algokit_utils/applications/app_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
CompiledTeal,
)
from algokit_utils.models.state import BoxName, BoxValue
from algokit_utils.models.transaction import AppCallSendParams, SendParams
from algokit_utils.models.transaction import SendParams
from algokit_utils.transactions.transaction_composer import (
AppCallMethodCallParams,
AppCallParams,
Expand Down Expand Up @@ -1023,7 +1023,7 @@ def __init__(self, client: AppClient) -> None:
def update(
self,
params: AppClientBareCallParams | None = None,
send_params: AppCallSendParams | None = None,
send_params: SendParams | None = None,
compilation_params: AppClientCompilationParams | None = None,
) -> SendAppTransactionResult[ABIReturn]:
"""Send an application update transaction.
Expand Down Expand Up @@ -1052,7 +1052,7 @@ def update(
)

def opt_in(
self, params: AppClientBareCallParams | None = None, send_params: AppCallSendParams | None = None
self, params: AppClientBareCallParams | None = None, send_params: SendParams | None = None
) -> SendAppTransactionResult[ABIReturn]:
"""Send an application opt-in transaction.

Expand All @@ -1069,7 +1069,7 @@ def opt_in(
)

def delete(
self, params: AppClientBareCallParams | None = None, send_params: AppCallSendParams | None = None
self, params: AppClientBareCallParams | None = None, send_params: SendParams | None = None
) -> SendAppTransactionResult[ABIReturn]:
"""Send an application delete transaction.

Expand All @@ -1086,7 +1086,7 @@ def delete(
)

def clear_state(
self, params: AppClientBareCallParams | None = None, send_params: AppCallSendParams | None = None
self, params: AppClientBareCallParams | None = None, send_params: SendParams | None = None
) -> SendAppTransactionResult[ABIReturn]:
"""Send an application clear state transaction.

Expand All @@ -1103,7 +1103,7 @@ def clear_state(
)

def close_out(
self, params: AppClientBareCallParams | None = None, send_params: AppCallSendParams | None = None
self, params: AppClientBareCallParams | None = None, send_params: SendParams | None = None
) -> SendAppTransactionResult[ABIReturn]:
"""Send an application close out transaction.

Expand All @@ -1123,7 +1123,7 @@ def call(
self,
params: AppClientBareCallParams | None = None,
on_complete: OnComplete | None = None,
send_params: AppCallSendParams | None = None,
send_params: SendParams | None = None,
) -> SendAppTransactionResult[ABIReturn]:
"""Send an application call transaction.

Expand Down Expand Up @@ -1173,7 +1173,7 @@ def fund_app_account(
)

def opt_in(
self, params: AppClientMethodCallParams, send_params: AppCallSendParams | None = None
self, params: AppClientMethodCallParams, send_params: SendParams | None = None
) -> SendAppTransactionResult[Arc56ReturnValueType]:
"""Send an application opt-in transaction.

Expand All @@ -1191,7 +1191,7 @@ def opt_in(
)

def delete(
self, params: AppClientMethodCallParams, send_params: AppCallSendParams | None = None
self, params: AppClientMethodCallParams, send_params: SendParams | None = None
) -> SendAppTransactionResult[Arc56ReturnValueType]:
"""Send an application delete transaction.

Expand All @@ -1212,7 +1212,7 @@ def update(
self,
params: AppClientMethodCallParams,
compilation_params: AppClientCompilationParams | None = None,
send_params: AppCallSendParams | None = None,
send_params: SendParams | None = None,
) -> SendAppUpdateTransactionResult[Arc56ReturnValueType]:
"""Send an application update transaction.

Expand All @@ -1235,7 +1235,7 @@ def update(
return result

def close_out(
self, params: AppClientMethodCallParams, send_params: AppCallSendParams | None = None
self, params: AppClientMethodCallParams, send_params: SendParams | None = None
) -> SendAppTransactionResult[Arc56ReturnValueType]:
"""Send an application close out transaction.

Expand All @@ -1253,7 +1253,7 @@ def close_out(
)

def call(
self, params: AppClientMethodCallParams, send_params: AppCallSendParams | None = None
self, params: AppClientMethodCallParams, send_params: SendParams | None = None
) -> SendAppTransactionResult[Arc56ReturnValueType]:
"""Send an application call transaction.

Expand All @@ -1272,7 +1272,7 @@ def call(
method_call_to_simulate = self._algorand.new_group().add_app_call_method_call(
self._client.params.call(params)
)
send_params = send_params or AppCallSendParams()
send_params = send_params or SendParams()
simulate_response = self._client._handle_call_errors(
lambda: method_call_to_simulate.simulate(
allow_unnamed_resources=send_params.get("populate_app_call_resources") or True,
Expand Down
6 changes: 3 additions & 3 deletions src/algokit_utils/applications/app_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
AppSourceMaps,
)
from algokit_utils.models.state import TealTemplateParams
from algokit_utils.models.transaction import AppCallSendParams
from algokit_utils.models.transaction import SendParams
from algokit_utils.transactions.transaction_composer import (
AppCreateMethodCallParams,
AppCreateParams,
Expand Down Expand Up @@ -381,7 +381,7 @@ def __init__(self, factory: "AppFactory") -> None:
def create(
self,
params: AppFactoryCreateParams | None = None,
send_params: AppCallSendParams | None = None,
send_params: SendParams | None = None,
compilation_params: AppClientCompilationParams | None = None,
) -> tuple[AppClient, SendAppCreateTransactionResult]:
compilation_params = compilation_params or AppClientCompilationParams()
Expand Down Expand Up @@ -441,7 +441,7 @@ def bare(self) -> _AppFactoryBareSendAccessor:
def create(
self,
params: AppFactoryCreateMethodCallParams,
send_params: AppCallSendParams | None = None,
send_params: SendParams | None = None,
compilation_params: AppClientCompilationParams | None = None,
) -> tuple[AppClient, AppFactoryCreateMethodCallResult[Arc56ReturnValueType]]:
compilation_params = compilation_params or AppClientCompilationParams()
Expand Down
16 changes: 9 additions & 7 deletions src/algokit_utils/models/amount.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

from decimal import Decimal

import algosdk
from typing_extensions import Self

Expand All @@ -18,15 +20,15 @@ class AlgoAmount:
>>> amount = AlgoAmount({"microAlgos": 1_000_000})
"""

def __init__(self, amount: dict[str, int]):
def __init__(self, amount: dict[str, int | Decimal]):
if "microAlgos" in amount:
self.amount_in_micro_algo = int(amount["microAlgos"])
elif "microAlgo" in amount:
self.amount_in_micro_algo = int(amount["microAlgo"])
elif "algos" in amount:
self.amount_in_micro_algo = algosdk.util.algos_to_microalgos(float(amount["algos"]))
self.amount_in_micro_algo = int(amount["algos"] * algosdk.constants.MICROALGOS_TO_ALGOS_RATIO)
elif "algo" in amount:
self.amount_in_micro_algo = algosdk.util.algos_to_microalgos(float(amount["algo"]))
self.amount_in_micro_algo = int(amount["algo"] * algosdk.constants.MICROALGOS_TO_ALGOS_RATIO)
else:
raise ValueError("Invalid amount provided")

Expand All @@ -47,23 +49,23 @@ def micro_algo(self) -> int:
return self.amount_in_micro_algo

@property
def algos(self) -> int:
def algos(self) -> Decimal:
"""Return the amount as a number in Algo.

:returns: The amount in Algo.
"""
return algosdk.util.microalgos_to_algos(self.amount_in_micro_algo) # type: ignore[no-any-return]

@property
def algo(self) -> int:
def algo(self) -> Decimal:
"""Return the amount as a number in Algo.

:returns: The amount in Algo.
"""
return algosdk.util.microalgos_to_algos(self.amount_in_micro_algo) # type: ignore[no-any-return]

@staticmethod
def from_algos(amount: int) -> AlgoAmount:
def from_algos(amount: int | Decimal) -> AlgoAmount:
"""Create an AlgoAmount object representing the given number of Algo.

:param amount: The amount in Algo.
Expand All @@ -75,7 +77,7 @@ def from_algos(amount: int) -> AlgoAmount:
return AlgoAmount({"algos": amount})

@staticmethod
def from_algo(amount: int) -> AlgoAmount:
def from_algo(amount: int | Decimal) -> AlgoAmount:
"""Create an AlgoAmount object representing the given number of Algo.

:param amount: The amount in Algo.
Expand Down
4 changes: 0 additions & 4 deletions src/algokit_utils/models/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import algosdk

__all__ = [
"AppCallSendParams",
"Arc2TransactionNote",
"BaseArc2Note",
"JsonFormatArc2Note",
Expand Down Expand Up @@ -96,9 +95,6 @@ def _return_if_type(self, txn_type: type[TxnTypeT]) -> TxnTypeT:
class SendParams(TypedDict, total=False):
max_rounds_to_wait: int | None
suppress_log: bool | None


class AppCallSendParams(SendParams, total=False):
populate_app_call_resources: bool | None
cover_app_call_inner_txn_fees: bool | None

Expand Down
12 changes: 6 additions & 6 deletions src/algokit_utils/transactions/transaction_composer.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from algokit_utils.applications.app_spec.arc56 import Method as Arc56Method
from algokit_utils.config import config
from algokit_utils.models.state import BoxIdentifier, BoxReference
from algokit_utils.models.transaction import AppCallSendParams, SendParams, TransactionWrapper
from algokit_utils.models.transaction import SendParams, TransactionWrapper

if TYPE_CHECKING:
from collections.abc import Callable
Expand Down Expand Up @@ -1609,7 +1609,7 @@ def execute(

def send(
self,
params: SendParams | AppCallSendParams | None = None,
params: SendParams | None = None,
) -> SendAtomicTransactionComposerResults:
"""Send the transaction group to the network.

Expand All @@ -1621,13 +1621,13 @@ def send(

if not params:
has_app_call = any(isinstance(txn.txn, ApplicationCallTxn) for txn in group)
params = AppCallSendParams() if has_app_call else SendParams()

cover_app_call_inner_txn_fees: bool | None = params.get("cover_app_call_inner_txn_fees") # type: ignore[assignment]
populate_app_call_resources: bool | None = params.get("populate_app_call_resources") # type: ignore[assignment]
params = SendParams() if has_app_call else SendParams()

cover_app_call_inner_txn_fees = params.get("cover_app_call_inner_txn_fees")
populate_app_call_resources = params.get("populate_app_call_resources")
wait_rounds = params.get("max_rounds_to_wait")
sp = self._get_suggested_params() if not wait_rounds or cover_app_call_inner_txn_fees else None

if wait_rounds is None:
last_round = max(txn.txn.last_valid_round for txn in group)
assert sp is not None
Expand Down
30 changes: 15 additions & 15 deletions src/algokit_utils/transactions/transaction_sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from algokit_utils.applications.app_manager import AppManager
from algokit_utils.assets.asset_manager import AssetManager
from algokit_utils.config import config
from algokit_utils.models.transaction import AppCallSendParams, SendParams, TransactionWrapper
from algokit_utils.models.transaction import SendParams, TransactionWrapper
from algokit_utils.transactions.transaction_composer import (
AppCallMethodCallParams,
AppCallParams,
Expand Down Expand Up @@ -214,9 +214,9 @@ def _send_app_call(
c: Callable[[TransactionComposer], Callable[[TxnParamsT], TransactionComposer]],
pre_log: Callable[[TxnParamsT, Transaction], str] | None = None,
post_log: Callable[[TxnParamsT, SendSingleTransactionResult], str] | None = None,
) -> Callable[[TxnParamsT, AppCallSendParams | None], SendAppTransactionResult[ABIReturn]]:
) -> Callable[[TxnParamsT, SendParams | None], SendAppTransactionResult[ABIReturn]]:
def send_app_call(
params: TxnParamsT, send_params: AppCallSendParams | None = None
params: TxnParamsT, send_params: SendParams | None = None
) -> SendAppTransactionResult[ABIReturn]:
result = self._send(c, pre_log, post_log)(params, send_params)
return SendAppTransactionResult[ABIReturn](
Expand All @@ -231,9 +231,9 @@ def _send_app_update_call(
c: Callable[[TransactionComposer], Callable[[TxnParamsT], TransactionComposer]],
pre_log: Callable[[TxnParamsT, Transaction], str] | None = None,
post_log: Callable[[TxnParamsT, SendSingleTransactionResult], str] | None = None,
) -> Callable[[TxnParamsT, AppCallSendParams | None], SendAppUpdateTransactionResult[ABIReturn]]:
) -> Callable[[TxnParamsT, SendParams | None], SendAppUpdateTransactionResult[ABIReturn]]:
def send_app_update_call(
params: TxnParamsT, send_params: AppCallSendParams | None = None
params: TxnParamsT, send_params: SendParams | None = None
) -> SendAppUpdateTransactionResult[ABIReturn]:
result = self._send_app_call(c, pre_log, post_log)(params, send_params)

Expand Down Expand Up @@ -266,9 +266,9 @@ def _send_app_create_call(
c: Callable[[TransactionComposer], Callable[[TxnParamsT], TransactionComposer]],
pre_log: Callable[[TxnParamsT, Transaction], str] | None = None,
post_log: Callable[[TxnParamsT, SendSingleTransactionResult], str] | None = None,
) -> Callable[[TxnParamsT, AppCallSendParams | None], SendAppCreateTransactionResult[ABIReturn]]:
) -> Callable[[TxnParamsT, SendParams | None], SendAppCreateTransactionResult[ABIReturn]]:
def send_app_create_call(
params: TxnParamsT, send_params: AppCallSendParams | None = None
params: TxnParamsT, send_params: SendParams | None = None
) -> SendAppCreateTransactionResult[ABIReturn]:
result = self._send_app_update_call(c, pre_log, post_log)(params, send_params)
app_id = int(result.confirmation["application-index"]) # type: ignore[call-overload]
Expand Down Expand Up @@ -454,7 +454,7 @@ def asset_opt_out(
)(params, send_params)

def app_create(
self, params: AppCreateParams, send_params: AppCallSendParams | None = None
self, params: AppCreateParams, send_params: SendParams | None = None
) -> SendAppCreateTransactionResult[ABIReturn]:
"""Create a new application.

Expand All @@ -465,7 +465,7 @@ def app_create(
return self._send_app_create_call(lambda c: c.add_app_create)(params, send_params)

def app_update(
self, params: AppUpdateParams, send_params: AppCallSendParams | None = None
self, params: AppUpdateParams, send_params: SendParams | None = None
) -> SendAppUpdateTransactionResult[ABIReturn]:
"""Update an application.

Expand All @@ -476,7 +476,7 @@ def app_update(
return self._send_app_update_call(lambda c: c.add_app_update)(params, send_params)

def app_delete(
self, params: AppDeleteParams, send_params: AppCallSendParams | None = None
self, params: AppDeleteParams, send_params: SendParams | None = None
) -> SendAppTransactionResult[ABIReturn]:
"""Delete an application.

Expand All @@ -487,7 +487,7 @@ def app_delete(
return self._send_app_call(lambda c: c.add_app_delete)(params, send_params)

def app_call(
self, params: AppCallParams, send_params: AppCallSendParams | None = None
self, params: AppCallParams, send_params: SendParams | None = None
) -> SendAppTransactionResult[ABIReturn]:
"""Call an application.

Expand All @@ -498,7 +498,7 @@ def app_call(
return self._send_app_call(lambda c: c.add_app_call)(params, send_params)

def app_create_method_call(
self, params: AppCreateMethodCallParams, send_params: AppCallSendParams | None = None
self, params: AppCreateMethodCallParams, send_params: SendParams | None = None
) -> SendAppCreateTransactionResult[ABIReturn]:
"""Call an application's create method.

Expand All @@ -509,7 +509,7 @@ def app_create_method_call(
return self._send_app_create_call(lambda c: c.add_app_create_method_call)(params, send_params)

def app_update_method_call(
self, params: AppUpdateMethodCallParams, send_params: AppCallSendParams | None = None
self, params: AppUpdateMethodCallParams, send_params: SendParams | None = None
) -> SendAppUpdateTransactionResult[ABIReturn]:
"""Call an application's update method.

Expand All @@ -520,7 +520,7 @@ def app_update_method_call(
return self._send_app_update_call(lambda c: c.add_app_update_method_call)(params, send_params)

def app_delete_method_call(
self, params: AppDeleteMethodCallParams, send_params: AppCallSendParams | None = None
self, params: AppDeleteMethodCallParams, send_params: SendParams | None = None
) -> SendAppTransactionResult[ABIReturn]:
"""Call an application's delete method.

Expand All @@ -531,7 +531,7 @@ def app_delete_method_call(
return self._send_app_call(lambda c: c.add_app_delete_method_call)(params, send_params)

def app_call_method_call(
self, params: AppCallMethodCallParams, send_params: AppCallSendParams | None = None
self, params: AppCallMethodCallParams, send_params: SendParams | None = None
) -> SendAppTransactionResult[ABIReturn]:
"""Call an application's call method.

Expand Down
Loading
Loading