Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Largely these functions wrap the underlying Algorand SDK, but provide a higher l
> **Note**
> If you prefer TypeScript there's an equivalent [TypeScript utility library](https://github.com/algorandfoundation/algokit-utils-ts).

[Install](https://github.com/algorandfoundation/algokit-utils-py#install) | [Documentation](https://algorandfoundation.github.io/algokit-utils-py/html/index.html)
[Install](https://github.com/algorandfoundation/algokit-utils-py#install) | [Documentation](https://algorandfoundation.github.io/algokit-utils-py)

## Install

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ Note: If you are generating accounts via the various methods on AccountManager

```pycon
>>> account_manager = AccountManager(client_manager)
>>> account_manager.set_signer_from_account(SigningAccount.new_account())
>>> account_manager.set_signer_from_account(SigningAccount(private_key=algosdk.account.generate_account()[0]))
>>> account_manager.set_signer_from_account(LogicSigAccount(AlgosdkLogicSigAccount(program, args)))
>>> account_manager.set_signer_from_account(MultiSigAccount(multisig_params, [account1, account2]))
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

| [`AppFactoryParams`](#algokit_utils.applications.app_factory.AppFactoryParams) | |
|--------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------|
| [`AppFactoryCreateParams`](#algokit_utils.applications.app_factory.AppFactoryCreateParams) | |
| [`AppFactoryCreateMethodCallParams`](#algokit_utils.applications.app_factory.AppFactoryCreateMethodCallParams) | |
| [`AppFactoryCreateParams`](#algokit_utils.applications.app_factory.AppFactoryCreateParams) | Schema for application creation. |
| [`AppFactoryCreateMethodCallParams`](#algokit_utils.applications.app_factory.AppFactoryCreateMethodCallParams) | Schema for application creation. |
| [`AppFactoryCreateMethodCallResult`](#algokit_utils.applications.app_factory.AppFactoryCreateMethodCallResult) | Base class for transaction results. |
| [`SendAppFactoryTransactionResult`](#algokit_utils.applications.app_factory.SendAppFactoryTransactionResult) | |
| [`SendAppUpdateFactoryTransactionResult`](#algokit_utils.applications.app_factory.SendAppUpdateFactoryTransactionResult) | |
| [`SendAppCreateFactoryTransactionResult`](#algokit_utils.applications.app_factory.SendAppCreateFactoryTransactionResult) | |
| [`SendAppFactoryTransactionResult`](#algokit_utils.applications.app_factory.SendAppFactoryTransactionResult) | Result of an application transaction. |
| [`SendAppUpdateFactoryTransactionResult`](#algokit_utils.applications.app_factory.SendAppUpdateFactoryTransactionResult) | Result of updating an application. |
| [`SendAppCreateFactoryTransactionResult`](#algokit_utils.applications.app_factory.SendAppCreateFactoryTransactionResult) | Result of creating a new application. |
| [`AppFactoryDeployResult`](#algokit_utils.applications.app_factory.AppFactoryDeployResult) | Result from deploying an application via AppFactory |
| [`AppFactory`](#algokit_utils.applications.app_factory.AppFactory) | |

Expand All @@ -35,10 +35,22 @@

Bases: `_AppFactoryCreateBaseParams`, [`algokit_utils.applications.app_client.AppClientBareCallParams`](../app_client/index.md#algokit_utils.applications.app_client.AppClientBareCallParams)

Schema for application creation.

* **Variables:**
* **extra_program_pages** – Optional number of extra program pages
* **schema** – Optional application creation schema

### *class* algokit_utils.applications.app_factory.AppFactoryCreateMethodCallParams

Bases: `_AppFactoryCreateBaseParams`, [`algokit_utils.applications.app_client.AppClientMethodCallParams`](../app_client/index.md#algokit_utils.applications.app_client.AppClientMethodCallParams)

Schema for application creation.

* **Variables:**
* **extra_program_pages** – Optional number of extra program pages
* **schema** – Optional application creation schema

### *class* algokit_utils.applications.app_factory.AppFactoryCreateMethodCallResult

Bases: [`algokit_utils.transactions.transaction_sender.SendSingleTransactionResult`](../../transactions/transaction_sender/index.md#algokit_utils.transactions.transaction_sender.SendSingleTransactionResult), `Generic`[`ABIReturnT`]
Expand All @@ -61,14 +73,26 @@ Represents the result of sending a single transaction.

Bases: [`algokit_utils.transactions.transaction_sender.SendAppTransactionResult`](../../transactions/transaction_sender/index.md#algokit_utils.transactions.transaction_sender.SendAppTransactionResult)[[`algokit_utils.applications.abi.Arc56ReturnValueType`](../abi/index.md#algokit_utils.applications.abi.Arc56ReturnValueType)]

Result of an application transaction.

Contains the ABI return value if applicable.

### *class* algokit_utils.applications.app_factory.SendAppUpdateFactoryTransactionResult

Bases: [`algokit_utils.transactions.transaction_sender.SendAppUpdateTransactionResult`](../../transactions/transaction_sender/index.md#algokit_utils.transactions.transaction_sender.SendAppUpdateTransactionResult)[[`algokit_utils.applications.abi.Arc56ReturnValueType`](../abi/index.md#algokit_utils.applications.abi.Arc56ReturnValueType)]

Result of updating an application.

Contains the compiled approval and clear programs.

### *class* algokit_utils.applications.app_factory.SendAppCreateFactoryTransactionResult

Bases: [`algokit_utils.transactions.transaction_sender.SendAppCreateTransactionResult`](../../transactions/transaction_sender/index.md#algokit_utils.transactions.transaction_sender.SendAppCreateTransactionResult)[[`algokit_utils.applications.abi.Arc56ReturnValueType`](../abi/index.md#algokit_utils.applications.abi.Arc56ReturnValueType)]

Result of creating a new application.

Contains the app ID and address of the newly created application.

### *class* algokit_utils.applications.app_factory.AppFactoryDeployResult

Result from deploying an application via AppFactory
Expand Down
6 changes: 3 additions & 3 deletions src/algokit_utils/accounts/account_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def set_signer_from_account(self, account: TransactionSignerAccountProtocol) ->

:example:
>>> account_manager = AccountManager(client_manager)
>>> account_manager.set_signer_from_account(SigningAccount.new_account())
>>> account_manager.set_signer_from_account(SigningAccount(private_key=algosdk.account.generate_account()[0]))
>>> account_manager.set_signer_from_account(LogicSigAccount(AlgosdkLogicSigAccount(program, args)))
>>> account_manager.set_signer_from_account(MultiSigAccount(multisig_params, [account1, account2]))
"""
Expand Down Expand Up @@ -449,8 +449,8 @@ def random(self) -> SigningAccount:
:example:
>>> account = account_manager.random()
"""
account = SigningAccount.new_account()
return self._register_account(account.private_key)
private_key, _ = algosdk.account.generate_account()
return self._register_account(private_key)

def localnet_dispenser(self) -> SigningAccount:
"""
Expand Down
2 changes: 1 addition & 1 deletion src/algokit_utils/application_specification.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import warnings

from deprecated import deprecated
from typing_extensions import deprecated

warnings.warn(
"""The legacy v2 application_specification module is deprecated and will be removed in a future version.
Expand Down
8 changes: 3 additions & 5 deletions src/algokit_utils/applications/app_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import json
import os
from collections.abc import Sequence
from dataclasses import dataclass, fields
from dataclasses import asdict, dataclass, fields
from typing import TYPE_CHECKING, Any, Generic, Literal, TypedDict, TypeVar

import algosdk
Expand Down Expand Up @@ -799,14 +799,12 @@ def update(
:param compilation_params: Parameters for the compilation, defaults to None
:return: Parameters for updating the application
"""
compile_params = (
compile_params = asdict(
self._client.compile(
app_spec=self._client.app_spec,
app_manager=self._algorand.app,
compilation_params=compilation_params,
).__dict__
if compilation_params
else {}
)
)

input_params = {
Expand Down
4 changes: 4 additions & 0 deletions src/algokit_utils/models/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from algosdk.atomic_transaction_composer import AccountTransactionSigner, LogicSigTransactionSigner, TransactionSigner
from algosdk.transaction import LogicSigAccount as AlgosdkLogicSigAccount
from algosdk.transaction import Multisig, MultisigTransaction
from typing_extensions import deprecated

__all__ = [
"DISPENSER_ACCOUNT_NAME",
Expand Down Expand Up @@ -66,6 +67,9 @@ def signer(self) -> AccountTransactionSigner:
"""
return AccountTransactionSigner(self.private_key)

@deprecated(
"Use `algorand.account.random()` or `SigningAccount(private_key=algosdk.account.generate_account()[0])` instead"
)
@staticmethod
def new_account() -> "SigningAccount":
"""Create a new random account.
Expand Down
22 changes: 8 additions & 14 deletions src/algokit_utils/transactions/transaction_composer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import base64
import json
import math
import re
from copy import deepcopy
from dataclasses import dataclass
Expand Down Expand Up @@ -796,6 +795,12 @@ def check_transaction(txn: TransactionWithSigner) -> bool:
return next((i for i, txn in enumerate(txns) if check_transaction(txn)), -1)


def _num_extra_program_pages(approval: bytes | None, clear: bytes | None) -> int:
"""Calculate minimum number of extra_pages required for provided approval and clear programs"""
total = len(approval or b"") + len(clear or b"")
return max(0, (total - 1) // algosdk.constants.APP_PAGE_MAX_SIZE)


def populate_app_call_resources(atc: AtomicTransactionComposer, algod: AlgodClient) -> AtomicTransactionComposer:
"""Populate application call resources based on simulation results.

Expand Down Expand Up @@ -1975,12 +1980,7 @@ def _build_method_call( # noqa: C901, PLR0912, PLR0915
if app_id == 0:
extra_pages = getattr(params, "extra_program_pages", None)
if extra_pages is None and approval_program is not None:
approval_len, clear_len = len(approval_program), len(clear_program or b"")
extra_pages = (
int(math.floor((approval_len + clear_len) / algosdk.constants.APP_PAGE_MAX_SIZE))
if approval_len
else 0
)
extra_pages = _num_extra_program_pages(approval_program, clear_program)

txn_params = {
"app_id": app_id,
Expand Down Expand Up @@ -2085,9 +2085,6 @@ def _build_app_call(
elif isinstance(params.clear_state_program, bytes):
clear_program = params.clear_state_program

approval_program_len = len(approval_program) if approval_program else 0
clear_program_len = len(clear_program) if clear_program else 0

sdk_params = {
"sender": params.sender,
"sp": suggested_params,
Expand Down Expand Up @@ -2120,10 +2117,7 @@ def _build_app_call(
num_uints=params.schema.get("local_ints", 0),
num_byte_slices=params.schema.get("local_byte_slices", 0),
),
"extra_pages": params.extra_program_pages
or math.floor((approval_program_len + clear_program_len) / algosdk.constants.APP_PAGE_MAX_SIZE)
if params.extra_program_pages
else 0,
"extra_pages": params.extra_program_pages or _num_extra_program_pages(approval_program, clear_program),
}

return self._common_txn_build_step(lambda x: algosdk.transaction.ApplicationCallTxn(**x), params, txn_params)
Expand Down
4 changes: 2 additions & 2 deletions src/algokit_utils/transactions/transaction_sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,12 @@ def send_app_update_call(
compiled_approval = (
self._app_manager.get_compilation_result(params.approval_program)
if isinstance(params.approval_program, str)
else None
else params.approval_program
)
compiled_clear = (
self._app_manager.get_compilation_result(params.clear_state_program)
if isinstance(params.clear_state_program, str)
else None
else params.clear_state_program
)

return SendAppUpdateTransactionResult[ABIReturn](
Expand Down
Loading