algokit-utils 5.0.0a3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- algokit_abi/__init__.py +9 -0
- algokit_abi/_arc32_to_arc56.py +242 -0
- algokit_abi/_arc56_serde.py +161 -0
- algokit_abi/abi.py +667 -0
- algokit_abi/arc32.py +210 -0
- algokit_abi/arc56.py +821 -0
- algokit_abi/py.typed +0 -0
- algokit_algo25/__init__.py +38 -0
- algokit_algo25/_encoding.py +46 -0
- algokit_algo25/_wordlist.py +2065 -0
- algokit_algo25/exceptions.py +29 -0
- algokit_algo25/mnemonic.py +128 -0
- algokit_algo25/py.typed +0 -0
- algokit_algod_client/__init__.py +10 -0
- algokit_algod_client/client.py +1585 -0
- algokit_algod_client/config.py +36 -0
- algokit_algod_client/exceptions.py +59 -0
- algokit_algod_client/models/__init__.py +229 -0
- algokit_algod_client/models/_account.py +150 -0
- algokit_algod_client/models/_account_application_response.py +25 -0
- algokit_algod_client/models/_account_asset_response.py +25 -0
- algokit_algod_client/models/_account_participation.py +53 -0
- algokit_algod_client/models/_account_state_delta.py +30 -0
- algokit_algod_client/models/_allocations_for_genesis_file.py +23 -0
- algokit_algod_client/models/_allocations_for_genesis_file_state_model.py +42 -0
- algokit_algod_client/models/_application.py +23 -0
- algokit_algod_client/models/_application_initial_states.py +37 -0
- algokit_algod_client/models/_application_kvstorage.py +29 -0
- algokit_algod_client/models/_application_local_state.py +33 -0
- algokit_algod_client/models/_application_params.py +63 -0
- algokit_algod_client/models/_application_state_operation.py +41 -0
- algokit_algod_client/models/_application_state_schema.py +22 -0
- algokit_algod_client/models/_asset.py +23 -0
- algokit_algod_client/models/_asset_holding.py +29 -0
- algokit_algod_client/models/_asset_params.py +102 -0
- algokit_algod_client/models/_avm_key_value.py +28 -0
- algokit_algod_client/models/_avm_value.py +32 -0
- algokit_algod_client/models/_block.py +363 -0
- algokit_algod_client/models/_block_hash_response.py +14 -0
- algokit_algod_client/models/_block_txids_response.py +14 -0
- algokit_algod_client/models/_box.py +36 -0
- algokit_algod_client/models/_box_descriptor.py +24 -0
- algokit_algod_client/models/_boxes_response.py +21 -0
- algokit_algod_client/models/_build_version_contains_the_current_algod_build_version_information.py +34 -0
- algokit_algod_client/models/_compile_response.py +24 -0
- algokit_algod_client/models/_disassemble_response.py +14 -0
- algokit_algod_client/models/_error_response.py +22 -0
- algokit_algod_client/models/_eval_delta.py +32 -0
- algokit_algod_client/models/_eval_delta_key_value.py +28 -0
- algokit_algod_client/models/_genesis_file_in_json.py +53 -0
- algokit_algod_client/models/_get_block_time_stamp_offset_response.py +14 -0
- algokit_algod_client/models/_get_sync_round_response.py +14 -0
- algokit_algod_client/models/_ledger_state_delta.py +389 -0
- algokit_algod_client/models/_light_block_header_proof.py +32 -0
- algokit_algod_client/models/_node_status_response.py +118 -0
- algokit_algod_client/models/_pending_transaction_response.py +91 -0
- algokit_algod_client/models/_pending_transactions_response.py +29 -0
- algokit_algod_client/models/_post_transactions_response.py +14 -0
- algokit_algod_client/models/_scratch_change.py +23 -0
- algokit_algod_client/models/_serde_helpers.py +241 -0
- algokit_algod_client/models/_simulate_initial_states.py +25 -0
- algokit_algod_client/models/_simulate_request.py +54 -0
- algokit_algod_client/models/_simulate_request_transaction_group.py +25 -0
- algokit_algod_client/models/_simulate_response.py +44 -0
- algokit_algod_client/models/_simulate_trace_config.py +30 -0
- algokit_algod_client/models/_simulate_transaction_group_result.py +46 -0
- algokit_algod_client/models/_simulate_transaction_result.py +41 -0
- algokit_algod_client/models/_simulate_unnamed_resources_accessed.py +64 -0
- algokit_algod_client/models/_simulation_eval_overrides.py +40 -0
- algokit_algod_client/models/_simulation_opcode_trace_unit.py +55 -0
- algokit_algod_client/models/_simulation_transaction_exec_trace.py +82 -0
- algokit_algod_client/models/_source_map.py +30 -0
- algokit_algod_client/models/_state_delta.py +6 -0
- algokit_algod_client/models/_state_proof.py +28 -0
- algokit_algod_client/models/_state_proof_message.py +44 -0
- algokit_algod_client/models/_supply_response.py +26 -0
- algokit_algod_client/models/_teal_key_value.py +28 -0
- algokit_algod_client/models/_teal_key_value_store.py +6 -0
- algokit_algod_client/models/_teal_value.py +32 -0
- algokit_algod_client/models/_transaction_group_ledger_state_deltas_for_round_response.py +21 -0
- algokit_algod_client/models/_transaction_parameters_response.py +45 -0
- algokit_algod_client/models/_transaction_proof.py +44 -0
- algokit_algod_client/models/_version_contains_the_current_algod_version.py +38 -0
- algokit_algod_client/models/suggested_params.py +42 -0
- algokit_algod_client/py.typed +1 -0
- algokit_algod_client/types.py +7 -0
- algokit_algosdk/__init__.py +38 -0
- algokit_algosdk/account.py +32 -0
- algokit_algosdk/app_access.py +228 -0
- algokit_algosdk/box_reference.py +100 -0
- algokit_algosdk/constants.py +147 -0
- algokit_algosdk/encoding.py +89 -0
- algokit_algosdk/error.py +180 -0
- algokit_algosdk/logic.py +61 -0
- algokit_algosdk/logicsig.py +218 -0
- algokit_algosdk/mnemonic.py +216 -0
- algokit_algosdk/multisig.py +161 -0
- algokit_algosdk/py.typed +0 -0
- algokit_algosdk/transaction.py +596 -0
- algokit_algosdk/wordlist.py +2054 -0
- algokit_common/__init__.py +50 -0
- algokit_common/address.py +34 -0
- algokit_common/constants.py +47 -0
- algokit_common/hashing.py +25 -0
- algokit_common/py.typed +0 -0
- algokit_common/serde/__init__.py +40 -0
- algokit_common/serde/_core.py +610 -0
- algokit_common/serde/_primitives.py +135 -0
- algokit_common/source_map.py +158 -0
- algokit_indexer_client/__init__.py +10 -0
- algokit_indexer_client/client.py +1456 -0
- algokit_indexer_client/config.py +36 -0
- algokit_indexer_client/exceptions.py +59 -0
- algokit_indexer_client/models/__init__.py +148 -0
- algokit_indexer_client/models/_account.py +161 -0
- algokit_indexer_client/models/_account_participation.py +53 -0
- algokit_indexer_client/models/_account_response.py +19 -0
- algokit_indexer_client/models/_account_state_delta.py +29 -0
- algokit_indexer_client/models/_accounts_response.py +29 -0
- algokit_indexer_client/models/_application.py +35 -0
- algokit_indexer_client/models/_application_local_state.py +45 -0
- algokit_indexer_client/models/_application_local_states_response.py +29 -0
- algokit_indexer_client/models/_application_log_data.py +28 -0
- algokit_indexer_client/models/_application_logs_response.py +33 -0
- algokit_indexer_client/models/_application_params.py +62 -0
- algokit_indexer_client/models/_application_response.py +20 -0
- algokit_indexer_client/models/_application_state_schema.py +22 -0
- algokit_indexer_client/models/_applications_response.py +29 -0
- algokit_indexer_client/models/_asset.py +35 -0
- algokit_indexer_client/models/_asset_balances_response.py +29 -0
- algokit_indexer_client/models/_asset_holding.py +41 -0
- algokit_indexer_client/models/_asset_holdings_response.py +29 -0
- algokit_indexer_client/models/_asset_params.py +102 -0
- algokit_indexer_client/models/_asset_response.py +19 -0
- algokit_indexer_client/models/_assets_response.py +29 -0
- algokit_indexer_client/models/_block.py +150 -0
- algokit_indexer_client/models/_block_headers_response.py +29 -0
- algokit_indexer_client/models/_block_rewards.py +38 -0
- algokit_indexer_client/models/_block_upgrade_state.py +34 -0
- algokit_indexer_client/models/_block_upgrade_vote.py +26 -0
- algokit_indexer_client/models/_box.py +36 -0
- algokit_indexer_client/models/_box_descriptor.py +24 -0
- algokit_indexer_client/models/_box_reference.py +28 -0
- algokit_indexer_client/models/_boxes_response.py +29 -0
- algokit_indexer_client/models/_error_response.py +18 -0
- algokit_indexer_client/models/_eval_delta.py +32 -0
- algokit_indexer_client/models/_eval_delta_key_value.py +28 -0
- algokit_indexer_client/models/_hash_factory.py +14 -0
- algokit_indexer_client/models/_hb_proof_fields.py +57 -0
- algokit_indexer_client/models/_health_check.py +42 -0
- algokit_indexer_client/models/_holding_ref.py +23 -0
- algokit_indexer_client/models/_indexer_state_proof_message.py +40 -0
- algokit_indexer_client/models/_locals_ref.py +23 -0
- algokit_indexer_client/models/_merkle_array_proof.py +29 -0
- algokit_indexer_client/models/_mini_asset_holding.py +38 -0
- algokit_indexer_client/models/_on_completion.py +25 -0
- algokit_indexer_client/models/_participation_updates.py +22 -0
- algokit_indexer_client/models/_resource_ref.py +42 -0
- algokit_indexer_client/models/_serde_helpers.py +241 -0
- algokit_indexer_client/models/_state_delta.py +6 -0
- algokit_indexer_client/models/_state_proof_fields.py +57 -0
- algokit_indexer_client/models/_state_proof_participant.py +20 -0
- algokit_indexer_client/models/_state_proof_reveal.py +25 -0
- algokit_indexer_client/models/_state_proof_sig_slot.py +20 -0
- algokit_indexer_client/models/_state_proof_signature.py +37 -0
- algokit_indexer_client/models/_state_proof_tracking.py +32 -0
- algokit_indexer_client/models/_state_proof_verifier.py +24 -0
- algokit_indexer_client/models/_state_schema.py +25 -0
- algokit_indexer_client/models/_teal_key_value.py +28 -0
- algokit_indexer_client/models/_teal_key_value_store.py +6 -0
- algokit_indexer_client/models/_teal_value.py +32 -0
- algokit_indexer_client/models/_transaction.py +213 -0
- algokit_indexer_client/models/_transaction_application.py +105 -0
- algokit_indexer_client/models/_transaction_asset_config.py +31 -0
- algokit_indexer_client/models/_transaction_asset_freeze.py +29 -0
- algokit_indexer_client/models/_transaction_asset_transfer.py +41 -0
- algokit_indexer_client/models/_transaction_heartbeat.py +52 -0
- algokit_indexer_client/models/_transaction_keyreg.py +59 -0
- algokit_indexer_client/models/_transaction_payment.py +33 -0
- algokit_indexer_client/models/_transaction_response.py +19 -0
- algokit_indexer_client/models/_transaction_signature.py +35 -0
- algokit_indexer_client/models/_transaction_signature_logicsig.py +59 -0
- algokit_indexer_client/models/_transaction_signature_multisig.py +36 -0
- algokit_indexer_client/models/_transaction_signature_multisig_subsignature.py +28 -0
- algokit_indexer_client/models/_transaction_state_proof.py +32 -0
- algokit_indexer_client/models/_transactions_response.py +29 -0
- algokit_indexer_client/py.typed +1 -0
- algokit_indexer_client/types.py +7 -0
- algokit_kmd_client/__init__.py +10 -0
- algokit_kmd_client/client.py +1240 -0
- algokit_kmd_client/config.py +36 -0
- algokit_kmd_client/exceptions.py +59 -0
- algokit_kmd_client/models/__init__.py +112 -0
- algokit_kmd_client/models/_classical_signatures.py +4 -0
- algokit_kmd_client/models/_create_wallet_request.py +30 -0
- algokit_kmd_client/models/_create_wallet_response.py +19 -0
- algokit_kmd_client/models/_delete_key_request.py +27 -0
- algokit_kmd_client/models/_delete_multisig_request.py +27 -0
- algokit_kmd_client/models/_digest_represents_a32_byte_value_holding_the256_bit_hash_digest.py +4 -0
- algokit_kmd_client/models/_ed25519_public_key.py +4 -0
- algokit_kmd_client/models/_export_key_request.py +27 -0
- algokit_kmd_client/models/_export_key_response.py +24 -0
- algokit_kmd_client/models/_export_master_key_request.py +22 -0
- algokit_kmd_client/models/_export_master_key_response.py +18 -0
- algokit_kmd_client/models/_export_multisig_request.py +23 -0
- algokit_kmd_client/models/_export_multisig_response.py +26 -0
- algokit_kmd_client/models/_generate_key_request.py +18 -0
- algokit_kmd_client/models/_generate_key_response.py +19 -0
- algokit_kmd_client/models/_import_key_request.py +28 -0
- algokit_kmd_client/models/_import_key_response.py +19 -0
- algokit_kmd_client/models/_import_multisig_request.py +30 -0
- algokit_kmd_client/models/_import_multisig_response.py +19 -0
- algokit_kmd_client/models/_init_wallet_handle_token_request.py +22 -0
- algokit_kmd_client/models/_init_wallet_handle_token_response.py +18 -0
- algokit_kmd_client/models/_list_keys_request.py +18 -0
- algokit_kmd_client/models/_list_keys_response.py +18 -0
- algokit_kmd_client/models/_list_multisig_request.py +18 -0
- algokit_kmd_client/models/_list_multisig_response.py +18 -0
- algokit_kmd_client/models/_list_wallets_request.py +11 -0
- algokit_kmd_client/models/_list_wallets_response.py +25 -0
- algokit_kmd_client/models/_master_derivation_key.py +4 -0
- algokit_kmd_client/models/_multisig_sig.py +33 -0
- algokit_kmd_client/models/_multisig_subsig.py +23 -0
- algokit_kmd_client/models/_public_key.py +4 -0
- algokit_kmd_client/models/_release_wallet_handle_token_request.py +18 -0
- algokit_kmd_client/models/_rename_wallet_request.py +26 -0
- algokit_kmd_client/models/_rename_wallet_response.py +19 -0
- algokit_kmd_client/models/_renew_wallet_handle_token_request.py +18 -0
- algokit_kmd_client/models/_renew_wallet_handle_token_response.py +19 -0
- algokit_kmd_client/models/_serde_helpers.py +241 -0
- algokit_kmd_client/models/_sign_multisig_response.py +24 -0
- algokit_kmd_client/models/_sign_multisig_txn_request.py +45 -0
- algokit_kmd_client/models/_sign_program_multisig_request.py +50 -0
- algokit_kmd_client/models/_sign_program_multisig_response.py +24 -0
- algokit_kmd_client/models/_sign_program_request.py +37 -0
- algokit_kmd_client/models/_sign_program_response.py +24 -0
- algokit_kmd_client/models/_sign_transaction_response.py +24 -0
- algokit_kmd_client/models/_sign_txn_request.py +36 -0
- algokit_kmd_client/models/_signature.py +4 -0
- algokit_kmd_client/models/_tx_type.py +4 -0
- algokit_kmd_client/models/_versions_request.py +11 -0
- algokit_kmd_client/models/_versions_response.py +19 -0
- algokit_kmd_client/models/_wallet.py +38 -0
- algokit_kmd_client/models/_wallet_handle.py +24 -0
- algokit_kmd_client/models/_wallet_info_request.py +18 -0
- algokit_kmd_client/models/_wallet_info_response.py +19 -0
- algokit_kmd_client/py.typed +1 -0
- algokit_kmd_client/types.py +7 -0
- algokit_transact/__init__.py +190 -0
- algokit_transact/codec/__init__.py +0 -0
- algokit_transact/codec/msgpack.py +11 -0
- algokit_transact/codec/serde.py +7 -0
- algokit_transact/codec/signed.py +57 -0
- algokit_transact/codec/transaction.py +65 -0
- algokit_transact/exceptions.py +17 -0
- algokit_transact/logicsig.py +220 -0
- algokit_transact/models/__init__.py +0 -0
- algokit_transact/models/app_call.py +447 -0
- algokit_transact/models/asset_config.py +19 -0
- algokit_transact/models/asset_freeze.py +11 -0
- algokit_transact/models/asset_transfer.py +13 -0
- algokit_transact/models/common.py +17 -0
- algokit_transact/models/heartbeat.py +21 -0
- algokit_transact/models/key_registration.py +14 -0
- algokit_transact/models/payment.py +14 -0
- algokit_transact/models/signed_transaction.py +21 -0
- algokit_transact/models/state_proof.py +150 -0
- algokit_transact/models/transaction.py +88 -0
- algokit_transact/multisig.py +93 -0
- algokit_transact/ops/__init__.py +0 -0
- algokit_transact/ops/fees.py +47 -0
- algokit_transact/ops/group.py +28 -0
- algokit_transact/ops/ids.py +14 -0
- algokit_transact/ops/validate.py +503 -0
- algokit_transact/py.typed +0 -0
- algokit_transact/signer.py +195 -0
- algokit_transact/signing/__init__.py +0 -0
- algokit_transact/signing/logic_signature.py +19 -0
- algokit_transact/signing/multisig.py +84 -0
- algokit_transact/signing/types.py +39 -0
- algokit_transact/signing/validation.py +63 -0
- algokit_utils/__init__.py +23 -0
- algokit_utils/_debugging.py +304 -0
- algokit_utils/accounts/__init__.py +2 -0
- algokit_utils/accounts/account_manager.py +1051 -0
- algokit_utils/accounts/kmd_account_manager.py +206 -0
- algokit_utils/algo25.py +46 -0
- algokit_utils/algorand.py +383 -0
- algokit_utils/applications/__init__.py +7 -0
- algokit_utils/applications/abi.py +280 -0
- algokit_utils/applications/app_client.py +2193 -0
- algokit_utils/applications/app_deployer.py +788 -0
- algokit_utils/applications/app_factory.py +1140 -0
- algokit_utils/applications/app_manager.py +575 -0
- algokit_utils/applications/app_spec/__init__.py +6 -0
- algokit_utils/applications/enums.py +40 -0
- algokit_utils/assets/__init__.py +1 -0
- algokit_utils/assets/asset_manager.py +344 -0
- algokit_utils/clients/__init__.py +41 -0
- algokit_utils/clients/client_manager.py +756 -0
- algokit_utils/clients/dispenser_api_client.py +212 -0
- algokit_utils/common.py +40 -0
- algokit_utils/config.py +159 -0
- algokit_utils/errors/__init__.py +1 -0
- algokit_utils/errors/logic_error.py +160 -0
- algokit_utils/models/__init__.py +7 -0
- algokit_utils/models/account.py +12 -0
- algokit_utils/models/amount.py +198 -0
- algokit_utils/models/application.py +90 -0
- algokit_utils/models/network.py +29 -0
- algokit_utils/models/simulate.py +7 -0
- algokit_utils/models/state.py +53 -0
- algokit_utils/models/transaction.py +49 -0
- algokit_utils/protocols/__init__.py +3 -0
- algokit_utils/protocols/account.py +11 -0
- algokit_utils/protocols/signer.py +17 -0
- algokit_utils/protocols/typed_clients.py +110 -0
- algokit_utils/py.typed +0 -0
- algokit_utils/transact.py +195 -0
- algokit_utils/transactions/__init__.py +3 -0
- algokit_utils/transactions/builders/__init__.py +67 -0
- algokit_utils/transactions/builders/app.py +248 -0
- algokit_utils/transactions/builders/asset.py +256 -0
- algokit_utils/transactions/builders/common.py +263 -0
- algokit_utils/transactions/builders/keyreg.py +103 -0
- algokit_utils/transactions/builders/method_call.py +380 -0
- algokit_utils/transactions/builders/payment.py +43 -0
- algokit_utils/transactions/composer_resources.py +409 -0
- algokit_utils/transactions/fee_coverage.py +79 -0
- algokit_utils/transactions/helpers.py +9 -0
- algokit_utils/transactions/transaction_composer.py +1574 -0
- algokit_utils/transactions/transaction_creator.py +699 -0
- algokit_utils/transactions/transaction_sender.py +1240 -0
- algokit_utils/transactions/types.py +262 -0
- algokit_utils-5.0.0a3.dist-info/METADATA +105 -0
- algokit_utils-5.0.0a3.dist-info/RECORD +337 -0
- algokit_utils-5.0.0a3.dist-info/WHEEL +4 -0
algokit_abi/__init__.py
ADDED
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import base64
|
|
4
|
+
import json
|
|
5
|
+
from base64 import b64encode
|
|
6
|
+
from collections.abc import Mapping, Sequence
|
|
7
|
+
from enum import Enum
|
|
8
|
+
from typing import Any, Literal, overload
|
|
9
|
+
|
|
10
|
+
from algokit_abi import abi, arc32, arc56
|
|
11
|
+
from algokit_common import from_wire
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class _ActionType(str, Enum):
|
|
15
|
+
CALL = "CALL"
|
|
16
|
+
CREATE = "CREATE"
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
_ARG_ALIASES: Mapping[str, arc56.ReferenceType | arc56.TransactionType] = {
|
|
20
|
+
**{r.value: r for r in arc56.ReferenceType},
|
|
21
|
+
**{t.value: t for t in arc56.TransactionType},
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
__all__ = ["arc32_to_arc56"]
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def arc32_to_arc56(arc32_application_spec: str | arc32.Arc32Contract) -> arc56.Arc56Contract:
|
|
29
|
+
"""Convert an ARC-32 application specification to ARC-56."""
|
|
30
|
+
|
|
31
|
+
arc32_json = (
|
|
32
|
+
arc32_application_spec.to_json()
|
|
33
|
+
if isinstance(arc32_application_spec, arc32.Arc32Contract)
|
|
34
|
+
else arc32_application_spec
|
|
35
|
+
)
|
|
36
|
+
return _Arc32ToArc56Converter(arc32_json).convert()
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class _Arc32ToArc56Converter:
|
|
40
|
+
def __init__(self, arc32_application_spec: str):
|
|
41
|
+
self.arc32 = json.loads(arc32_application_spec)
|
|
42
|
+
|
|
43
|
+
def convert(self) -> arc56.Arc56Contract:
|
|
44
|
+
source_data = self.arc32.get("source")
|
|
45
|
+
methods, structs = self._convert_methods(self.arc32)
|
|
46
|
+
return arc56.Arc56Contract(
|
|
47
|
+
name=self.arc32["contract"]["name"],
|
|
48
|
+
desc=self.arc32["contract"].get("desc"),
|
|
49
|
+
arcs=[],
|
|
50
|
+
methods=methods,
|
|
51
|
+
structs=structs,
|
|
52
|
+
state=self._convert_state(self.arc32),
|
|
53
|
+
source=arc56.Source(**source_data) if source_data else None,
|
|
54
|
+
bare_actions=arc56.Actions(
|
|
55
|
+
call=self._convert_actions(self.arc32.get("bare_call_config"), _ActionType.CALL),
|
|
56
|
+
create=self._convert_actions(self.arc32.get("bare_call_config"), _ActionType.CREATE),
|
|
57
|
+
),
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
def _convert_storage_keys(self, schema: dict) -> dict[str, arc56.StorageKey]:
|
|
61
|
+
"""Convert ARC32 schema declared fields to ARC56 storage keys."""
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
name: arc56.StorageKey(
|
|
65
|
+
key=b64encode(field["key"].encode()).decode(),
|
|
66
|
+
_key_type=arc56.AVMType.STRING,
|
|
67
|
+
_value_type=arc56.AVMType.UINT64 if field["type"] == "uint64" else arc56.AVMType.BYTES,
|
|
68
|
+
desc=field.get("descr"),
|
|
69
|
+
)
|
|
70
|
+
for name, field in schema.items()
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
def _convert_state(self, arc32: dict) -> arc56.State:
|
|
74
|
+
"""Convert ARC32 state and schema to ARC56 state specification."""
|
|
75
|
+
state_data = arc32.get("state", {})
|
|
76
|
+
return arc56.State(
|
|
77
|
+
schema=arc56.Schema(
|
|
78
|
+
global_state=arc56.Global(
|
|
79
|
+
ints=state_data.get("global", {}).get("num_uints", 0),
|
|
80
|
+
bytes=state_data.get("global", {}).get("num_byte_slices", 0),
|
|
81
|
+
),
|
|
82
|
+
local_state=arc56.Local(
|
|
83
|
+
ints=state_data.get("local", {}).get("num_uints", 0),
|
|
84
|
+
bytes=state_data.get("local", {}).get("num_byte_slices", 0),
|
|
85
|
+
),
|
|
86
|
+
),
|
|
87
|
+
keys=arc56.Keys(
|
|
88
|
+
global_state=self._convert_storage_keys(arc32.get("schema", {}).get("global", {}).get("declared", {})),
|
|
89
|
+
local_state=self._convert_storage_keys(arc32.get("schema", {}).get("local", {}).get("declared", {})),
|
|
90
|
+
box={},
|
|
91
|
+
),
|
|
92
|
+
maps=arc56.Maps(global_state={}, local_state={}, box={}),
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
def _convert_default_value(self, default_arg: dict[str, Any] | None) -> arc56.DefaultValue | None:
|
|
96
|
+
"""Convert ARC32 default argument to ARC56 format."""
|
|
97
|
+
if not default_arg or not default_arg.get("source"):
|
|
98
|
+
return None
|
|
99
|
+
|
|
100
|
+
source_mapping = {
|
|
101
|
+
"constant": "literal",
|
|
102
|
+
"global-state": "global",
|
|
103
|
+
"local-state": "local",
|
|
104
|
+
"abi-method": "method",
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
mapped_source = source_mapping.get(default_arg["source"])
|
|
108
|
+
if not mapped_source:
|
|
109
|
+
return None
|
|
110
|
+
arg_data = default_arg["data"]
|
|
111
|
+
if mapped_source == "method":
|
|
112
|
+
method = from_wire(arc56.Method, arg_data)
|
|
113
|
+
return arc56.DefaultValue(
|
|
114
|
+
source=mapped_source, # type: ignore[arg-type]
|
|
115
|
+
data=method.signature,
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
default_value_type: abi.ABIType | arc56.AVMType | None = None
|
|
119
|
+
if mapped_source == "literal":
|
|
120
|
+
if isinstance(arg_data, int):
|
|
121
|
+
default_value_type = abi.UintType(64)
|
|
122
|
+
arg_data = default_value_type.encode(arg_data)
|
|
123
|
+
elif isinstance(arg_data, str):
|
|
124
|
+
default_value_type = arc56.AVMType.STRING
|
|
125
|
+
else:
|
|
126
|
+
raise ValueError(f"Invalid default argument data type: {type(arg_data)}")
|
|
127
|
+
if isinstance(arg_data, str):
|
|
128
|
+
arg_data = arg_data.encode("utf-8")
|
|
129
|
+
return arc56.DefaultValue(
|
|
130
|
+
source=mapped_source, # type: ignore[arg-type]
|
|
131
|
+
data=base64.b64encode(arg_data).decode("utf-8"),
|
|
132
|
+
type=default_value_type,
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
@overload
|
|
136
|
+
def _convert_actions(self, config: dict | None, action_type: Literal[_ActionType.CALL]) -> list[arc56.CallEnum]: ...
|
|
137
|
+
|
|
138
|
+
@overload
|
|
139
|
+
def _convert_actions(
|
|
140
|
+
self, config: dict | None, action_type: Literal[_ActionType.CREATE]
|
|
141
|
+
) -> list[arc56.CreateEnum]: ...
|
|
142
|
+
|
|
143
|
+
def _convert_actions(
|
|
144
|
+
self, config: dict | None, action_type: _ActionType
|
|
145
|
+
) -> Sequence[arc56.CallEnum | arc56.CreateEnum]:
|
|
146
|
+
"""Extract supported actions from call config."""
|
|
147
|
+
if not config:
|
|
148
|
+
return []
|
|
149
|
+
|
|
150
|
+
actions = list[arc56.CallEnum | arc56.CreateEnum]()
|
|
151
|
+
mappings = {
|
|
152
|
+
"no_op": (arc56.CallEnum.NO_OP, arc56.CreateEnum.NO_OP),
|
|
153
|
+
"opt_in": (arc56.CallEnum.OPT_IN, arc56.CreateEnum.OPT_IN),
|
|
154
|
+
"close_out": (arc56.CallEnum.CLOSE_OUT, None),
|
|
155
|
+
"delete_application": (arc56.CallEnum.DELETE_APPLICATION, arc56.CreateEnum.DELETE_APPLICATION),
|
|
156
|
+
"update_application": (arc56.CallEnum.UPDATE_APPLICATION, None),
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
for action, (call_enum, create_enum) in mappings.items():
|
|
160
|
+
if action in config and config[action] in ["ALL", action_type]:
|
|
161
|
+
if action_type == "CALL" and call_enum:
|
|
162
|
+
actions.append(call_enum)
|
|
163
|
+
elif action_type == "CREATE" and create_enum:
|
|
164
|
+
actions.append(create_enum)
|
|
165
|
+
|
|
166
|
+
return actions
|
|
167
|
+
|
|
168
|
+
def _convert_method_actions(self, hint: dict | None) -> arc56.Actions:
|
|
169
|
+
"""Convert method call config to ARC56 actions."""
|
|
170
|
+
config = hint.get("call_config", {}) if hint else {}
|
|
171
|
+
return arc56.Actions(
|
|
172
|
+
call=self._convert_actions(config, _ActionType.CALL),
|
|
173
|
+
create=self._convert_actions(config, _ActionType.CREATE),
|
|
174
|
+
)
|
|
175
|
+
|
|
176
|
+
def _convert_methods(self, arc32: dict) -> tuple[list[arc56.Method], dict[str, abi.StructType]]:
|
|
177
|
+
"""Convert ARC32 methods to ARC56 format."""
|
|
178
|
+
methods = []
|
|
179
|
+
contract = arc32["contract"]
|
|
180
|
+
hints = arc32.get("hints", {})
|
|
181
|
+
structs = {}
|
|
182
|
+
for method in contract["methods"]:
|
|
183
|
+
args_sig = ",".join(a["type"] for a in method["args"])
|
|
184
|
+
signature = f"{method['name']}({args_sig}){method['returns']['type']}"
|
|
185
|
+
hint = hints.get(signature, {})
|
|
186
|
+
method_structs = hint.get("structs", {})
|
|
187
|
+
method_args = []
|
|
188
|
+
for arg in method["args"]:
|
|
189
|
+
name = arg.get("name")
|
|
190
|
+
struct_name = None
|
|
191
|
+
if struct := method_structs.get(name):
|
|
192
|
+
struct_type = _convert_struct(struct)
|
|
193
|
+
struct_name = struct_type.display_name
|
|
194
|
+
structs[struct_name] = struct_type
|
|
195
|
+
arg_type: abi.ABIType | arc56.ReferenceType | arc56.TransactionType = struct_type
|
|
196
|
+
elif alias := _ARG_ALIASES.get(arg["type"]):
|
|
197
|
+
arg_type = alias
|
|
198
|
+
else:
|
|
199
|
+
arg_type = abi.ABIType.from_string(arg["type"])
|
|
200
|
+
method_args.append(
|
|
201
|
+
arc56.Argument(
|
|
202
|
+
type=arg_type,
|
|
203
|
+
name=name,
|
|
204
|
+
desc=arg.get("desc"),
|
|
205
|
+
default_value=self._convert_default_value(
|
|
206
|
+
hint.get("default_arguments", {}).get(arg.get("name"))
|
|
207
|
+
),
|
|
208
|
+
struct=struct_name,
|
|
209
|
+
)
|
|
210
|
+
)
|
|
211
|
+
returns = method["returns"]
|
|
212
|
+
struct_name = None
|
|
213
|
+
if struct := method_structs.get("output"):
|
|
214
|
+
struct_type = _convert_struct(struct)
|
|
215
|
+
struct_name = struct_type.display_name
|
|
216
|
+
structs[struct_name] = struct_type
|
|
217
|
+
return_type: abi.ABIType | arc56.VoidType = struct_type
|
|
218
|
+
elif returns["type"] == arc56.Void:
|
|
219
|
+
return_type = arc56.Void
|
|
220
|
+
else:
|
|
221
|
+
return_type = abi.ABIType.from_string(returns["type"])
|
|
222
|
+
methods.append(
|
|
223
|
+
arc56.Method(
|
|
224
|
+
name=method["name"],
|
|
225
|
+
desc=method.get("desc"),
|
|
226
|
+
readonly=hint.get("read_only"),
|
|
227
|
+
args=method_args,
|
|
228
|
+
returns=arc56.Returns(
|
|
229
|
+
return_type,
|
|
230
|
+
desc=returns.get("desc"),
|
|
231
|
+
struct=struct_name,
|
|
232
|
+
),
|
|
233
|
+
actions=self._convert_method_actions(hint),
|
|
234
|
+
events=[], # ARC32 doesn't specify events
|
|
235
|
+
)
|
|
236
|
+
)
|
|
237
|
+
return methods, structs
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
def _convert_struct(struct: dict) -> abi.StructType:
|
|
241
|
+
fields = {name: abi.ABIType.from_string(typ) for name, typ in struct["elements"]}
|
|
242
|
+
return abi.StructType(struct_name=struct["name"], fields=fields)
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import base64
|
|
2
|
+
import typing
|
|
3
|
+
from collections.abc import Callable, Mapping, Sequence
|
|
4
|
+
from dataclasses import dataclass, field
|
|
5
|
+
|
|
6
|
+
from algokit_abi import abi
|
|
7
|
+
from algokit_common import from_wire, to_wire, wire
|
|
8
|
+
|
|
9
|
+
_Metadata = Mapping[str, object]
|
|
10
|
+
_T = typing.TypeVar("_T")
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def base64_encoded_bytes(alias: str) -> _Metadata:
|
|
14
|
+
return wire(
|
|
15
|
+
alias,
|
|
16
|
+
encode=lambda v: base64.b64encode(v).decode("ascii"),
|
|
17
|
+
decode=base64.b64decode,
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def sequence(alias: str, typ: Callable[..., object], *, omit_empty_seq: bool = True) -> _Metadata:
|
|
22
|
+
def decode(payload: list) -> object:
|
|
23
|
+
return [typ(v) for v in payload]
|
|
24
|
+
|
|
25
|
+
return wire(alias, decode=decode, omit_empty_seq=omit_empty_seq)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def nested_sequence(alias: str, typ: type[_T]) -> _Metadata:
|
|
29
|
+
def encode(val: list | None) -> object:
|
|
30
|
+
if val is None:
|
|
31
|
+
return None
|
|
32
|
+
return [to_wire(v) for v in val]
|
|
33
|
+
|
|
34
|
+
def decode(payload: list | None) -> object:
|
|
35
|
+
if payload is None:
|
|
36
|
+
return None
|
|
37
|
+
return [from_wire(typ, v) for v in payload]
|
|
38
|
+
|
|
39
|
+
return wire(alias, encode=encode, decode=decode, omit_empty_seq=False, omit_if_none=True)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def mapping(alias: str, typ: type[_T]) -> _Metadata:
|
|
43
|
+
def encode(value: Mapping) -> Mapping:
|
|
44
|
+
return {k: to_wire(v) for k, v in value.items()}
|
|
45
|
+
|
|
46
|
+
def decode(payload: Mapping) -> Mapping:
|
|
47
|
+
return {k: from_wire(typ, v) for k, v in payload.items()}
|
|
48
|
+
|
|
49
|
+
return wire(alias, decode=decode, encode=encode)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def abi_type(alias: str) -> _Metadata:
|
|
53
|
+
def encode(value: object) -> str:
|
|
54
|
+
if isinstance(value, abi.ABIType):
|
|
55
|
+
return value.name
|
|
56
|
+
else:
|
|
57
|
+
return str(value)
|
|
58
|
+
|
|
59
|
+
def decode(value: str) -> object:
|
|
60
|
+
from algokit_abi import arc56
|
|
61
|
+
|
|
62
|
+
try:
|
|
63
|
+
return arc56.ENUM_ALIASES[value]
|
|
64
|
+
except KeyError:
|
|
65
|
+
return abi.ABIType.from_string(value)
|
|
66
|
+
|
|
67
|
+
return wire(alias, encode=encode, decode=decode)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def storage(alias: str) -> _Metadata:
|
|
71
|
+
def encode(value: object) -> str:
|
|
72
|
+
if isinstance(value, abi.ABIType):
|
|
73
|
+
return value.name
|
|
74
|
+
else:
|
|
75
|
+
return str(value)
|
|
76
|
+
|
|
77
|
+
def decode(value: str) -> object:
|
|
78
|
+
from algokit_abi import arc56
|
|
79
|
+
|
|
80
|
+
try:
|
|
81
|
+
return arc56.AVMType(value)
|
|
82
|
+
except ValueError:
|
|
83
|
+
pass
|
|
84
|
+
try:
|
|
85
|
+
return abi.ABIType.from_string(value)
|
|
86
|
+
except ValueError:
|
|
87
|
+
return str(value)
|
|
88
|
+
|
|
89
|
+
return wire(alias, encode=encode, decode=decode)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
class _StructField(typing.TypedDict):
|
|
93
|
+
name: str
|
|
94
|
+
type: "str | list[_StructField]"
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
_StructFieldJson = dict[str, list[_StructField]]
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
@dataclass
|
|
101
|
+
class _StructDecoder:
|
|
102
|
+
_struct_json: _StructFieldJson
|
|
103
|
+
result: dict[str, abi.StructType] = field(default_factory=dict)
|
|
104
|
+
|
|
105
|
+
@classmethod
|
|
106
|
+
def decode(cls, struct_json: _StructFieldJson) -> dict[str, abi.StructType]:
|
|
107
|
+
decoder = cls(struct_json)
|
|
108
|
+
decoder._process()
|
|
109
|
+
return decoder.result
|
|
110
|
+
|
|
111
|
+
def _process(self) -> None:
|
|
112
|
+
# add known struct names
|
|
113
|
+
for struct_name, struct_json in self._struct_json.items():
|
|
114
|
+
self._get_or_add(struct_name, struct_json)
|
|
115
|
+
|
|
116
|
+
def _get_or_add(self, name: str, fields: Sequence[_StructField]) -> abi.StructType:
|
|
117
|
+
try:
|
|
118
|
+
return self.result[name]
|
|
119
|
+
except KeyError:
|
|
120
|
+
pass
|
|
121
|
+
self.result[name] = struct = self._decode_struct(name, fields)
|
|
122
|
+
return struct
|
|
123
|
+
|
|
124
|
+
def _decode_struct(self, name: str, fields: Sequence[_StructField]) -> abi.StructType:
|
|
125
|
+
abi_fields = dict[str, abi.ABIType]()
|
|
126
|
+
for field_ in fields:
|
|
127
|
+
field_name = field_["name"]
|
|
128
|
+
field_type = field_["type"]
|
|
129
|
+
if isinstance(field_type, Sequence) and not isinstance(field_type, str): # anonymous inner struct
|
|
130
|
+
inner_struct_name = f"{name}_{field_name}"
|
|
131
|
+
field_abi_type: abi.ABIType = self._decode_struct(inner_struct_name, field_type)
|
|
132
|
+
elif (field_struct_json := self._struct_json.get(field_type)) is not None: # named struct
|
|
133
|
+
field_abi_type = self._get_or_add(field_type, field_struct_json)
|
|
134
|
+
else:
|
|
135
|
+
field_abi_type = abi.ABIType.from_string(field_type)
|
|
136
|
+
abi_fields[field_name] = field_abi_type
|
|
137
|
+
return abi.StructType(struct_name=name, fields=abi_fields)
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def _encode_structs(structs: dict[str, abi.StructType]) -> dict:
|
|
141
|
+
return {name: _encode_struct(structs, struct) for name, struct in structs.items()}
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def _encode_struct(structs: dict[str, abi.StructType], struct: abi.StructType) -> list:
|
|
145
|
+
fields = []
|
|
146
|
+
for field_name, field_type in struct.fields.items():
|
|
147
|
+
fields.append(_StructField(name=field_name, type=_encode_struct_field(structs, field_type)))
|
|
148
|
+
return fields
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def _encode_struct_field(structs: dict[str, abi.StructType], field_type: abi.ABIType) -> str | list:
|
|
152
|
+
if isinstance(field_type, abi.StructType):
|
|
153
|
+
if field_type.display_name in structs:
|
|
154
|
+
return field_type.display_name
|
|
155
|
+
else:
|
|
156
|
+
return _encode_struct(structs, field_type)
|
|
157
|
+
else:
|
|
158
|
+
return field_type.name
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
struct_metadata = wire("structs", encode=_encode_structs, decode=_StructDecoder.decode)
|