diff --git a/docs/migration_guide.rst b/docs/migration_guide.rst index b53e554a3..37f8ee09e 100644 --- a/docs/migration_guide.rst +++ b/docs/migration_guide.rst @@ -1,6 +1,22 @@ Migration guide =============== +*************************** +0.28.0-rc.4 Migration guide +*************************** + +Version 0.28.0-rc.4 of **starknet.py** comes with partial support for RPC 0.9.0 (without the support for changes in the Websockets methods). + +.. currentmodule:: starknet_py.net.client_models + +1. Removed fields ``block_number`` and ``block_hash`` from :class:`TransactionReceipt` +2. Added a dedicated class :class:`TransactionReceiptWithBlockInfo`, a subclass of :class:`TransactionReceipt`, that has non-optional field ``block_number`` and optional field ``block_hash``. + +.. currentmodule:: starknet_py.net.client + +3. Changed return type of :meth:`Client.get_transaction_receipt` to :class:`~starknet_py.net.client_models.TransactionReceiptWithBlockInfo`. +4. Changed return type of :meth:`Client.wait_for_tx` to :class:`~starknet_py.net.client_models.TransactionReceiptWithBlockInfo`. + *************************** 0.28.0-rc.3 Migration guide *************************** diff --git a/starknet_py/net/client.py b/starknet_py/net/client.py index 58d2372a5..446cc0852 100644 --- a/starknet_py/net/client.py +++ b/starknet_py/net/client.py @@ -30,7 +30,7 @@ Tag, Transaction, TransactionExecutionStatus, - TransactionReceipt, + TransactionReceiptWithBlockInfo, TransactionStatus, TransactionStatusResponse, ) @@ -190,7 +190,7 @@ async def get_transaction( async def get_transaction_receipt( self, tx_hash: Hash, - ) -> TransactionReceipt: + ) -> TransactionReceiptWithBlockInfo: """ Get the transaction receipt @@ -214,7 +214,7 @@ async def wait_for_tx( tx_hash: Hash, check_interval: float = 2, retries: int = 500, - ) -> TransactionReceipt: + ) -> TransactionReceiptWithBlockInfo: # pylint: disable=too-many-branches """ Awaits the transaction until its status is either ``ACCEPTED_ON_L2`` or ``ACCEPTED_ON_L1`` diff --git a/starknet_py/net/client_models.py b/starknet_py/net/client_models.py index fcbecfe29..c05f35b0b 100644 --- a/starknet_py/net/client_models.py +++ b/starknet_py/net/client_models.py @@ -461,15 +461,22 @@ class TransactionReceipt: events: List[Event] = field(default_factory=list) messages_sent: List[L2toL1Message] = field(default_factory=list) - block_number: Optional[int] = None - block_hash: Optional[int] = None - contract_address: Optional[int] = None # DEPLOY_ACCOUNT_TXN_RECEIPT only message_hash: Optional[int] = None # L1_HANDLER_TXN_RECEIPT only revert_reason: Optional[str] = None +@dataclass +class TransactionReceiptWithBlockInfo(TransactionReceipt): + """ + Dataclass representing details of sent transaction with additional block info. + """ + + block_number: int = 0 + block_hash: Optional[int] = None + + @dataclass class TransactionWithReceipt: transaction: Transaction diff --git a/starknet_py/net/full_node_client.py b/starknet_py/net/full_node_client.py index 0ac0756ee..77a70bfa3 100644 --- a/starknet_py/net/full_node_client.py +++ b/starknet_py/net/full_node_client.py @@ -36,7 +36,7 @@ SyncStatus, Tag, Transaction, - TransactionReceipt, + TransactionReceiptWithBlockInfo, TransactionStatusResponse, TransactionTrace, ) @@ -88,7 +88,7 @@ DeployAccountTransactionResponseSchema, MessageStatusSchema, SentTransactionSchema, - TransactionReceiptSchema, + TransactionReceiptWithBlockInfoSchema, TransactionStatusResponseSchema, TypesOfTransactionsSchema, ) @@ -425,13 +425,18 @@ async def get_l1_message_hash(self, tx_hash: Hash) -> Hash: encoded_message = encode_l1_message(tx) return keccak256(encoded_message) - async def get_transaction_receipt(self, tx_hash: Hash) -> TransactionReceipt: + async def get_transaction_receipt( + self, tx_hash: Hash + ) -> TransactionReceiptWithBlockInfo: res = await self._client.call( method_name="getTransactionReceipt", params={"transaction_hash": _to_rpc_felt(tx_hash)}, ) - return cast(TransactionReceipt, TransactionReceiptSchema().load(res)) + return cast( + TransactionReceiptWithBlockInfo, + TransactionReceiptWithBlockInfoSchema().load(res), + ) async def estimate_fee( self, diff --git a/starknet_py/net/schemas/rpc/transactions.py b/starknet_py/net/schemas/rpc/transactions.py index f284738a4..9ec161cf8 100644 --- a/starknet_py/net/schemas/rpc/transactions.py +++ b/starknet_py/net/schemas/rpc/transactions.py @@ -23,6 +23,7 @@ ResourceBoundsMapping, SentTransactionResponse, TransactionReceipt, + TransactionReceiptWithBlockInfo, TransactionStatusResponse, TransactionWithReceipt, ) @@ -68,8 +69,6 @@ class TransactionReceiptSchema(Schema): transaction_hash = Felt(data_key="transaction_hash", required=True) execution_status = ExecutionStatusField(data_key="execution_status", required=True) finality_status = FinalityStatusField(data_key="finality_status", required=True) - block_number = fields.Integer(data_key="block_number", load_default=None) - block_hash = Felt(data_key="block_hash", load_default=None) actual_fee = fields.Nested(FeePaymentSchema(), data_key="actual_fee", required=True) type = TransactionTypeField(data_key="type", required=True) contract_address = Felt(data_key="contract_address", load_default=None) @@ -90,6 +89,15 @@ def make_dataclass(self, data, **kwargs) -> TransactionReceipt: return TransactionReceipt(**data) +class TransactionReceiptWithBlockInfoSchema(TransactionReceiptSchema): + block_hash = Felt(data_key="block_hash", load_default=None) + block_number = fields.Integer(data_key="block_number", required=True) + + @post_load + def make_dataclass(self, data, **kwargs) -> TransactionReceiptWithBlockInfo: + return TransactionReceiptWithBlockInfo(**data) + + class TransactionStatusResponseSchema(Schema): finality_status = StatusField(data_key="finality_status", required=True) execution_status = ExecutionStatusField( diff --git a/starknet_py/tests/e2e/client/client_test.py b/starknet_py/tests/e2e/client/client_test.py index efc7b9936..2e4e13b58 100644 --- a/starknet_py/tests/e2e/client/client_test.py +++ b/starknet_py/tests/e2e/client/client_test.py @@ -30,7 +30,7 @@ StorageProofResponse, TransactionExecutionStatus, TransactionFinalityStatus, - TransactionReceipt, + TransactionReceiptWithBlockInfo, TransactionStatus, TransactionStatusResponse, TransactionType, @@ -471,7 +471,7 @@ async def test_wait_for_tx_accepted(client, get_tx_receipt_path, get_tx_status_p get_tx_receipt_path, AsyncMock(), ) as mocked_receipt, patch(get_tx_status_path, AsyncMock()) as mocked_status: - mocked_receipt.return_value = TransactionReceipt( + mocked_receipt.return_value = TransactionReceiptWithBlockInfo( transaction_hash=0x1, block_number=1, type=TransactionType.INVOKE, @@ -514,7 +514,7 @@ async def test_wait_for_tx_reverted(client, get_tx_receipt_path, get_tx_status_p get_tx_receipt_path, AsyncMock(), ) as mocked_receipt, patch(get_tx_status_path, AsyncMock()) as mocked_status: - mocked_receipt.return_value = TransactionReceipt( + mocked_receipt.return_value = TransactionReceiptWithBlockInfo( transaction_hash=0x1, block_number=1, type=TransactionType.INVOKE,