diff --git a/backend/database_handler/transactions_processor.py b/backend/database_handler/transactions_processor.py index 85fa00362..bb3d6e877 100644 --- a/backend/database_handler/transactions_processor.py +++ b/backend/database_handler/transactions_processor.py @@ -587,7 +587,7 @@ def _process_result(self, transaction_data: dict) -> dict: return transaction_data def get_transaction_by_hash( - self, transaction_hash: str, sim_config: dict | None = None + self, transaction_hash: str, sim_config: dict | None = None, hide_fields: bool = False ) -> dict | None: transaction = ( self.session.query(Transactions) @@ -630,6 +630,23 @@ def get_transaction_by_hash( transaction_data = self._process_messages(transaction_data) transaction_data = self._process_queue(transaction_data) transaction_data = self._process_round_data(transaction_data) + + if hide_fields: + if transaction_data[ + "type" + ] == TransactionType.DEPLOY_CONTRACT.value and not ( + transaction_data["last_round"]["result"] == 6 + and "leader_receipt" in transaction_data["consensus_data"] + and transaction_data["consensus_data"]["leader_receipt"] is not None + and len(transaction_data["consensus_data"]["leader_receipt"]) > 0 + and transaction_data["consensus_data"]["leader_receipt"][0][ + "execution_result" + ] + == ExecutionResultStatus.SUCCESS.value + ): + transaction_data["data"]["contract_address"] = None + if "contract_snapshot" in transaction_data: + del transaction_data["contract_snapshot"] return transaction_data def get_studio_transaction_by_hash( diff --git a/backend/protocol_rpc/endpoints.py b/backend/protocol_rpc/endpoints.py index 735330e85..216a745ec 100644 --- a/backend/protocol_rpc/endpoints.py +++ b/backend/protocol_rpc/endpoints.py @@ -1048,7 +1048,7 @@ def get_transaction_by_hash( sim_config: dict | None = None, ) -> dict: transaction = transactions_processor.get_transaction_by_hash( - transaction_hash, sim_config + transaction_hash, sim_config, True ) if transaction is None: @@ -1427,7 +1427,7 @@ def get_transaction_receipt( event_signature = "NewTransaction(bytes32,address,address)" event_signature_hash = eth_utils.keccak(text=event_signature).hex() - to_addr = transaction.get("to_address") + to_addr = transaction.get("to_address") if transaction.get("to_address") else None from_addr = transaction.get("from_address") logs = [ @@ -1457,6 +1457,19 @@ def get_transaction_receipt( } ] + if ( + transaction["type"] == TransactionType.DEPLOY_CONTRACT.value + and transaction["last_round"]["result"] == 6 + and "leader_receipt" in transaction["consensus_data"] + and transaction["consensus_data"]["leader_receipt"] is not None + and len(transaction["consensus_data"]["leader_receipt"]) > 0 + and transaction["consensus_data"]["leader_receipt"][0]["execution_result"] + == ExecutionResultStatus.SUCCESS.value + ): + contract_address = transaction["to_address"] + else: + contract_address = None + receipt = { "transactionHash": transaction_hash, "transactionIndex": hex(0), @@ -1466,11 +1479,7 @@ def get_transaction_receipt( "to": to_addr, "cumulativeGasUsed": hex(transaction.get("gas_used", 8000000)), "gasUsed": hex(transaction.get("gas_used", 8000000)), - "contractAddress": ( - transaction.get("contract_address") - if transaction.get("contract_address") - else None - ), + "contractAddress": contract_address, "logs": logs, "logsBloom": "0x" + "00" * 256, "status": hex(1 if transaction.get("status", True) else 0), @@ -1485,7 +1494,7 @@ def get_block_by_hash( full_tx: bool = False, ) -> dict | None: - transaction = transactions_processor.get_transaction_by_hash(block_hash) + transaction = transactions_processor.get_transaction_by_hash(block_hash, True) if not transaction: return None