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.
Files changed (337) hide show
  1. algokit_abi/__init__.py +9 -0
  2. algokit_abi/_arc32_to_arc56.py +242 -0
  3. algokit_abi/_arc56_serde.py +161 -0
  4. algokit_abi/abi.py +667 -0
  5. algokit_abi/arc32.py +210 -0
  6. algokit_abi/arc56.py +821 -0
  7. algokit_abi/py.typed +0 -0
  8. algokit_algo25/__init__.py +38 -0
  9. algokit_algo25/_encoding.py +46 -0
  10. algokit_algo25/_wordlist.py +2065 -0
  11. algokit_algo25/exceptions.py +29 -0
  12. algokit_algo25/mnemonic.py +128 -0
  13. algokit_algo25/py.typed +0 -0
  14. algokit_algod_client/__init__.py +10 -0
  15. algokit_algod_client/client.py +1585 -0
  16. algokit_algod_client/config.py +36 -0
  17. algokit_algod_client/exceptions.py +59 -0
  18. algokit_algod_client/models/__init__.py +229 -0
  19. algokit_algod_client/models/_account.py +150 -0
  20. algokit_algod_client/models/_account_application_response.py +25 -0
  21. algokit_algod_client/models/_account_asset_response.py +25 -0
  22. algokit_algod_client/models/_account_participation.py +53 -0
  23. algokit_algod_client/models/_account_state_delta.py +30 -0
  24. algokit_algod_client/models/_allocations_for_genesis_file.py +23 -0
  25. algokit_algod_client/models/_allocations_for_genesis_file_state_model.py +42 -0
  26. algokit_algod_client/models/_application.py +23 -0
  27. algokit_algod_client/models/_application_initial_states.py +37 -0
  28. algokit_algod_client/models/_application_kvstorage.py +29 -0
  29. algokit_algod_client/models/_application_local_state.py +33 -0
  30. algokit_algod_client/models/_application_params.py +63 -0
  31. algokit_algod_client/models/_application_state_operation.py +41 -0
  32. algokit_algod_client/models/_application_state_schema.py +22 -0
  33. algokit_algod_client/models/_asset.py +23 -0
  34. algokit_algod_client/models/_asset_holding.py +29 -0
  35. algokit_algod_client/models/_asset_params.py +102 -0
  36. algokit_algod_client/models/_avm_key_value.py +28 -0
  37. algokit_algod_client/models/_avm_value.py +32 -0
  38. algokit_algod_client/models/_block.py +363 -0
  39. algokit_algod_client/models/_block_hash_response.py +14 -0
  40. algokit_algod_client/models/_block_txids_response.py +14 -0
  41. algokit_algod_client/models/_box.py +36 -0
  42. algokit_algod_client/models/_box_descriptor.py +24 -0
  43. algokit_algod_client/models/_boxes_response.py +21 -0
  44. algokit_algod_client/models/_build_version_contains_the_current_algod_build_version_information.py +34 -0
  45. algokit_algod_client/models/_compile_response.py +24 -0
  46. algokit_algod_client/models/_disassemble_response.py +14 -0
  47. algokit_algod_client/models/_error_response.py +22 -0
  48. algokit_algod_client/models/_eval_delta.py +32 -0
  49. algokit_algod_client/models/_eval_delta_key_value.py +28 -0
  50. algokit_algod_client/models/_genesis_file_in_json.py +53 -0
  51. algokit_algod_client/models/_get_block_time_stamp_offset_response.py +14 -0
  52. algokit_algod_client/models/_get_sync_round_response.py +14 -0
  53. algokit_algod_client/models/_ledger_state_delta.py +389 -0
  54. algokit_algod_client/models/_light_block_header_proof.py +32 -0
  55. algokit_algod_client/models/_node_status_response.py +118 -0
  56. algokit_algod_client/models/_pending_transaction_response.py +91 -0
  57. algokit_algod_client/models/_pending_transactions_response.py +29 -0
  58. algokit_algod_client/models/_post_transactions_response.py +14 -0
  59. algokit_algod_client/models/_scratch_change.py +23 -0
  60. algokit_algod_client/models/_serde_helpers.py +241 -0
  61. algokit_algod_client/models/_simulate_initial_states.py +25 -0
  62. algokit_algod_client/models/_simulate_request.py +54 -0
  63. algokit_algod_client/models/_simulate_request_transaction_group.py +25 -0
  64. algokit_algod_client/models/_simulate_response.py +44 -0
  65. algokit_algod_client/models/_simulate_trace_config.py +30 -0
  66. algokit_algod_client/models/_simulate_transaction_group_result.py +46 -0
  67. algokit_algod_client/models/_simulate_transaction_result.py +41 -0
  68. algokit_algod_client/models/_simulate_unnamed_resources_accessed.py +64 -0
  69. algokit_algod_client/models/_simulation_eval_overrides.py +40 -0
  70. algokit_algod_client/models/_simulation_opcode_trace_unit.py +55 -0
  71. algokit_algod_client/models/_simulation_transaction_exec_trace.py +82 -0
  72. algokit_algod_client/models/_source_map.py +30 -0
  73. algokit_algod_client/models/_state_delta.py +6 -0
  74. algokit_algod_client/models/_state_proof.py +28 -0
  75. algokit_algod_client/models/_state_proof_message.py +44 -0
  76. algokit_algod_client/models/_supply_response.py +26 -0
  77. algokit_algod_client/models/_teal_key_value.py +28 -0
  78. algokit_algod_client/models/_teal_key_value_store.py +6 -0
  79. algokit_algod_client/models/_teal_value.py +32 -0
  80. algokit_algod_client/models/_transaction_group_ledger_state_deltas_for_round_response.py +21 -0
  81. algokit_algod_client/models/_transaction_parameters_response.py +45 -0
  82. algokit_algod_client/models/_transaction_proof.py +44 -0
  83. algokit_algod_client/models/_version_contains_the_current_algod_version.py +38 -0
  84. algokit_algod_client/models/suggested_params.py +42 -0
  85. algokit_algod_client/py.typed +1 -0
  86. algokit_algod_client/types.py +7 -0
  87. algokit_algosdk/__init__.py +38 -0
  88. algokit_algosdk/account.py +32 -0
  89. algokit_algosdk/app_access.py +228 -0
  90. algokit_algosdk/box_reference.py +100 -0
  91. algokit_algosdk/constants.py +147 -0
  92. algokit_algosdk/encoding.py +89 -0
  93. algokit_algosdk/error.py +180 -0
  94. algokit_algosdk/logic.py +61 -0
  95. algokit_algosdk/logicsig.py +218 -0
  96. algokit_algosdk/mnemonic.py +216 -0
  97. algokit_algosdk/multisig.py +161 -0
  98. algokit_algosdk/py.typed +0 -0
  99. algokit_algosdk/transaction.py +596 -0
  100. algokit_algosdk/wordlist.py +2054 -0
  101. algokit_common/__init__.py +50 -0
  102. algokit_common/address.py +34 -0
  103. algokit_common/constants.py +47 -0
  104. algokit_common/hashing.py +25 -0
  105. algokit_common/py.typed +0 -0
  106. algokit_common/serde/__init__.py +40 -0
  107. algokit_common/serde/_core.py +610 -0
  108. algokit_common/serde/_primitives.py +135 -0
  109. algokit_common/source_map.py +158 -0
  110. algokit_indexer_client/__init__.py +10 -0
  111. algokit_indexer_client/client.py +1456 -0
  112. algokit_indexer_client/config.py +36 -0
  113. algokit_indexer_client/exceptions.py +59 -0
  114. algokit_indexer_client/models/__init__.py +148 -0
  115. algokit_indexer_client/models/_account.py +161 -0
  116. algokit_indexer_client/models/_account_participation.py +53 -0
  117. algokit_indexer_client/models/_account_response.py +19 -0
  118. algokit_indexer_client/models/_account_state_delta.py +29 -0
  119. algokit_indexer_client/models/_accounts_response.py +29 -0
  120. algokit_indexer_client/models/_application.py +35 -0
  121. algokit_indexer_client/models/_application_local_state.py +45 -0
  122. algokit_indexer_client/models/_application_local_states_response.py +29 -0
  123. algokit_indexer_client/models/_application_log_data.py +28 -0
  124. algokit_indexer_client/models/_application_logs_response.py +33 -0
  125. algokit_indexer_client/models/_application_params.py +62 -0
  126. algokit_indexer_client/models/_application_response.py +20 -0
  127. algokit_indexer_client/models/_application_state_schema.py +22 -0
  128. algokit_indexer_client/models/_applications_response.py +29 -0
  129. algokit_indexer_client/models/_asset.py +35 -0
  130. algokit_indexer_client/models/_asset_balances_response.py +29 -0
  131. algokit_indexer_client/models/_asset_holding.py +41 -0
  132. algokit_indexer_client/models/_asset_holdings_response.py +29 -0
  133. algokit_indexer_client/models/_asset_params.py +102 -0
  134. algokit_indexer_client/models/_asset_response.py +19 -0
  135. algokit_indexer_client/models/_assets_response.py +29 -0
  136. algokit_indexer_client/models/_block.py +150 -0
  137. algokit_indexer_client/models/_block_headers_response.py +29 -0
  138. algokit_indexer_client/models/_block_rewards.py +38 -0
  139. algokit_indexer_client/models/_block_upgrade_state.py +34 -0
  140. algokit_indexer_client/models/_block_upgrade_vote.py +26 -0
  141. algokit_indexer_client/models/_box.py +36 -0
  142. algokit_indexer_client/models/_box_descriptor.py +24 -0
  143. algokit_indexer_client/models/_box_reference.py +28 -0
  144. algokit_indexer_client/models/_boxes_response.py +29 -0
  145. algokit_indexer_client/models/_error_response.py +18 -0
  146. algokit_indexer_client/models/_eval_delta.py +32 -0
  147. algokit_indexer_client/models/_eval_delta_key_value.py +28 -0
  148. algokit_indexer_client/models/_hash_factory.py +14 -0
  149. algokit_indexer_client/models/_hb_proof_fields.py +57 -0
  150. algokit_indexer_client/models/_health_check.py +42 -0
  151. algokit_indexer_client/models/_holding_ref.py +23 -0
  152. algokit_indexer_client/models/_indexer_state_proof_message.py +40 -0
  153. algokit_indexer_client/models/_locals_ref.py +23 -0
  154. algokit_indexer_client/models/_merkle_array_proof.py +29 -0
  155. algokit_indexer_client/models/_mini_asset_holding.py +38 -0
  156. algokit_indexer_client/models/_on_completion.py +25 -0
  157. algokit_indexer_client/models/_participation_updates.py +22 -0
  158. algokit_indexer_client/models/_resource_ref.py +42 -0
  159. algokit_indexer_client/models/_serde_helpers.py +241 -0
  160. algokit_indexer_client/models/_state_delta.py +6 -0
  161. algokit_indexer_client/models/_state_proof_fields.py +57 -0
  162. algokit_indexer_client/models/_state_proof_participant.py +20 -0
  163. algokit_indexer_client/models/_state_proof_reveal.py +25 -0
  164. algokit_indexer_client/models/_state_proof_sig_slot.py +20 -0
  165. algokit_indexer_client/models/_state_proof_signature.py +37 -0
  166. algokit_indexer_client/models/_state_proof_tracking.py +32 -0
  167. algokit_indexer_client/models/_state_proof_verifier.py +24 -0
  168. algokit_indexer_client/models/_state_schema.py +25 -0
  169. algokit_indexer_client/models/_teal_key_value.py +28 -0
  170. algokit_indexer_client/models/_teal_key_value_store.py +6 -0
  171. algokit_indexer_client/models/_teal_value.py +32 -0
  172. algokit_indexer_client/models/_transaction.py +213 -0
  173. algokit_indexer_client/models/_transaction_application.py +105 -0
  174. algokit_indexer_client/models/_transaction_asset_config.py +31 -0
  175. algokit_indexer_client/models/_transaction_asset_freeze.py +29 -0
  176. algokit_indexer_client/models/_transaction_asset_transfer.py +41 -0
  177. algokit_indexer_client/models/_transaction_heartbeat.py +52 -0
  178. algokit_indexer_client/models/_transaction_keyreg.py +59 -0
  179. algokit_indexer_client/models/_transaction_payment.py +33 -0
  180. algokit_indexer_client/models/_transaction_response.py +19 -0
  181. algokit_indexer_client/models/_transaction_signature.py +35 -0
  182. algokit_indexer_client/models/_transaction_signature_logicsig.py +59 -0
  183. algokit_indexer_client/models/_transaction_signature_multisig.py +36 -0
  184. algokit_indexer_client/models/_transaction_signature_multisig_subsignature.py +28 -0
  185. algokit_indexer_client/models/_transaction_state_proof.py +32 -0
  186. algokit_indexer_client/models/_transactions_response.py +29 -0
  187. algokit_indexer_client/py.typed +1 -0
  188. algokit_indexer_client/types.py +7 -0
  189. algokit_kmd_client/__init__.py +10 -0
  190. algokit_kmd_client/client.py +1240 -0
  191. algokit_kmd_client/config.py +36 -0
  192. algokit_kmd_client/exceptions.py +59 -0
  193. algokit_kmd_client/models/__init__.py +112 -0
  194. algokit_kmd_client/models/_classical_signatures.py +4 -0
  195. algokit_kmd_client/models/_create_wallet_request.py +30 -0
  196. algokit_kmd_client/models/_create_wallet_response.py +19 -0
  197. algokit_kmd_client/models/_delete_key_request.py +27 -0
  198. algokit_kmd_client/models/_delete_multisig_request.py +27 -0
  199. algokit_kmd_client/models/_digest_represents_a32_byte_value_holding_the256_bit_hash_digest.py +4 -0
  200. algokit_kmd_client/models/_ed25519_public_key.py +4 -0
  201. algokit_kmd_client/models/_export_key_request.py +27 -0
  202. algokit_kmd_client/models/_export_key_response.py +24 -0
  203. algokit_kmd_client/models/_export_master_key_request.py +22 -0
  204. algokit_kmd_client/models/_export_master_key_response.py +18 -0
  205. algokit_kmd_client/models/_export_multisig_request.py +23 -0
  206. algokit_kmd_client/models/_export_multisig_response.py +26 -0
  207. algokit_kmd_client/models/_generate_key_request.py +18 -0
  208. algokit_kmd_client/models/_generate_key_response.py +19 -0
  209. algokit_kmd_client/models/_import_key_request.py +28 -0
  210. algokit_kmd_client/models/_import_key_response.py +19 -0
  211. algokit_kmd_client/models/_import_multisig_request.py +30 -0
  212. algokit_kmd_client/models/_import_multisig_response.py +19 -0
  213. algokit_kmd_client/models/_init_wallet_handle_token_request.py +22 -0
  214. algokit_kmd_client/models/_init_wallet_handle_token_response.py +18 -0
  215. algokit_kmd_client/models/_list_keys_request.py +18 -0
  216. algokit_kmd_client/models/_list_keys_response.py +18 -0
  217. algokit_kmd_client/models/_list_multisig_request.py +18 -0
  218. algokit_kmd_client/models/_list_multisig_response.py +18 -0
  219. algokit_kmd_client/models/_list_wallets_request.py +11 -0
  220. algokit_kmd_client/models/_list_wallets_response.py +25 -0
  221. algokit_kmd_client/models/_master_derivation_key.py +4 -0
  222. algokit_kmd_client/models/_multisig_sig.py +33 -0
  223. algokit_kmd_client/models/_multisig_subsig.py +23 -0
  224. algokit_kmd_client/models/_public_key.py +4 -0
  225. algokit_kmd_client/models/_release_wallet_handle_token_request.py +18 -0
  226. algokit_kmd_client/models/_rename_wallet_request.py +26 -0
  227. algokit_kmd_client/models/_rename_wallet_response.py +19 -0
  228. algokit_kmd_client/models/_renew_wallet_handle_token_request.py +18 -0
  229. algokit_kmd_client/models/_renew_wallet_handle_token_response.py +19 -0
  230. algokit_kmd_client/models/_serde_helpers.py +241 -0
  231. algokit_kmd_client/models/_sign_multisig_response.py +24 -0
  232. algokit_kmd_client/models/_sign_multisig_txn_request.py +45 -0
  233. algokit_kmd_client/models/_sign_program_multisig_request.py +50 -0
  234. algokit_kmd_client/models/_sign_program_multisig_response.py +24 -0
  235. algokit_kmd_client/models/_sign_program_request.py +37 -0
  236. algokit_kmd_client/models/_sign_program_response.py +24 -0
  237. algokit_kmd_client/models/_sign_transaction_response.py +24 -0
  238. algokit_kmd_client/models/_sign_txn_request.py +36 -0
  239. algokit_kmd_client/models/_signature.py +4 -0
  240. algokit_kmd_client/models/_tx_type.py +4 -0
  241. algokit_kmd_client/models/_versions_request.py +11 -0
  242. algokit_kmd_client/models/_versions_response.py +19 -0
  243. algokit_kmd_client/models/_wallet.py +38 -0
  244. algokit_kmd_client/models/_wallet_handle.py +24 -0
  245. algokit_kmd_client/models/_wallet_info_request.py +18 -0
  246. algokit_kmd_client/models/_wallet_info_response.py +19 -0
  247. algokit_kmd_client/py.typed +1 -0
  248. algokit_kmd_client/types.py +7 -0
  249. algokit_transact/__init__.py +190 -0
  250. algokit_transact/codec/__init__.py +0 -0
  251. algokit_transact/codec/msgpack.py +11 -0
  252. algokit_transact/codec/serde.py +7 -0
  253. algokit_transact/codec/signed.py +57 -0
  254. algokit_transact/codec/transaction.py +65 -0
  255. algokit_transact/exceptions.py +17 -0
  256. algokit_transact/logicsig.py +220 -0
  257. algokit_transact/models/__init__.py +0 -0
  258. algokit_transact/models/app_call.py +447 -0
  259. algokit_transact/models/asset_config.py +19 -0
  260. algokit_transact/models/asset_freeze.py +11 -0
  261. algokit_transact/models/asset_transfer.py +13 -0
  262. algokit_transact/models/common.py +17 -0
  263. algokit_transact/models/heartbeat.py +21 -0
  264. algokit_transact/models/key_registration.py +14 -0
  265. algokit_transact/models/payment.py +14 -0
  266. algokit_transact/models/signed_transaction.py +21 -0
  267. algokit_transact/models/state_proof.py +150 -0
  268. algokit_transact/models/transaction.py +88 -0
  269. algokit_transact/multisig.py +93 -0
  270. algokit_transact/ops/__init__.py +0 -0
  271. algokit_transact/ops/fees.py +47 -0
  272. algokit_transact/ops/group.py +28 -0
  273. algokit_transact/ops/ids.py +14 -0
  274. algokit_transact/ops/validate.py +503 -0
  275. algokit_transact/py.typed +0 -0
  276. algokit_transact/signer.py +195 -0
  277. algokit_transact/signing/__init__.py +0 -0
  278. algokit_transact/signing/logic_signature.py +19 -0
  279. algokit_transact/signing/multisig.py +84 -0
  280. algokit_transact/signing/types.py +39 -0
  281. algokit_transact/signing/validation.py +63 -0
  282. algokit_utils/__init__.py +23 -0
  283. algokit_utils/_debugging.py +304 -0
  284. algokit_utils/accounts/__init__.py +2 -0
  285. algokit_utils/accounts/account_manager.py +1051 -0
  286. algokit_utils/accounts/kmd_account_manager.py +206 -0
  287. algokit_utils/algo25.py +46 -0
  288. algokit_utils/algorand.py +383 -0
  289. algokit_utils/applications/__init__.py +7 -0
  290. algokit_utils/applications/abi.py +280 -0
  291. algokit_utils/applications/app_client.py +2193 -0
  292. algokit_utils/applications/app_deployer.py +788 -0
  293. algokit_utils/applications/app_factory.py +1140 -0
  294. algokit_utils/applications/app_manager.py +575 -0
  295. algokit_utils/applications/app_spec/__init__.py +6 -0
  296. algokit_utils/applications/enums.py +40 -0
  297. algokit_utils/assets/__init__.py +1 -0
  298. algokit_utils/assets/asset_manager.py +344 -0
  299. algokit_utils/clients/__init__.py +41 -0
  300. algokit_utils/clients/client_manager.py +756 -0
  301. algokit_utils/clients/dispenser_api_client.py +212 -0
  302. algokit_utils/common.py +40 -0
  303. algokit_utils/config.py +159 -0
  304. algokit_utils/errors/__init__.py +1 -0
  305. algokit_utils/errors/logic_error.py +160 -0
  306. algokit_utils/models/__init__.py +7 -0
  307. algokit_utils/models/account.py +12 -0
  308. algokit_utils/models/amount.py +198 -0
  309. algokit_utils/models/application.py +90 -0
  310. algokit_utils/models/network.py +29 -0
  311. algokit_utils/models/simulate.py +7 -0
  312. algokit_utils/models/state.py +53 -0
  313. algokit_utils/models/transaction.py +49 -0
  314. algokit_utils/protocols/__init__.py +3 -0
  315. algokit_utils/protocols/account.py +11 -0
  316. algokit_utils/protocols/signer.py +17 -0
  317. algokit_utils/protocols/typed_clients.py +110 -0
  318. algokit_utils/py.typed +0 -0
  319. algokit_utils/transact.py +195 -0
  320. algokit_utils/transactions/__init__.py +3 -0
  321. algokit_utils/transactions/builders/__init__.py +67 -0
  322. algokit_utils/transactions/builders/app.py +248 -0
  323. algokit_utils/transactions/builders/asset.py +256 -0
  324. algokit_utils/transactions/builders/common.py +263 -0
  325. algokit_utils/transactions/builders/keyreg.py +103 -0
  326. algokit_utils/transactions/builders/method_call.py +380 -0
  327. algokit_utils/transactions/builders/payment.py +43 -0
  328. algokit_utils/transactions/composer_resources.py +409 -0
  329. algokit_utils/transactions/fee_coverage.py +79 -0
  330. algokit_utils/transactions/helpers.py +9 -0
  331. algokit_utils/transactions/transaction_composer.py +1574 -0
  332. algokit_utils/transactions/transaction_creator.py +699 -0
  333. algokit_utils/transactions/transaction_sender.py +1240 -0
  334. algokit_utils/transactions/types.py +262 -0
  335. algokit_utils-5.0.0a3.dist-info/METADATA +105 -0
  336. algokit_utils-5.0.0a3.dist-info/RECORD +337 -0
  337. algokit_utils-5.0.0a3.dist-info/WHEEL +4 -0
