|
1 | 1 | import base64 |
2 | 2 | import json |
3 | 3 | import re |
4 | | -from collections.abc import Callable, Iterable, Sequence |
| 4 | +from collections.abc import Callable, Sequence |
5 | 5 | from dataclasses import dataclass, replace |
6 | 6 | from typing import Any, TypeAlias, TypedDict, cast |
7 | 7 |
|
|
10 | 10 | from algokit_algod_client import models as algod_models |
11 | 11 | from algokit_algod_client.exceptions import UnexpectedStatusError |
12 | 12 | from algokit_algod_client.models import SimulateTransactionResult |
13 | | -from algokit_common.constants import MAX_TRANSACTION_GROUP_SIZE, SIGNATURE_BYTE_LENGTH |
| 13 | +from algokit_common.constants import MAX_TRANSACTION_GROUP_SIZE |
14 | 14 | from algokit_transact import decode_signed_transaction, encode_signed_transactions, make_empty_transaction_signer |
15 | 15 | from algokit_transact.models.signed_transaction import SignedTransaction |
16 | 16 | from algokit_transact.models.transaction import Transaction, TransactionType |
17 | 17 | from algokit_transact.ops.fees import calculate_fee |
18 | 18 | from algokit_transact.ops.group import group_transactions |
19 | 19 | from algokit_transact.ops.ids import get_transaction_id |
20 | | -from algokit_transact.ops.validate import validate_transaction |
| 20 | +from algokit_transact.ops.validate import validate_signed_transaction, validate_transaction |
21 | 21 | from algokit_transact.signer import AddressWithTransactionSigner, TransactionSigner |
22 | 22 | from algokit_utils.applications.abi import ABIReturn |
23 | 23 | from algokit_utils.applications.app_manager import AppManager |
@@ -293,6 +293,7 @@ def register_error_transformer(self, transformer: ErrorTransformer) -> "Transact |
293 | 293 | return self |
294 | 294 |
|
295 | 295 | def add_transaction(self, txn: Transaction, signer: TransactionSigner | None = None) -> "TransactionComposer": |
| 296 | + validate_transaction(txn) |
296 | 297 | self._ensure_not_built() |
297 | 298 | self._queued.append(_QueuedTransaction(txn=self._sanitize_transaction(txn), signer=signer)) |
298 | 299 | return self |
@@ -501,7 +502,6 @@ def send(self, params: SendParams | None = None) -> SendTransactionComposerResul |
501 | 502 |
|
502 | 503 | # Send transactions and handle network errors |
503 | 504 | try: |
504 | | - _validate_signed_transactions(signed_transactions) |
505 | 505 | blobs = encode_signed_transactions(signed_transactions) |
506 | 506 | self._algod.send_raw_transaction(blobs) |
507 | 507 |
|
@@ -1370,7 +1370,9 @@ def _sign_transactions(self, txns_with_signers: Sequence[TransactionWithSigner]) |
1370 | 1370 | for key, (_, indexes) in signer_groups.items(): |
1371 | 1371 | blobs = signed_blobs[key] |
1372 | 1372 | for blob_index, txn_index in enumerate(indexes): |
1373 | | - ordered[txn_index] = decode_signed_transaction(blobs[blob_index]) |
| 1373 | + signed_txn = decode_signed_transaction(blobs[blob_index]) |
| 1374 | + validate_signed_transaction(signed_txn) |
| 1375 | + ordered[txn_index] = signed_txn |
1374 | 1376 |
|
1375 | 1377 | if any(item is None for item in ordered): |
1376 | 1378 | raise ValueError("One or more transactions were not signed") |
@@ -1557,24 +1559,6 @@ def _extract_algod_error_message(payload: object) -> str | None: # noqa: PLR091 |
1557 | 1559 | return text |
1558 | 1560 |
|
1559 | 1561 |
|
1560 | | -def _validate_signed_transactions(stxns: Iterable[SignedTransaction]) -> None: |
1561 | | - for stxn in stxns: |
1562 | | - _validate_signed_transaction(stxn) |
1563 | | - |
1564 | | - |
1565 | | -def _validate_signed_transaction(stx: SignedTransaction) -> None: |
1566 | | - validate_transaction(stx.txn) |
1567 | | - |
1568 | | - signatures = {stx.sig, stx.msig, stx.lsig} - {None} |
1569 | | - if not signatures: |
1570 | | - raise ValueError("At least one signature type must be set") |
1571 | | - if len(signatures) > 1: |
1572 | | - raise ValueError("Only one signature type can be set") |
1573 | | - |
1574 | | - if stx.sig is not None and len(stx.sig) != SIGNATURE_BYTE_LENGTH: |
1575 | | - raise ValueError("Signature must be 64 bytes") |
1576 | | - |
1577 | | - |
1578 | 1562 | def _wait_for_confirmation( |
1579 | 1563 | algod: AlgodClient, |
1580 | 1564 | tx_id: str, |
|
0 commit comments