Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion qubipy/rpc/rpc_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
15 changes: 7 additions & 8 deletions qubipy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down