@@ -0,0 +1,575 @@
1
+ import base64
2
+ from collections.abc import Mapping, Sequence
3
+
4
+ import algokit_algosdk as algosdk
5
+ from algokit_abi import arc56
6
+ from algokit_algod_client import AlgodClient
7
+ from algokit_algod_client import models as algod_models
8
+ from algokit_common import ProgramSourceMap, get_application_address, public_key_from_address
9
+ from algokit_common.serde import to_wire
10
+ from algokit_transact.signer import AddressWithTransactionSigner
11
+ from algokit_utils.applications.abi import ABIReturn, ABIType, ABIValue, extract_abi_return_from_logs
12
+ from algokit_utils.models.application import (
13
+ AppInformation,
14
+ AppState,
15
+ CompiledTeal,
16
+ )
17
+ from algokit_utils.models.state import BoxIdentifier, BoxName, BoxReference, DataTypeFlag, TealTemplateParams
18
+
19
+ __all__ = [
20
+ "DELETABLE_TEMPLATE_NAME",
21
+ "UPDATABLE_TEMPLATE_NAME",
22
+ "AppManager",
23
+ ]
24
+
25
+ AlgosdkBoxReference = algosdk.box_reference.BoxReference
26
+
27
+
28
+ UPDATABLE_TEMPLATE_NAME = "TMPL_UPDATABLE"
29
+ """The name of the TEAL template variable for deploy-time immutability control."""
30
+
31
+ DELETABLE_TEMPLATE_NAME = "TMPL_DELETABLE"
32
+ """The name of the TEAL template variable for deploy-time permanence control."""
33
+
34
+
35
+ def _is_valid_token_character(char: str) -> bool:
36
+ return char.isalnum() or char == "_"
37
+
38
+
39
+ def _last_token_base64(line: str, idx: int) -> bool:
40
+ try:
41
+ *_, last = line[:idx].split()
42
+ except ValueError:
43
+ return False
44
+ return last in ("base64", "b64")
45
+
46
+
47
+ def _find_template_token(line: str, token: str, start: int = 0, end: int = -1) -> int | None:
48
+ if end < 0:
49
+ end = len(line)
50
+
51
+ idx = start
52
+ while idx < end:
53
+ token_idx = _find_unquoted_string(line, token, idx, end)
54
+ if token_idx is None:
55
+ break
56
+ trailing_idx = token_idx + len(token)
57
+ if (token_idx == 0 or not _is_valid_token_character(line[token_idx - 1])) and (
58
+ trailing_idx >= len(line) or not _is_valid_token_character(line[trailing_idx])
59
+ ):
60
+ return token_idx
61
+ idx = trailing_idx
62
+ return None
63
+
64
+
65
+ def _find_unquoted_string(line: str, token: str, start: int = 0, end: int = -1) -> int | None:
66
+ if end < 0:
67
+ end = len(line)
68
+ idx = start
69
+ in_quotes = in_base64 = False
70
+ while idx < end:
71
+ current_char = line[idx]
72
+ match current_char:
73
+ case " " | "(" if not in_quotes and _last_token_base64(line, idx):
74
+ in_base64 = True
75
+ case " " | ")" if not in_quotes and in_base64:
76
+ in_base64 = False
77
+ case "\\" if in_quotes:
78
+ idx += 1
79
+ case '"':
80
+ in_quotes = not in_quotes
81
+ case _ if not in_quotes and not in_base64 and line.startswith(token, idx):
82
+ return idx
83
+ idx += 1
84
+ return None
85
+
86
+
87
+ def _replace_template_variable(program_lines: list[str], template_variable: str, value: str) -> tuple[list[str], int]:
88
+ result: list[str] = []
89
+ match_count = 0
90
+ token = f"TMPL_{template_variable}" if not template_variable.startswith("TMPL_") else template_variable
91
+ token_idx_offset = len(value) - len(token)
92
+ for line in program_lines:
93
+ comment_idx = _find_unquoted_string(line, "//")
94
+ if comment_idx is None:
95
+ comment_idx = len(line)
96
+ code = line[:comment_idx]
97
+ comment = line[comment_idx:]
98
+ trailing_idx = 0
99
+ while True:
100
+ token_idx = _find_template_token(code, token, trailing_idx)
101
+ if token_idx is None:
102
+ break
103
+
104
+ trailing_idx = token_idx + len(token)
105
+ prefix = code[:token_idx]
106
+ suffix = code[trailing_idx:]
107
+ code = f"{prefix}{value}{suffix}"
108
+ match_count += 1
109
+ trailing_idx += token_idx_offset
110
+ result.append(code + comment)
111
+ return result, match_count
112
+
113
+
114
+ class AppManager:
115
+ """A manager class for interacting with Algorand applications.
116
+
117
+ Provides functionality for compiling TEAL code, managing application state,
118
+ and interacting with application boxes.
119
+
120
+ :param algod_client: The Algorand client instance to use for interacting with the network
121
+
122
+ :example:
123
+ >>> app_manager = AppManager(algod_client)
124
+ """
125
+
126
+ def __init__(self, algod_client: AlgodClient):
127
+ self._algod = algod_client
128
+ self._compilation_results: dict[str, CompiledTeal] = {}
129
+
130
+ def compile_teal(self, teal_code: str) -> CompiledTeal:
131
+ """Compile TEAL source code.
132
+
133
+ :param teal_code: The TEAL source code to compile
134
+ :return: The compiled TEAL code and associated metadata
135
+ """
136
+
137
+ if teal_code in self._compilation_results:
138
+ return self._compilation_results[teal_code]
139
+
140
+ compiled = self._algod.teal_compile(teal_code.encode("utf-8"), sourcemap=True)
141
+ sourcemap_dict = to_wire(compiled.sourcemap) if compiled.sourcemap else {}
142
+ result = CompiledTeal(
143
+ teal=teal_code,
144
+ compiled=compiled.result,
145
+ compiled_hash=compiled.hash_,
146
+ compiled_base64_to_bytes=base64.b64decode(compiled.result),
147
+ source_map=ProgramSourceMap(sourcemap_dict),
148
+ )
149
+ self._compilation_results[teal_code] = result
150
+ return result
151
+
152
+ def compile_teal_template(
153
+ self,
154
+ teal_template_code: str,
155
+ template_params: TealTemplateParams | None = None,
156
+ deployment_metadata: Mapping[str, bool | None] | None = None,
157
+ ) -> CompiledTeal:
158
+ """Compile a TEAL template with parameters.
159
+
160
+ :param teal_template_code: The TEAL template code to compile
161
+ :param template_params: Parameters to substitute in the template
162
+ :param deployment_metadata: Deployment control parameters
163
+ :return: The compiled TEAL code and associated metadata
164
+
165
+ :example:
166
+ >>> app_manager = AppManager(algod_client)
167
+ >>> teal_template_code =
168
+ ... # This is a TEAL template
169
+ ... # It can contain template variables like {TMPL_UPDATABLE} and {TMPL_DELETABLE}
170
+ ...
171
+ >>> compiled_teal = app_manager.compile_teal_template(teal_template_code)
172
+ """
173
+
174
+ teal_code = AppManager.strip_teal_comments(teal_template_code)
175
+ teal_code = AppManager.replace_template_variables(teal_code, template_params or {})
176
+
177
+ if deployment_metadata:
178
+ teal_code = AppManager.replace_teal_template_deploy_time_control_params(teal_code, deployment_metadata)
179
+
180
+ return self.compile_teal(teal_code)
181
+
182
+ def get_compilation_result(self, teal_code: str) -> CompiledTeal | None:
183
+ """Get cached compilation result for TEAL code if available.
184
+
185
+ :param teal_code: The TEAL source code
186
+ :return: The cached compilation result if available, None otherwise
187
+
188
+ :example:
189
+ >>> app_manager = AppManager(algod_client)
190
+ >>> teal_code = "RETURN 1"
191
+ >>> compiled_teal = app_manager.compile_teal(teal_code)
192
+ >>> compilation_result = app_manager.get_compilation_result(teal_code)
193
+ """
194
+ return self._compilation_results.get(teal_code)
195
+
196
+ def get_by_id(self, app_id: int) -> AppInformation:
197
+ """Get information about an application by ID.
198
+
199
+ :param app_id: The application ID
200
+ :return: Information about the application
201
+
202
+ :example:
203
+ >>> app_manager = AppManager(algod_client)
204
+ >>> app_id = 1234567890
205
+ >>> app_info = app_manager.get_by_id(app_id)
206
+ """
207
+
208
+ app = self._algod.get_application_by_id(app_id)
209
+ app_params = app.params
210
+
211
+ return AppInformation(
212
+ app_id=app_id,
213
+ app_address=get_application_address(app_id),
214
+ approval_program=app_params.approval_program,
215
+ clear_state_program=app_params.clear_state_program,
216
+ creator=app_params.creator,
217
+ local_ints=app_params.local_state_schema.num_uints if app_params.local_state_schema else 0,
218
+ local_byte_slices=app_params.local_state_schema.num_byte_slices if app_params.local_state_schema else 0,
219
+ global_ints=app_params.global_state_schema.num_uints if app_params.global_state_schema else 0,
220
+ global_byte_slices=app_params.global_state_schema.num_byte_slices if app_params.global_state_schema else 0,
221
+ extra_program_pages=app_params.extra_program_pages or 0,
222
+ global_state=self.decode_app_state(app_params.global_state),
223
+ )
224
+
225
+ def get_global_state(self, app_id: int) -> dict[str, AppState]:
226
+ """Get the global state of an application.
227
+
228
+ :param app_id: The application ID
229
+ :return: The application's global state
230
+
231
+ :example:
232
+ >>> app_manager = AppManager(algod_client)
233
+ >>> app_id = 123
234
+ >>> global_state = app_manager.get_global_state(app_id)
235
+ """
236
+
237
+ return self.get_by_id(app_id).global_state
238
+
239
+ def get_local_state(self, app_id: int, address: str) -> dict[str, AppState]:
240
+ """Get the local state for an account in an application.
241
+
242
+ :param app_id: The application ID
243
+ :param address: The account address
244
+ :return: The account's local state for the application
245
+ :raises ValueError: If local state is not found
246
+
247
+ :example:
248
+ >>> app_manager = AppManager(algod_client)
249
+ >>> app_id = 123
250
+ >>> address = "SENDER_ADDRESS"
251
+ >>> local_state = app_manager.get_local_state(app_id, address)
252
+ """
253
+
254
+ app_info = self._algod.account_application_information(address, app_id)
255
+ if not app_info.app_local_state or not app_info.app_local_state.key_value:
256
+ raise ValueError("Couldn't find local state")
257
+ return self.decode_app_state(app_info.app_local_state.key_value)
258
+
259
+ def get_box_names(self, app_id: int) -> list[BoxName]:
260
+ """Get names of all boxes for an application.
261
+
262
+ If the box name can't be decoded from UTF-8, the string representation of the bytes is returned.
263
+
264
+ :param app_id: The application ID
265
+ :return: List of box names
266
+
267
+ :example:
268
+ >>> app_manager = AppManager(algod_client)
269
+ >>> app_id = 123
270
+ >>> box_names = app_manager.get_box_names(app_id)
271
+ """
272
+
273
+ def utf8_decode_or_string_cast(b: bytes) -> str:
274
+ """Return the UTF-8 encoding or return the string representation of the bytes."""
275
+ try:
276
+ return b.decode("utf-8")
277
+ except UnicodeDecodeError:
278
+ return str(b)
279
+
280
+ box_result = self._algod.get_application_boxes(app_id)
281
+ return [
282
+ BoxName(
283
+ name_raw=b.name,
284
+ name_base64=base64.b64encode(b.name).decode("utf-8"),
285
+ name=utf8_decode_or_string_cast(b.name),
286
+ )
287
+ for b in (box_result.boxes or [])
288
+ ]
289
+
290
+ def get_box_value(self, app_id: int, box_name: BoxIdentifier) -> bytes:
291
+ """Get the value stored in a box.
292
+
293
+ :param app_id: The application ID
294
+ :param box_name: The box identifier
295
+ :return: The box value as bytes
296
+
297
+ :example:
298
+ >>> app_manager = AppManager(algod_client)
299
+ >>> app_id = 123
300
+ >>> box_name = "BOX_NAME"
301
+ >>> box_value = app_manager.get_box_value(app_id, box_name)
302
+ """
303
+
304
+ name = AppManager.get_box_reference(box_name)[1]
305
+ box_result = self._algod.get_application_box_by_name(
306
+ app_id,
307
+ name if isinstance(name, bytes | bytearray | memoryview) else str(name).encode("utf-8"),
308
+ )
309
+ return box_result.value
310
+
311
+ def get_box_values(self, app_id: int, box_names: list[BoxIdentifier]) -> list[bytes]:
312
+ """Get values for multiple boxes.
313
+
314
+ :param app_id: The application ID
315
+ :param box_names: List of box identifiers
316
+ :return: List of box values as bytes
317
+
318
+ :example:
319
+ >>> app_manager = AppManager(algod_client)
320
+ >>> app_id = 123
321
+ >>> box_names = ["BOX_NAME_1", "BOX_NAME_2"]
322
+ >>> box_values = app_manager.get_box_values(app_id, box_names)
323
+ """
324
+
325
+ return [self.get_box_value(app_id, box_name) for box_name in box_names]
326
+
327
+ def get_box_value_from_abi_type(self, app_id: int, box_name: BoxIdentifier, abi_type: ABIType) -> ABIValue:
328
+ """Get and decode a box value using an ABI type.
329
+
330
+ :param app_id: The application ID
331
+ :param box_name: The box identifier
332
+ :param abi_type: The ABI type to decode with
333
+ :return: The decoded box value
334
+ :raises ValueError: If decoding fails
335
+
336
+ :example:
337
+ >>> app_manager = AppManager(algod_client)
338
+ >>> app_id = 123
339
+ >>> box_name = "BOX_NAME"
340
+ >>> abi_type = ABIType.UINT
341
+ >>> box_value = app_manager.get_box_value_from_abi_type(app_id, box_name, abi_type)
342
+ """
343
+
344
+ value = self.get_box_value(app_id, box_name)
345
+ try:
346
+ return abi_type.decode(value) # type: ignore[no-any-return]
347
+ except Exception as e:
348
+ raise ValueError(f"Failed to decode box value {value.decode('utf-8')} with ABI type {abi_type}") from e
349
+
350
+ def get_box_values_from_abi_type(
351
+ self, app_id: int, box_names: list[BoxIdentifier], abi_type: ABIType
352
+ ) -> list[ABIValue]:
353
+ """Get and decode multiple box values using an ABI type.
354
+
355
+ :param app_id: The application ID
356
+ :param box_names: List of box identifiers
357
+ :param abi_type: The ABI type to decode with
358
+ :return: List of decoded box values
359
+
360
+ :example:
361
+ >>> app_manager = AppManager(algod_client)
362
+ >>> app_id = 123
363
+ >>> box_names = ["BOX_NAME_1", "BOX_NAME_2"]
364
+ >>> abi_type = ABIType.UINT
365
+ >>> box_values = app_manager.get_box_values_from_abi_type(app_id, box_names, abi_type)
366
+ """
367
+
368
+ return [self.get_box_value_from_abi_type(app_id, box_name, abi_type) for box_name in box_names]
369
+
370
+ @staticmethod
371
+ def get_box_reference(box_id: BoxIdentifier | BoxReference) -> tuple[int, bytes]:
372
+ """Get standardized box reference from various identifier types.
373
+
374
+ :param box_id: The box identifier
375
+ :return: Tuple of (app_id, box_name_bytes)
376
+ :raises ValueError: If box identifier type is invalid
377
+
378
+ :example:
379
+ >>> app_manager = AppManager(algod_client)
380
+ >>> app_id = 123
381
+ >>> box_name = "BOX_NAME"
382
+ >>> box_reference = app_manager.get_box_reference(box_name)
383
+ """
384
+
385
+ if isinstance(box_id, (BoxReference | AlgosdkBoxReference)):
386
+ return box_id.app_id, box_id.name
387
+
388
+ name = b""
389
+ if isinstance(box_id, str):
390
+ name = box_id.encode("utf-8")
391
+ elif isinstance(box_id, bytes):
392
+ name = box_id
393
+ elif isinstance(box_id, AddressWithTransactionSigner):
394
+ name = public_key_from_address(box_id.addr)
395
+ else:
396
+ raise ValueError(f"Invalid box identifier type: {type(box_id)}")
397
+
398
+ return 0, name
399
+
400
+ @staticmethod
401
+ def get_abi_return(
402
+ confirmation: algod_models.PendingTransactionResponse,
403
+ method: arc56.Method | None = None,
404
+ ) -> ABIReturn | None:
405
+ """Get the ABI return value from a transaction confirmation.
406
+
407
+ :param confirmation: The transaction confirmation
408
+ :param method: The ABI method
409
+ :return: The parsed ABI return value, or None if not available
410
+
411
+ :example:
412
+ >>> app_manager = AppManager(algod_client)
413
+ >>> app_id = 123
414
+ >>> method = "METHOD_NAME"
415
+ >>> confirmation = algod_client.pending_transaction_information(tx_id)
416
+ >>> abi_return = app_manager.get_abi_return(confirmation, method)
417
+ """
418
+ if not method:
419
+ return None
420
+
421
+ return extract_abi_return_from_logs(confirmation, method)
422
+
423
+ @staticmethod
424
+ def decode_app_state(state: Sequence[algod_models.TealKeyValue] | None) -> dict[str, AppState]:
425
+ """Decode application state from raw format.
426
+
427
+ :param state: The raw application state
428
+ :return: Decoded application state
429
+ :raises ValueError: If unknown state data type is encountered
430
+
431
+ :example:
432
+ >>> app_manager = AppManager(algod_client)
433
+ >>> app_id = 123
434
+ >>> state = app_manager.get_global_state(app_id)
435
+ >>> decoded_state = app_manager.decode_app_state(state)
436
+ """
437
+
438
+ state_values: dict[str, AppState] = {}
439
+
440
+ def decode_bytes_to_str(value: bytes) -> str:
441
+ try:
442
+ return value.decode("utf-8")
443
+ except UnicodeDecodeError:
444
+ return value.hex()
445
+
446
+ if not state:
447
+ return state_values
448
+
449
+ for state_val in state:
450
+ key_raw = state_val.key
451
+ key_base64 = base64.b64encode(key_raw).decode("utf-8")
452
+ key = decode_bytes_to_str(key_raw)
453
+ teal_value = state_val.value
454
+
455
+ data_type_flag = DataTypeFlag(teal_value.type_)
456
+
457
+ if data_type_flag == DataTypeFlag.BYTES:
458
+ value_raw = teal_value.bytes_ or b""
459
+ value_base64 = base64.b64encode(value_raw).decode("utf-8")
460
+ state_values[key] = AppState(
461
+ key_raw=key_raw,
462
+ key_base64=key_base64,
463
+ value_raw=value_raw,
464
+ value_base64=value_base64,
465
+ value=decode_bytes_to_str(value_raw),
466
+ )
467
+ elif data_type_flag == DataTypeFlag.UINT:
468
+ state_values[key] = AppState(
469
+ key_raw=key_raw,
470
+ key_base64=key_base64,
471
+ value_raw=None,
472
+ value_base64=None,
473
+ value=int(teal_value.uint or 0),
474
+ )
475
+ else:
476
+ raise ValueError(f"Received unknown state data type of {data_type_flag}")
477
+
478
+ return state_values
479
+
480
+ @staticmethod
481
+ def replace_template_variables(program: str, template_values: TealTemplateParams) -> str:
482
+ """Replace template variables in TEAL code.
483
+
484
+ :param program: The TEAL program code
485
+ :param template_values: Template variable values to substitute
486
+ :return: TEAL code with substituted values
487
+ :raises ValueError: If template value type is unexpected
488
+
489
+ :example:
490
+ >>> app_manager = AppManager(algod_client)
491
+ >>> app_id = 123
492
+ >>> program = "RETURN 1"
493
+ >>> template_values = {"TMPL_UPDATABLE": True, "TMPL_DELETABLE": True}
494
+ >>> updated_program = app_manager.replace_template_variables(program, template_values)
495
+ """
496
+
497
+ program_lines = program.splitlines()
498
+ for template_variable_name, template_value in template_values.items():
499
+ match template_value:
500
+ case int():
501
+ value = str(template_value)
502
+ case str():
503
+ value = "0x" + template_value.encode("utf-8").hex()
504
+ case bytes():
505
+ value = "0x" + template_value.hex()
506
+ case _:
507
+ raise ValueError(
508
+ f"Unexpected template value type {template_variable_name}: {template_value.__class__}"
509
+ )
510
+
511
+ program_lines, _ = _replace_template_variable(program_lines, template_variable_name, value)
512
+
513
+ return "\n".join(program_lines)
514
+
515
+ @staticmethod
516
+ def replace_teal_template_deploy_time_control_params(
517
+ teal_template_code: str, params: Mapping[str, bool | None]
518
+ ) -> str:
519
+ """Replace deploy-time control parameters in TEAL template.
520
+
521
+ :param teal_template_code: The TEAL template code
522
+ :param params: The deploy-time control parameters
523
+ :return: TEAL code with substituted control parameters
524
+ :raises ValueError: If template variables not found in code
525
+
526
+ :example:
527
+ >>> app_manager = AppManager(algod_client)
528
+ >>> app_id = 123
529
+ >>> teal_template_code = "RETURN 1"
530
+ >>> params = {"TMPL_UPDATABLE": True, "TMPL_DELETABLE": True}
531
+ >>> updated_teal_code = app_manager.replace_teal_template_deploy_time_control_params(
532
+ teal_template_code, params
533
+ )
534
+ """
535
+
536
+ updatable = params.get("updatable")
537
+ if updatable is not None:
538
+ if UPDATABLE_TEMPLATE_NAME not in teal_template_code:
539
+ raise ValueError(
540
+ f"Deploy-time updatability control requested for app deployment, but {UPDATABLE_TEMPLATE_NAME} "
541
+ "not present in TEAL code"
542
+ )
543
+ teal_template_code = teal_template_code.replace(UPDATABLE_TEMPLATE_NAME, str(int(updatable)))
544
+
545
+ deletable = params.get("deletable")
546
+ if deletable is not None:
547
+ if DELETABLE_TEMPLATE_NAME not in teal_template_code:
548
+ raise ValueError(
549
+ f"Deploy-time deletability control requested for app deployment, but {DELETABLE_TEMPLATE_NAME} "
550
+ "not present in TEAL code"
551
+ )
552
+ teal_template_code = teal_template_code.replace(DELETABLE_TEMPLATE_NAME, str(int(deletable)))
553
+
554
+ return teal_template_code
555
+
556
+ @staticmethod
557
+ def strip_teal_comments(teal_code: str) -> str:
558
+ """Strip comments from TEAL code.
559
+
560
+ :param teal_code: The TEAL code to strip comments from
561
+ :return: The TEAL code with comments stripped
562
+
563
+ :example:
564
+ >>> app_manager = AppManager(algod_client)
565
+ >>> teal_code = "RETURN 1"
566
+ >>> stripped_teal_code = app_manager.strip_teal_comments(teal_code)
567
+ """
568
+
569
+ def _strip_comment(line: str) -> str:
570
+ comment_idx = _find_unquoted_string(line, "//")
571
+ if comment_idx is None:
572
+ return line
573
+ return line[:comment_idx].rstrip()
574
+
575
+ return "\n".join(_strip_comment(line) for line in teal_code.splitlines())
@@ -0,0 +1,6 @@
1
+ # app spec definitions used to be defined here, import new definitions from algokit_abi for backwards compatability
2
+ from algokit_abi import arc32, arc56
3
+ from algokit_abi.arc32 import Arc32Contract
4
+ from algokit_abi.arc56 import Arc56Contract
5
+
6
+ __all__ = ["Arc32Contract", "Arc56Contract", "arc32", "arc56"]
@@ -0,0 +1,40 @@
1
+ from enum import Enum
2
+
3
+ # NOTE: this is moved to a separate file to avoid circular imports
4
+
5
+
6
+ class OnSchemaBreak(Enum):
7
+ """Action to take if an Application's schema has breaking changes"""
8
+
9
+ Fail = 0
10
+ """Fail the deployment"""
11
+ ReplaceApp = 2
12
+ """Create a new Application and delete the old Application in a single transaction"""
13
+ AppendApp = 3
14
+ """Create a new Application"""
15
+
16
+
17
+ class OnUpdate(Enum):
18
+ """Action to take if an Application has been updated"""
19
+
20
+ Fail = 0
21
+ """Fail the deployment"""
22
+ UpdateApp = 1
23
+ """Update the Application with the new approval and clear programs"""
24
+ ReplaceApp = 2
25
+ """Create a new Application and delete the old Application in a single transaction"""
26
+ AppendApp = 3
27
+ """Create a new application"""
28
+
29
+
30
+ class OperationPerformed(Enum):
31
+ """Describes the actions taken during deployment"""
32
+
33
+ Nothing = 0
34
+ """An existing Application was found"""
35
+ Create = 1
36
+ """No existing Application was found, created a new Application"""
37
+ Update = 2
38
+ """An existing Application was found, but was out of date, updated to latest version"""
39
+ Replace = 3
40
+ """An existing Application was found, but was out of date, created a new Application and deleted the original"""
@@ -0,0 +1 @@
1
+ from algokit_utils.assets.asset_manager import * # noqa: F403