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
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
from algokit_transact.models.asset_config import AssetConfigTransactionFields
|
|
2
|
+
from algokit_transact.models.asset_freeze import AssetFreezeTransactionFields
|
|
3
|
+
from algokit_transact.models.asset_transfer import AssetTransferTransactionFields
|
|
4
|
+
from algokit_transact.models.transaction import TransactionType
|
|
5
|
+
from algokit_utils.transactions.builders.common import (
|
|
6
|
+
BuiltTransaction,
|
|
7
|
+
SuggestedParamsLike,
|
|
8
|
+
apply_transaction_fees,
|
|
9
|
+
build_transaction,
|
|
10
|
+
build_transaction_header,
|
|
11
|
+
)
|
|
12
|
+
from algokit_utils.transactions.types import (
|
|
13
|
+
AssetConfigParams,
|
|
14
|
+
AssetCreateParams,
|
|
15
|
+
AssetDestroyParams,
|
|
16
|
+
AssetFreezeParams,
|
|
17
|
+
AssetOptInParams,
|
|
18
|
+
AssetOptOutParams,
|
|
19
|
+
AssetTransferParams,
|
|
20
|
+
CommonTxnParams,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
AssetFieldPayload = AssetConfigTransactionFields | AssetFreezeTransactionFields | AssetTransferTransactionFields
|
|
24
|
+
|
|
25
|
+
__all__ = [
|
|
26
|
+
"build_asset_config_transaction",
|
|
27
|
+
"build_asset_create_transaction",
|
|
28
|
+
"build_asset_destroy_transaction",
|
|
29
|
+
"build_asset_freeze_transaction",
|
|
30
|
+
"build_asset_opt_in_transaction",
|
|
31
|
+
"build_asset_opt_out_transaction",
|
|
32
|
+
"build_asset_transfer_transaction",
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _build_transaction(
|
|
37
|
+
params: CommonTxnParams,
|
|
38
|
+
suggested_params: SuggestedParamsLike,
|
|
39
|
+
*,
|
|
40
|
+
txn_type: TransactionType,
|
|
41
|
+
field_payload: AssetFieldPayload,
|
|
42
|
+
default_validity_window: int,
|
|
43
|
+
default_validity_window_is_explicit: bool,
|
|
44
|
+
is_localnet: bool,
|
|
45
|
+
) -> BuiltTransaction:
|
|
46
|
+
header, fee_config = build_transaction_header(
|
|
47
|
+
params,
|
|
48
|
+
suggested_params,
|
|
49
|
+
default_validity_window=default_validity_window,
|
|
50
|
+
default_validity_window_is_explicit=default_validity_window_is_explicit,
|
|
51
|
+
is_localnet=is_localnet,
|
|
52
|
+
)
|
|
53
|
+
txn = build_transaction(
|
|
54
|
+
txn_type,
|
|
55
|
+
header,
|
|
56
|
+
asset_config=field_payload if isinstance(field_payload, AssetConfigTransactionFields) else None,
|
|
57
|
+
asset_transfer=field_payload if isinstance(field_payload, AssetTransferTransactionFields) else None,
|
|
58
|
+
asset_freeze=field_payload if isinstance(field_payload, AssetFreezeTransactionFields) else None,
|
|
59
|
+
)
|
|
60
|
+
return apply_transaction_fees(txn, params, fee_config)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def build_asset_create_transaction(
|
|
64
|
+
params: AssetCreateParams,
|
|
65
|
+
suggested_params: SuggestedParamsLike,
|
|
66
|
+
*,
|
|
67
|
+
default_validity_window: int,
|
|
68
|
+
default_validity_window_is_explicit: bool,
|
|
69
|
+
is_localnet: bool,
|
|
70
|
+
) -> BuiltTransaction:
|
|
71
|
+
fields = AssetConfigTransactionFields(
|
|
72
|
+
asset_id=0,
|
|
73
|
+
total=params.total,
|
|
74
|
+
decimals=params.decimals,
|
|
75
|
+
default_frozen=params.default_frozen,
|
|
76
|
+
unit_name=params.unit_name,
|
|
77
|
+
asset_name=params.asset_name,
|
|
78
|
+
url=params.url,
|
|
79
|
+
metadata_hash=params.metadata_hash,
|
|
80
|
+
manager=params.manager,
|
|
81
|
+
reserve=params.reserve,
|
|
82
|
+
freeze=params.freeze,
|
|
83
|
+
clawback=params.clawback,
|
|
84
|
+
)
|
|
85
|
+
return _build_transaction(
|
|
86
|
+
params,
|
|
87
|
+
suggested_params,
|
|
88
|
+
txn_type=TransactionType.AssetConfig,
|
|
89
|
+
field_payload=fields,
|
|
90
|
+
default_validity_window=default_validity_window,
|
|
91
|
+
default_validity_window_is_explicit=default_validity_window_is_explicit,
|
|
92
|
+
is_localnet=is_localnet,
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def build_asset_config_transaction(
|
|
97
|
+
params: AssetConfigParams,
|
|
98
|
+
suggested_params: SuggestedParamsLike,
|
|
99
|
+
*,
|
|
100
|
+
default_validity_window: int,
|
|
101
|
+
default_validity_window_is_explicit: bool,
|
|
102
|
+
is_localnet: bool,
|
|
103
|
+
) -> BuiltTransaction:
|
|
104
|
+
fields = AssetConfigTransactionFields(
|
|
105
|
+
asset_id=params.asset_id,
|
|
106
|
+
manager=params.manager,
|
|
107
|
+
reserve=params.reserve,
|
|
108
|
+
freeze=params.freeze,
|
|
109
|
+
clawback=params.clawback,
|
|
110
|
+
)
|
|
111
|
+
return _build_transaction(
|
|
112
|
+
params,
|
|
113
|
+
suggested_params,
|
|
114
|
+
txn_type=TransactionType.AssetConfig,
|
|
115
|
+
field_payload=fields,
|
|
116
|
+
default_validity_window=default_validity_window,
|
|
117
|
+
default_validity_window_is_explicit=default_validity_window_is_explicit,
|
|
118
|
+
is_localnet=is_localnet,
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def build_asset_destroy_transaction(
|
|
123
|
+
params: AssetDestroyParams,
|
|
124
|
+
suggested_params: SuggestedParamsLike,
|
|
125
|
+
*,
|
|
126
|
+
default_validity_window: int,
|
|
127
|
+
default_validity_window_is_explicit: bool,
|
|
128
|
+
is_localnet: bool,
|
|
129
|
+
) -> BuiltTransaction:
|
|
130
|
+
fields = AssetConfigTransactionFields(asset_id=params.asset_id)
|
|
131
|
+
return _build_transaction(
|
|
132
|
+
params,
|
|
133
|
+
suggested_params,
|
|
134
|
+
txn_type=TransactionType.AssetConfig,
|
|
135
|
+
field_payload=fields,
|
|
136
|
+
default_validity_window=default_validity_window,
|
|
137
|
+
default_validity_window_is_explicit=default_validity_window_is_explicit,
|
|
138
|
+
is_localnet=is_localnet,
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def build_asset_freeze_transaction(
|
|
143
|
+
params: AssetFreezeParams,
|
|
144
|
+
suggested_params: SuggestedParamsLike,
|
|
145
|
+
*,
|
|
146
|
+
default_validity_window: int,
|
|
147
|
+
default_validity_window_is_explicit: bool,
|
|
148
|
+
is_localnet: bool,
|
|
149
|
+
) -> BuiltTransaction:
|
|
150
|
+
fields = AssetFreezeTransactionFields(
|
|
151
|
+
asset_id=params.asset_id,
|
|
152
|
+
freeze_target=params.account,
|
|
153
|
+
frozen=params.frozen,
|
|
154
|
+
)
|
|
155
|
+
return _build_transaction(
|
|
156
|
+
params,
|
|
157
|
+
suggested_params,
|
|
158
|
+
txn_type=TransactionType.AssetFreeze,
|
|
159
|
+
field_payload=fields,
|
|
160
|
+
default_validity_window=default_validity_window,
|
|
161
|
+
default_validity_window_is_explicit=default_validity_window_is_explicit,
|
|
162
|
+
is_localnet=is_localnet,
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def build_asset_transfer_transaction(
|
|
167
|
+
params: AssetTransferParams,
|
|
168
|
+
suggested_params: SuggestedParamsLike,
|
|
169
|
+
*,
|
|
170
|
+
default_validity_window: int,
|
|
171
|
+
default_validity_window_is_explicit: bool,
|
|
172
|
+
is_localnet: bool,
|
|
173
|
+
) -> BuiltTransaction:
|
|
174
|
+
fields = AssetTransferTransactionFields(
|
|
175
|
+
asset_id=params.asset_id,
|
|
176
|
+
amount=params.amount,
|
|
177
|
+
receiver=params.receiver,
|
|
178
|
+
close_remainder_to=params.close_asset_to,
|
|
179
|
+
asset_sender=params.clawback_target,
|
|
180
|
+
)
|
|
181
|
+
return _build_transaction(
|
|
182
|
+
params,
|
|
183
|
+
suggested_params,
|
|
184
|
+
txn_type=TransactionType.AssetTransfer,
|
|
185
|
+
field_payload=fields,
|
|
186
|
+
default_validity_window=default_validity_window,
|
|
187
|
+
default_validity_window_is_explicit=default_validity_window_is_explicit,
|
|
188
|
+
is_localnet=is_localnet,
|
|
189
|
+
)
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
def build_asset_opt_in_transaction(
|
|
193
|
+
params: AssetOptInParams,
|
|
194
|
+
suggested_params: SuggestedParamsLike,
|
|
195
|
+
*,
|
|
196
|
+
default_validity_window: int,
|
|
197
|
+
default_validity_window_is_explicit: bool,
|
|
198
|
+
is_localnet: bool,
|
|
199
|
+
) -> BuiltTransaction:
|
|
200
|
+
transfer_params = AssetTransferParams(
|
|
201
|
+
sender=params.sender,
|
|
202
|
+
signer=params.signer,
|
|
203
|
+
rekey_to=params.rekey_to,
|
|
204
|
+
note=params.note,
|
|
205
|
+
lease=params.lease,
|
|
206
|
+
static_fee=params.static_fee,
|
|
207
|
+
extra_fee=params.extra_fee,
|
|
208
|
+
max_fee=params.max_fee,
|
|
209
|
+
validity_window=params.validity_window,
|
|
210
|
+
first_valid_round=params.first_valid_round,
|
|
211
|
+
last_valid_round=params.last_valid_round,
|
|
212
|
+
asset_id=params.asset_id,
|
|
213
|
+
amount=0,
|
|
214
|
+
receiver=params.sender,
|
|
215
|
+
)
|
|
216
|
+
return build_asset_transfer_transaction(
|
|
217
|
+
transfer_params,
|
|
218
|
+
suggested_params,
|
|
219
|
+
default_validity_window=default_validity_window,
|
|
220
|
+
default_validity_window_is_explicit=default_validity_window_is_explicit,
|
|
221
|
+
is_localnet=is_localnet,
|
|
222
|
+
)
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
def build_asset_opt_out_transaction(
|
|
226
|
+
params: AssetOptOutParams,
|
|
227
|
+
suggested_params: SuggestedParamsLike,
|
|
228
|
+
*,
|
|
229
|
+
default_validity_window: int,
|
|
230
|
+
default_validity_window_is_explicit: bool,
|
|
231
|
+
is_localnet: bool,
|
|
232
|
+
) -> BuiltTransaction:
|
|
233
|
+
transfer_params = AssetTransferParams(
|
|
234
|
+
sender=params.sender,
|
|
235
|
+
signer=params.signer,
|
|
236
|
+
rekey_to=params.rekey_to,
|
|
237
|
+
note=params.note,
|
|
238
|
+
lease=params.lease,
|
|
239
|
+
static_fee=params.static_fee,
|
|
240
|
+
extra_fee=params.extra_fee,
|
|
241
|
+
max_fee=params.max_fee,
|
|
242
|
+
validity_window=params.validity_window,
|
|
243
|
+
first_valid_round=params.first_valid_round,
|
|
244
|
+
last_valid_round=params.last_valid_round,
|
|
245
|
+
asset_id=params.asset_id,
|
|
246
|
+
amount=0,
|
|
247
|
+
receiver=params.sender,
|
|
248
|
+
close_asset_to=params.creator,
|
|
249
|
+
)
|
|
250
|
+
return build_asset_transfer_transaction(
|
|
251
|
+
transfer_params,
|
|
252
|
+
suggested_params,
|
|
253
|
+
default_validity_window=default_validity_window,
|
|
254
|
+
default_validity_window_is_explicit=default_validity_window_is_explicit,
|
|
255
|
+
is_localnet=is_localnet,
|
|
256
|
+
)
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import base64
|
|
2
|
+
from dataclasses import dataclass, replace
|
|
3
|
+
from typing import Protocol, runtime_checkable
|
|
4
|
+
|
|
5
|
+
from algokit_algod_client import models as algod_models
|
|
6
|
+
from algokit_transact.models.app_call import AppCallTransactionFields
|
|
7
|
+
from algokit_transact.models.asset_config import AssetConfigTransactionFields
|
|
8
|
+
from algokit_transact.models.asset_freeze import AssetFreezeTransactionFields
|
|
9
|
+
from algokit_transact.models.asset_transfer import AssetTransferTransactionFields
|
|
10
|
+
from algokit_transact.models.key_registration import KeyRegistrationTransactionFields
|
|
11
|
+
from algokit_transact.models.payment import PaymentTransactionFields
|
|
12
|
+
from algokit_transact.models.transaction import Transaction, TransactionType
|
|
13
|
+
from algokit_transact.ops.fees import assign_fee
|
|
14
|
+
from algokit_utils.models.amount import AlgoAmount
|
|
15
|
+
from algokit_utils.transactions.fee_coverage import FeeDelta
|
|
16
|
+
from algokit_utils.transactions.types import CommonTxnParams
|
|
17
|
+
|
|
18
|
+
LEASE_MIN_LENGTH = 1
|
|
19
|
+
LEASE_MAX_LENGTH = 32
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@runtime_checkable
|
|
23
|
+
class AlgoSuggestedParams(Protocol):
|
|
24
|
+
fee: int
|
|
25
|
+
first: int
|
|
26
|
+
last: int
|
|
27
|
+
gen: str
|
|
28
|
+
gh: str
|
|
29
|
+
flat_fee: bool
|
|
30
|
+
consensus_version: str
|
|
31
|
+
min_fee: int
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
SuggestedParamsLike = AlgoSuggestedParams | algod_models.SuggestedParams
|
|
35
|
+
|
|
36
|
+
__all__ = [
|
|
37
|
+
"BuiltTransaction",
|
|
38
|
+
"FeeConfig",
|
|
39
|
+
"SuggestedParamsLike",
|
|
40
|
+
"TransactionHeader",
|
|
41
|
+
"apply_transaction_fees",
|
|
42
|
+
"build_transaction",
|
|
43
|
+
"build_transaction_header",
|
|
44
|
+
"calculate_inner_fee_delta",
|
|
45
|
+
"encode_lease",
|
|
46
|
+
]
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
@dataclass(slots=True)
|
|
50
|
+
class TransactionHeader:
|
|
51
|
+
sender: str
|
|
52
|
+
first_valid: int
|
|
53
|
+
last_valid: int
|
|
54
|
+
genesis_hash: bytes
|
|
55
|
+
genesis_id: str | None
|
|
56
|
+
note: bytes | None
|
|
57
|
+
lease: bytes | None
|
|
58
|
+
rekey_to: str | None
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
@dataclass(slots=True)
|
|
62
|
+
class FeeConfig:
|
|
63
|
+
fee_per_byte: int
|
|
64
|
+
min_fee: int
|
|
65
|
+
flat_fee: bool
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
@dataclass(slots=True)
|
|
69
|
+
class BuiltTransaction:
|
|
70
|
+
txn: Transaction
|
|
71
|
+
logical_max_fee: AlgoAmount | None
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def build_transaction_header(
|
|
75
|
+
params: CommonTxnParams,
|
|
76
|
+
suggested_params: SuggestedParamsLike,
|
|
77
|
+
*,
|
|
78
|
+
default_validity_window: int,
|
|
79
|
+
default_validity_window_is_explicit: bool,
|
|
80
|
+
is_localnet: bool,
|
|
81
|
+
) -> tuple[TransactionHeader, FeeConfig]:
|
|
82
|
+
normalized = _normalize_suggested_params(suggested_params)
|
|
83
|
+
first_valid = params.first_valid_round or normalized.first_valid
|
|
84
|
+
|
|
85
|
+
if params.last_valid_round:
|
|
86
|
+
last_valid = params.last_valid_round
|
|
87
|
+
else:
|
|
88
|
+
window = params.validity_window
|
|
89
|
+
if window is None:
|
|
90
|
+
window = 1000 if is_localnet and not default_validity_window_is_explicit else default_validity_window
|
|
91
|
+
last_valid = first_valid + window
|
|
92
|
+
|
|
93
|
+
header = TransactionHeader(
|
|
94
|
+
sender=params.sender,
|
|
95
|
+
first_valid=first_valid,
|
|
96
|
+
last_valid=last_valid,
|
|
97
|
+
genesis_hash=normalized.genesis_hash,
|
|
98
|
+
genesis_id=normalized.genesis_id,
|
|
99
|
+
note=params.note,
|
|
100
|
+
lease=encode_lease(params.lease),
|
|
101
|
+
rekey_to=params.rekey_to,
|
|
102
|
+
)
|
|
103
|
+
fee_config = FeeConfig(
|
|
104
|
+
fee_per_byte=normalized.fee,
|
|
105
|
+
min_fee=normalized.min_fee,
|
|
106
|
+
flat_fee=normalized.flat_fee,
|
|
107
|
+
)
|
|
108
|
+
return header, fee_config
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def build_transaction(
|
|
112
|
+
txn_type: TransactionType,
|
|
113
|
+
header: TransactionHeader,
|
|
114
|
+
*,
|
|
115
|
+
payment: PaymentTransactionFields | None = None,
|
|
116
|
+
asset_transfer: AssetTransferTransactionFields | None = None,
|
|
117
|
+
asset_config: AssetConfigTransactionFields | None = None,
|
|
118
|
+
asset_freeze: AssetFreezeTransactionFields | None = None,
|
|
119
|
+
application_call: AppCallTransactionFields | None = None,
|
|
120
|
+
key_registration: KeyRegistrationTransactionFields | None = None,
|
|
121
|
+
) -> Transaction:
|
|
122
|
+
return Transaction(
|
|
123
|
+
transaction_type=txn_type,
|
|
124
|
+
sender=header.sender,
|
|
125
|
+
first_valid=header.first_valid,
|
|
126
|
+
last_valid=header.last_valid,
|
|
127
|
+
genesis_hash=header.genesis_hash,
|
|
128
|
+
genesis_id=header.genesis_id,
|
|
129
|
+
note=header.note,
|
|
130
|
+
rekey_to=header.rekey_to,
|
|
131
|
+
lease=header.lease,
|
|
132
|
+
payment=payment,
|
|
133
|
+
asset_transfer=asset_transfer,
|
|
134
|
+
asset_config=asset_config,
|
|
135
|
+
asset_freeze=asset_freeze,
|
|
136
|
+
application_call=application_call,
|
|
137
|
+
key_registration=key_registration,
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def apply_transaction_fees(
|
|
142
|
+
txn: Transaction,
|
|
143
|
+
params: CommonTxnParams,
|
|
144
|
+
fee_config: FeeConfig,
|
|
145
|
+
) -> BuiltTransaction:
|
|
146
|
+
extra_fee = params.extra_fee.micro_algo if params.extra_fee else None
|
|
147
|
+
max_fee = params.max_fee.micro_algo if params.max_fee else None
|
|
148
|
+
|
|
149
|
+
if params.static_fee:
|
|
150
|
+
fee = params.static_fee.micro_algo
|
|
151
|
+
if extra_fee:
|
|
152
|
+
fee += extra_fee
|
|
153
|
+
if max_fee is not None and fee > max_fee:
|
|
154
|
+
raise ValueError(
|
|
155
|
+
f"Transaction fee {fee} µALGO is greater than max fee {max_fee} µALGO",
|
|
156
|
+
)
|
|
157
|
+
txn_with_fee = replace(txn, fee=fee)
|
|
158
|
+
else:
|
|
159
|
+
txn_with_fee = assign_fee(
|
|
160
|
+
txn,
|
|
161
|
+
fee_per_byte=0 if fee_config.flat_fee else fee_config.fee_per_byte,
|
|
162
|
+
min_fee=fee_config.min_fee,
|
|
163
|
+
extra_fee=extra_fee,
|
|
164
|
+
max_fee=max_fee,
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
logical_max_fee = _logical_max_fee(params)
|
|
168
|
+
return BuiltTransaction(txn=txn_with_fee, logical_max_fee=logical_max_fee)
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def encode_lease(lease: str | bytes | None) -> bytes | None:
|
|
172
|
+
if lease is None:
|
|
173
|
+
return None
|
|
174
|
+
if isinstance(lease, bytes):
|
|
175
|
+
if not (LEASE_MIN_LENGTH <= len(lease) <= LEASE_MAX_LENGTH):
|
|
176
|
+
raise ValueError(
|
|
177
|
+
(
|
|
178
|
+
"Received invalid lease; expected something with length between "
|
|
179
|
+
f"{LEASE_MIN_LENGTH} and {LEASE_MAX_LENGTH}, but received bytes with length {len(lease)}"
|
|
180
|
+
),
|
|
181
|
+
)
|
|
182
|
+
if len(lease) == LEASE_MAX_LENGTH:
|
|
183
|
+
return lease
|
|
184
|
+
data = bytearray(LEASE_MAX_LENGTH)
|
|
185
|
+
data[: len(lease)] = lease
|
|
186
|
+
return bytes(data)
|
|
187
|
+
encoded = lease.encode("utf-8")
|
|
188
|
+
if not (LEASE_MIN_LENGTH <= len(encoded) <= LEASE_MAX_LENGTH):
|
|
189
|
+
raise ValueError(
|
|
190
|
+
(
|
|
191
|
+
"Received invalid lease; expected something with length between "
|
|
192
|
+
f"{LEASE_MIN_LENGTH} and {LEASE_MAX_LENGTH}, but received '{lease}' with length {len(lease)}"
|
|
193
|
+
),
|
|
194
|
+
)
|
|
195
|
+
data = bytearray(LEASE_MAX_LENGTH)
|
|
196
|
+
data[: len(encoded)] = encoded
|
|
197
|
+
return bytes(data)
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
@dataclass(slots=True)
|
|
201
|
+
class _NormalizedSuggestedParams:
|
|
202
|
+
first_valid: int
|
|
203
|
+
last_valid: int
|
|
204
|
+
genesis_hash: bytes
|
|
205
|
+
genesis_id: str | None
|
|
206
|
+
fee: int
|
|
207
|
+
min_fee: int
|
|
208
|
+
flat_fee: bool
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
def _normalize_suggested_params(sp: SuggestedParamsLike) -> _NormalizedSuggestedParams:
|
|
212
|
+
if isinstance(sp, AlgoSuggestedParams):
|
|
213
|
+
genesis_hash = base64.b64decode(sp.gh) if isinstance(sp.gh, str) else sp.gh
|
|
214
|
+
return _NormalizedSuggestedParams(
|
|
215
|
+
first_valid=sp.first,
|
|
216
|
+
last_valid=sp.last,
|
|
217
|
+
genesis_hash=genesis_hash,
|
|
218
|
+
genesis_id=sp.gen,
|
|
219
|
+
fee=sp.fee,
|
|
220
|
+
min_fee=sp.min_fee,
|
|
221
|
+
flat_fee=sp.flat_fee,
|
|
222
|
+
)
|
|
223
|
+
# Typed client SuggestedParams
|
|
224
|
+
genesis_hash = sp.genesis_hash if isinstance(sp.genesis_hash, bytes) else bytes(sp.genesis_hash)
|
|
225
|
+
return _NormalizedSuggestedParams(
|
|
226
|
+
first_valid=sp.first_valid,
|
|
227
|
+
last_valid=sp.last_valid,
|
|
228
|
+
genesis_hash=genesis_hash,
|
|
229
|
+
genesis_id=sp.genesis_id,
|
|
230
|
+
fee=sp.fee,
|
|
231
|
+
min_fee=sp.min_fee,
|
|
232
|
+
flat_fee=sp.flat_fee,
|
|
233
|
+
)
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
def _logical_max_fee(params: CommonTxnParams) -> AlgoAmount | None:
|
|
237
|
+
if params.max_fee and (params.static_fee is None or params.max_fee.micro_algo > params.static_fee.micro_algo):
|
|
238
|
+
return params.max_fee
|
|
239
|
+
return params.static_fee
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
def calculate_inner_fee_delta(
|
|
243
|
+
inner_txns: list[algod_models.PendingTransactionResponse] | None,
|
|
244
|
+
min_fee: int,
|
|
245
|
+
acc: FeeDelta | None = None,
|
|
246
|
+
) -> FeeDelta | None:
|
|
247
|
+
if not inner_txns:
|
|
248
|
+
return acc
|
|
249
|
+
|
|
250
|
+
current = acc
|
|
251
|
+
for inner in reversed(inner_txns):
|
|
252
|
+
recursive_delta = calculate_inner_fee_delta(inner.inner_txns, min_fee, current)
|
|
253
|
+
txn_fee = inner.txn.txn.fee or 0
|
|
254
|
+
txn_fee_delta = FeeDelta.from_int(min_fee - txn_fee)
|
|
255
|
+
combined = FeeDelta.add(recursive_delta, txn_fee_delta)
|
|
256
|
+
|
|
257
|
+
if combined and FeeDelta.is_surplus(combined):
|
|
258
|
+
current = None
|
|
259
|
+
continue
|
|
260
|
+
|
|
261
|
+
current = combined
|
|
262
|
+
|
|
263
|
+
return current
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import base64
|
|
2
|
+
|
|
3
|
+
from algokit_transact.models.key_registration import KeyRegistrationTransactionFields
|
|
4
|
+
from algokit_transact.models.transaction import TransactionType
|
|
5
|
+
from algokit_utils.transactions.builders.common import (
|
|
6
|
+
BuiltTransaction,
|
|
7
|
+
SuggestedParamsLike,
|
|
8
|
+
apply_transaction_fees,
|
|
9
|
+
build_transaction,
|
|
10
|
+
build_transaction_header,
|
|
11
|
+
)
|
|
12
|
+
from algokit_utils.transactions.types import OfflineKeyRegistrationParams, OnlineKeyRegistrationParams
|
|
13
|
+
|
|
14
|
+
__all__ = ["build_offline_key_registration_transaction", "build_online_key_registration_transaction"]
|
|
15
|
+
|
|
16
|
+
STATE_PROOF_KEY_LENGTH = 64
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def build_online_key_registration_transaction(
|
|
20
|
+
params: OnlineKeyRegistrationParams,
|
|
21
|
+
suggested_params: SuggestedParamsLike,
|
|
22
|
+
*,
|
|
23
|
+
default_validity_window: int,
|
|
24
|
+
default_validity_window_is_explicit: bool,
|
|
25
|
+
is_localnet: bool,
|
|
26
|
+
) -> BuiltTransaction:
|
|
27
|
+
header, fee_config = build_transaction_header(
|
|
28
|
+
params,
|
|
29
|
+
suggested_params,
|
|
30
|
+
default_validity_window=default_validity_window,
|
|
31
|
+
default_validity_window_is_explicit=default_validity_window_is_explicit,
|
|
32
|
+
is_localnet=is_localnet,
|
|
33
|
+
)
|
|
34
|
+
fields = KeyRegistrationTransactionFields(
|
|
35
|
+
vote_key=_decode_key(params.vote_key),
|
|
36
|
+
selection_key=_decode_key(params.selection_key),
|
|
37
|
+
vote_first=params.vote_first,
|
|
38
|
+
vote_last=params.vote_last,
|
|
39
|
+
vote_key_dilution=params.vote_key_dilution,
|
|
40
|
+
state_proof_key=_decode_state_proof_key(params.state_proof_key),
|
|
41
|
+
non_participation=params.nonparticipation,
|
|
42
|
+
)
|
|
43
|
+
txn = build_transaction(
|
|
44
|
+
TransactionType.KeyRegistration,
|
|
45
|
+
header,
|
|
46
|
+
key_registration=fields,
|
|
47
|
+
)
|
|
48
|
+
return apply_transaction_fees(txn, params, fee_config)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def build_offline_key_registration_transaction(
|
|
52
|
+
params: OfflineKeyRegistrationParams,
|
|
53
|
+
suggested_params: SuggestedParamsLike,
|
|
54
|
+
*,
|
|
55
|
+
default_validity_window: int,
|
|
56
|
+
default_validity_window_is_explicit: bool,
|
|
57
|
+
is_localnet: bool,
|
|
58
|
+
) -> BuiltTransaction:
|
|
59
|
+
header, fee_config = build_transaction_header(
|
|
60
|
+
params,
|
|
61
|
+
suggested_params,
|
|
62
|
+
default_validity_window=default_validity_window,
|
|
63
|
+
default_validity_window_is_explicit=default_validity_window_is_explicit,
|
|
64
|
+
is_localnet=is_localnet,
|
|
65
|
+
)
|
|
66
|
+
fields = KeyRegistrationTransactionFields(
|
|
67
|
+
non_participation=params.prevent_account_from_ever_participating_again,
|
|
68
|
+
)
|
|
69
|
+
txn = build_transaction(TransactionType.KeyRegistration, header, key_registration=fields)
|
|
70
|
+
return apply_transaction_fees(txn, params, fee_config)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def _decode_key(value: str | bytes | None) -> bytes | None:
|
|
74
|
+
if value is None:
|
|
75
|
+
return None
|
|
76
|
+
if isinstance(value, bytes):
|
|
77
|
+
return value
|
|
78
|
+
try:
|
|
79
|
+
return base64.b64decode(value)
|
|
80
|
+
except Exception as exc:
|
|
81
|
+
raise ValueError("Vote/selection keys must be base64-encoded strings") from exc
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def _decode_state_proof_key(value: str | bytes | None) -> bytes | None:
|
|
85
|
+
if value is None:
|
|
86
|
+
return None
|
|
87
|
+
if isinstance(value, bytes):
|
|
88
|
+
if len(value) == STATE_PROOF_KEY_LENGTH:
|
|
89
|
+
return value
|
|
90
|
+
try:
|
|
91
|
+
decoded = base64.b64decode(value)
|
|
92
|
+
except Exception as exc:
|
|
93
|
+
raise ValueError("State proof keys must be 64 bytes or base64-encoded strings") from exc
|
|
94
|
+
if len(decoded) != STATE_PROOF_KEY_LENGTH:
|
|
95
|
+
raise ValueError("State proof keys must be 64 bytes or base64-encoded strings")
|
|
96
|
+
return decoded
|
|
97
|
+
try:
|
|
98
|
+
decoded = base64.b64decode(value)
|
|
99
|
+
except Exception as exc:
|
|
100
|
+
raise ValueError("State proof keys must be base64-encoded strings") from exc
|
|
101
|
+
if len(decoded) != STATE_PROOF_KEY_LENGTH:
|
|
102
|
+
raise ValueError("State proof keys must decode to 64 bytes")
|
|
103
|
+
return decoded
|