|
1 | | -from typing import Dict, List, Optional, Tuple, Union, cast |
| 1 | +from typing import List, Optional, Tuple, Union, cast |
2 | 2 |
|
3 | 3 | import aiohttp |
4 | 4 | from marshmallow import EXCLUDE |
|
34 | 34 | TransactionReceipt, |
35 | 35 | TransactionStatusResponse, |
36 | 36 | TransactionTrace, |
37 | | - TransactionType, |
38 | 37 | ) |
39 | 38 | from starknet_py.net.client_utils import ( |
| 39 | + _create_broadcasted_txn, |
40 | 40 | _is_valid_eth_address, |
41 | 41 | _to_rpc_felt, |
42 | 42 | _to_storage_key, |
|
46 | 46 | from starknet_py.net.models.transaction import ( |
47 | 47 | AccountTransaction, |
48 | 48 | Declare, |
49 | | - DeclareV1Schema, |
50 | | - DeclareV2, |
51 | | - DeclareV2Schema, |
52 | | - DeclareV3, |
53 | 49 | DeployAccount, |
54 | | - DeployAccountV3, |
55 | 50 | Invoke, |
56 | | - InvokeV3, |
57 | 51 | ) |
58 | | -from starknet_py.net.schemas.gateway import SierraCompiledContractSchema |
59 | 52 | from starknet_py.net.schemas.rpc import ( |
60 | 53 | BlockHashAndNumberSchema, |
61 | 54 | BlockStateUpdateSchema, |
|
77 | 70 | TransactionReceiptSchema, |
78 | 71 | TransactionStatusResponseSchema, |
79 | 72 | TransactionTraceSchema, |
80 | | - TransactionV3Schema, |
81 | 73 | TypesOfTransactionsSchema, |
82 | 74 | ) |
83 | | -from starknet_py.net.schemas.utils import _extract_tx_version |
84 | 75 | from starknet_py.transaction_errors import TransactionNotReceivedError |
85 | 76 | from starknet_py.utils.sync import add_sync_methods |
86 | 77 |
|
@@ -810,152 +801,3 @@ def _get_raw_block_identifier( |
810 | 801 | return {"block_number": block_number} |
811 | 802 |
|
812 | 803 | return "pending" |
813 | | - |
814 | | - |
815 | | -def _create_broadcasted_txn(transaction: AccountTransaction) -> dict: |
816 | | - txn_map = { |
817 | | - TransactionType.DECLARE: _create_broadcasted_declare_properties, |
818 | | - TransactionType.INVOKE: _create_broadcasted_invoke_properties, |
819 | | - TransactionType.DEPLOY_ACCOUNT: _create_broadcasted_deploy_account_properties, |
820 | | - } |
821 | | - |
822 | | - common_properties = _create_broadcasted_txn_common_properties(transaction) |
823 | | - transaction_specific_properties = txn_map[transaction.type](transaction) |
824 | | - |
825 | | - return { |
826 | | - **common_properties, |
827 | | - **transaction_specific_properties, |
828 | | - } |
829 | | - |
830 | | - |
831 | | -def _create_broadcasted_declare_properties( |
832 | | - transaction: Union[Declare, DeclareV2, DeclareV3] |
833 | | -) -> dict: |
834 | | - if isinstance(transaction, DeclareV2): |
835 | | - return _create_broadcasted_declare_v2_properties(transaction) |
836 | | - if isinstance(transaction, DeclareV3): |
837 | | - return _create_broadcasted_declare_v3_properties(transaction) |
838 | | - |
839 | | - contract_class = cast(Dict, DeclareV1Schema().dump(obj=transaction))[ |
840 | | - "contract_class" |
841 | | - ] |
842 | | - declare_properties = { |
843 | | - "contract_class": { |
844 | | - "entry_points_by_type": contract_class["entry_points_by_type"], |
845 | | - "program": contract_class["program"], |
846 | | - }, |
847 | | - "sender_address": _to_rpc_felt(transaction.sender_address), |
848 | | - } |
849 | | - if contract_class["abi"] is not None: |
850 | | - declare_properties["contract_class"]["abi"] = contract_class["abi"] |
851 | | - |
852 | | - return declare_properties |
853 | | - |
854 | | - |
855 | | -def _create_broadcasted_declare_v2_properties(transaction: DeclareV2) -> dict: |
856 | | - contract_class = cast(Dict, DeclareV2Schema().dump(obj=transaction))[ |
857 | | - "contract_class" |
858 | | - ] |
859 | | - declare_v2_properties = { |
860 | | - "contract_class": { |
861 | | - "entry_points_by_type": contract_class["entry_points_by_type"], |
862 | | - "sierra_program": contract_class["sierra_program"], |
863 | | - "contract_class_version": contract_class["contract_class_version"], |
864 | | - }, |
865 | | - "sender_address": _to_rpc_felt(transaction.sender_address), |
866 | | - "compiled_class_hash": _to_rpc_felt(transaction.compiled_class_hash), |
867 | | - } |
868 | | - if contract_class["abi"] is not None: |
869 | | - declare_v2_properties["contract_class"]["abi"] = contract_class["abi"] |
870 | | - |
871 | | - return declare_v2_properties |
872 | | - |
873 | | - |
874 | | -def _create_broadcasted_declare_v3_properties(transaction: DeclareV3) -> dict: |
875 | | - contract_class = cast( |
876 | | - Dict, SierraCompiledContractSchema().dump(obj=transaction.contract_class) |
877 | | - ) |
878 | | - |
879 | | - declare_v3_properties = { |
880 | | - "contract_class": { |
881 | | - "entry_points_by_type": contract_class["entry_points_by_type"], |
882 | | - "sierra_program": contract_class["sierra_program"], |
883 | | - "contract_class_version": contract_class["contract_class_version"], |
884 | | - }, |
885 | | - "sender_address": _to_rpc_felt(transaction.sender_address), |
886 | | - "compiled_class_hash": _to_rpc_felt(transaction.compiled_class_hash), |
887 | | - "account_deployment_data": [ |
888 | | - _to_rpc_felt(data) for data in transaction.account_deployment_data |
889 | | - ], |
890 | | - } |
891 | | - |
892 | | - if contract_class["abi"] is not None: |
893 | | - declare_v3_properties["contract_class"]["abi"] = contract_class["abi"] |
894 | | - |
895 | | - return { |
896 | | - **_create_broadcasted_txn_v3_common_properties(transaction), |
897 | | - **declare_v3_properties, |
898 | | - } |
899 | | - |
900 | | - |
901 | | -def _create_broadcasted_invoke_properties(transaction: Union[Invoke, InvokeV3]) -> dict: |
902 | | - invoke_properties = { |
903 | | - "sender_address": _to_rpc_felt(transaction.sender_address), |
904 | | - "calldata": [_to_rpc_felt(data) for data in transaction.calldata], |
905 | | - } |
906 | | - |
907 | | - if isinstance(transaction, InvokeV3): |
908 | | - return { |
909 | | - **_create_broadcasted_txn_v3_common_properties(transaction), |
910 | | - **invoke_properties, |
911 | | - "account_deployment_data": [ |
912 | | - _to_rpc_felt(data) for data in transaction.account_deployment_data |
913 | | - ], |
914 | | - } |
915 | | - |
916 | | - return invoke_properties |
917 | | - |
918 | | - |
919 | | -def _create_broadcasted_deploy_account_properties( |
920 | | - transaction: Union[DeployAccount, DeployAccountV3] |
921 | | -) -> dict: |
922 | | - deploy_account_txn_properties = { |
923 | | - "contract_address_salt": _to_rpc_felt(transaction.contract_address_salt), |
924 | | - "constructor_calldata": [ |
925 | | - _to_rpc_felt(data) for data in transaction.constructor_calldata |
926 | | - ], |
927 | | - "class_hash": _to_rpc_felt(transaction.class_hash), |
928 | | - } |
929 | | - |
930 | | - if isinstance(transaction, DeployAccountV3): |
931 | | - return { |
932 | | - **_create_broadcasted_txn_v3_common_properties(transaction), |
933 | | - **deploy_account_txn_properties, |
934 | | - } |
935 | | - |
936 | | - return deploy_account_txn_properties |
937 | | - |
938 | | - |
939 | | -def _create_broadcasted_txn_common_properties(transaction: AccountTransaction) -> dict: |
940 | | - broadcasted_txn_common_properties = { |
941 | | - "type": transaction.type.name, |
942 | | - "version": _to_rpc_felt(transaction.version), |
943 | | - "signature": [_to_rpc_felt(sig) for sig in transaction.signature], |
944 | | - "nonce": _to_rpc_felt(transaction.nonce), |
945 | | - } |
946 | | - |
947 | | - if _extract_tx_version(transaction.version) < 3 and hasattr(transaction, "max_fee"): |
948 | | - broadcasted_txn_common_properties["max_fee"] = _to_rpc_felt( |
949 | | - transaction.max_fee # pyright: ignore |
950 | | - ) |
951 | | - |
952 | | - return broadcasted_txn_common_properties |
953 | | - |
954 | | - |
955 | | -def _create_broadcasted_txn_v3_common_properties( |
956 | | - transaction: Union[DeclareV3, InvokeV3, DeployAccountV3] |
957 | | -) -> dict: |
958 | | - return cast( |
959 | | - Dict, |
960 | | - TransactionV3Schema(exclude=["version", "signature"]).dump(obj=transaction), |
961 | | - ) |
0 commit comments