Skip to content

Commit

Permalink
chore: algokit utils v3 migration
Browse files Browse the repository at this point in the history
  • Loading branch information
aorumbayev committed Feb 10, 2025
1 parent ba91e82 commit e2f7955
Show file tree
Hide file tree
Showing 14 changed files with 287 additions and 207 deletions.
1 change: 1 addition & 0 deletions .github/actions/setup-poetry/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ runs:
- if: ${{ runner.os == 'macOS' && runner.arch == 'ARM64' }}
run: |
pip install poetry
pipx inject poetry poetry-plugin-export
shell: bash

- if: ${{ runner.os != 'macOS' || runner.arch != 'ARM64' }}
Expand Down
154 changes: 48 additions & 106 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ mslex = "^1.1.0"
keyring = "25.2.1"
pyjwt = "^2.8.0"
cryptography = "^43.0.1" # pyjwt has a weak dependency on cryptography
algokit-utils = "^2.3.0"
algokit-utils = {git = "https://github.com/algorandfoundation/algokit-utils-py.git", rev = "fix/feedback-batch-4"}
multiformats = "0.3.1"
multiformats_config = "0.3.1" # pinned this to be in lockstep with multiformats
jsondiff = "^2.0.0"
Expand All @@ -44,6 +44,7 @@ sphinxnotes-markdown-builder = "^0.5.6"
poethepoet = ">=0.17.1,<0.27.0"
gfm-toc = "^0.0.7"
pytest-xdist = "^3.4.0"
pytest-sugar = "^1.0.0"

[build-system]
requires = ["poetry-core"]
Expand Down
1 change: 0 additions & 1 deletion src/algokit/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@

from algokit.cli import algokit

# Required to support full feature parity when running in binary execution mode
freeze_support()
algokit()
30 changes: 21 additions & 9 deletions src/algokit/cli/tasks/assets.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import logging

import click
from algokit_utils import opt_in, opt_out
from algosdk import error
from algosdk.v2client.algod import AlgodClient

Expand All @@ -14,6 +13,7 @@
validate_account_balance_to_opt_in,
validate_address,
)
from algokit.core.utils import get_algorand_client_for_network

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -55,19 +55,24 @@ def opt_in_command(asset_ids: tuple[int], account: str, network: AlgorandNetwork
opt_in_account = get_account_with_private_key(account)
validate_address(opt_in_account.address)
algod_client = load_algod_client(network)
algorand = get_algorand_client_for_network(network)

validate_account_balance_to_opt_in(algod_client, opt_in_account, len(asset_ids_list))
try:
click.echo("Performing opt-in. This may take a few seconds...")
response = opt_in(algod_client=algod_client, account=opt_in_account, asset_ids=asset_ids_list)
response = algorand.asset.bulk_opt_in(
account=opt_in_account.address,
asset_ids=asset_ids_list,
signer=opt_in_account.signer,
)
click.echo("Successfully performed opt-in.")
if len(response) > 1:
account_url = get_explorer_url(opt_in_account.address, network, ExplorerEntityType.ADDRESS)
click.echo(f"Check latest transactions on your account at: {account_url}")
else:
for asset_id, txn_id in response.items():
explorer_url = get_explorer_url(txn_id, network, ExplorerEntityType.ASSET)
click.echo(f"Check opt-in status for asset {asset_id} at: {explorer_url}")
for asset_opt_int_result in response:
explorer_url = get_explorer_url(asset_opt_int_result.transaction_id, network, ExplorerEntityType.ASSET)
click.echo(f"Check opt-in status for asset {asset_opt_int_result.asset_id} at: {explorer_url}")
except error.AlgodHTTPError as err:
raise click.ClickException(str(err)) from err
except ValueError as err:
Expand Down Expand Up @@ -106,6 +111,7 @@ def opt_out_command(*, asset_ids: tuple[int], account: str, network: AlgorandNet
opt_out_account = get_account_with_private_key(account)
validate_address(opt_out_account.address)
algod_client = load_algod_client(network)
algorand = get_algorand_client_for_network(network)
asset_ids_list = []
try:
asset_ids_list = _get_zero_balanced_assets(
Expand All @@ -119,15 +125,21 @@ def opt_out_command(*, asset_ids: tuple[int], account: str, network: AlgorandNet
raise click.ClickException("No assets to opt-out of.")

click.echo("Performing opt-out. This may take a few seconds...")
response = opt_out(algod_client=algod_client, account=opt_out_account, asset_ids=asset_ids_list)
response = algorand.asset.bulk_opt_out(
account=opt_out_account.address,
asset_ids=asset_ids_list,
signer=opt_out_account.signer,
)
click.echo("Successfully performed opt-out.")
if len(response) > 1:
account_url = get_explorer_url(opt_out_account.address, network, ExplorerEntityType.ADDRESS)
click.echo(f"Check latest transactions on your account at: {account_url}")
else:
asset_id, txn_id = response.popitem()
transaction_url = get_explorer_url(txn_id, network, ExplorerEntityType.TRANSACTION)
click.echo(f"Check opt-in status for asset {asset_id} at: {transaction_url}")
asset_opt_out_result = response[0]
transaction_url = get_explorer_url(
asset_opt_out_result.transaction_id, network, ExplorerEntityType.TRANSACTION
)
click.echo(f"Check opt-in status for asset {asset_opt_out_result.asset_id} at: {transaction_url}")
except error.AlgodHTTPError as err:
raise click.ClickException(str(err)) from err
except ConnectionRefusedError as err:
Expand Down
Loading

0 comments on commit e2f7955

Please sign in to comment.