diff --git a/qubipy/rpc/rpc_client.py b/qubipy/rpc/rpc_client.py index 85eb2be..d61233b 100644 --- a/qubipy/rpc/rpc_client.py +++ b/qubipy/rpc/rpc_client.py @@ -54,7 +54,8 @@ def broadcast_transaction(self, tx: bytes) -> Dict[str, Any]: QubiPy_Exceptions: If there is an issue broadcasting the transaction. """ - check_bytes(tx) + if is_tx_bytes_invalid(tx): + raise QubiPy_Exceptions(QubiPy_Exceptions.INVALID_TX_BYTES) tx_encoded = base64.b64encode(tx).decode('utf-8') payload = json.dumps({ diff --git a/qubipy/utils.py b/qubipy/utils.py index 0fa1fc7..6a6036a 100644 --- a/qubipy/utils.py +++ b/qubipy/utils.py @@ -42,21 +42,20 @@ def check_ticks_format(start_tick: int, end_tick: int): if start_tick <= 0 or end_tick <= 0: raise QubiPy_Exceptions(QubiPy_Exceptions.INVALID_START_TICK_AND_END_TICK) - -def check_bytes(tx: bytes): + +def is_tx_bytes_invalid(tx: bytes) -> bool: """ Validates that the input transaction data is in bytes format. Args: - tx (bytes): The transaction data to validate. Must be of type bytes or bytearray. + tx (bytes): The transaction data to validate. Must be of type bytes or bytearray + and not empty. - Raises: - QubiPy_Exceptions: If the transaction data is not in bytes or bytearray format. + Returns: + bool: True if the transaction data is invalid, False if valid """ - - if not isinstance(tx, (bytes, bytearray)): - raise QubiPy_Exceptions(QubiPy_Exceptions.INVALID_TX_BYTES) + return not isinstance(tx, (bytes, bytearray)) or len(tx) == 0 def is_wallet_id_invalid(wallet_id: str) -> bool: