Skip to content

Commit b5c7128

Browse files
authored
Merge pull request #26 from QubiPy-Labs/v0.2.6-dev
V0.2.6 dev
2 parents bc8d531 + 0a19ab9 commit b5c7128

File tree

7 files changed

+48
-20
lines changed

7 files changed

+48
-20
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
# Change Log
2+
## v0.2.6-beta - December 26, 2024
3+
* Added a check function to verify and validate the wallet ID before making a call to the Qubic network
4+
* Optimized network calls by preventing invalid requests
5+
* Added input validation to enhance security and reliability
6+
* Refactored transaction bytes validation for better data integrity
7+
* Added empty bytes check for transaction data validation
8+
29
## v0.2.5-beta - December 22, 2024
310
* Added new advanced code examples
411
* Reorganized documentation structure

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Currently, QubiPy is in a very early development phase, so please take this into
33

44
Please visit the [Change log](https://github.com/QubiPy-Labs/QubiPy/blob/main/docs/changelog.md) to see all changes.
55

6-
![release](https://img.shields.io/badge/release-v0.2.5--beta-blue)
6+
![release](https://img.shields.io/badge/release-v0.2.6--beta-blue)
77
![python](https://img.shields.io/badge/python-3.10_%7C_3.11_%7C_3.12-blue)
88
![Python Package](https://github.com/QubiPy-Labs/QubiPy/actions/workflows/python-package.yml/badge.svg)
99
![Code Quality](https://github.com/QubiPy-Labs/QubiPy/actions/workflows/pylint.yml/badge.svg)

docs/changelog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
# Change Log
2+
## v0.2.6-beta - December 26, 2024
3+
* Added a check function to verify and validate the wallet ID before making a call to the Qubic network
4+
* Optimized network calls by preventing invalid requests
5+
* Added input validation to enhance security and reliability
6+
* Refactored transaction bytes validation for better data integrity
7+
* Added empty bytes check for transaction data validation
8+
29
## v0.2.5-beta - December 22, 2024
310
* Added new advanced code examples
411
* Reorganized documentation structure

docs/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Welcome to the **QubiPy** official documentation, a Python Library for the QUBIC RPC API
22

3-
!!! note "Beta Version: 0.2.5"
3+
!!! note "Beta Version: 0.2.6"
44
QubiPy is currently in beta. While functional, some features might change before the stable release.
55

66
**QubiPy** is a Python library that provides RPC and Core client functionality. You can interact quickly and easily with the Qubic RPC API using the different methods offered by this library.
77

8-
![release](https://img.shields.io/badge/release-v0.2.5--beta-blue)
8+
![release](https://img.shields.io/badge/release-v0.2.6--beta-blue)
99
![python](https://img.shields.io/badge/python-3.10_%7C_3.11_%7C_3.12-blue)
1010
![Python Package](https://github.com/QubiPy-Labs/QubiPy/actions/workflows/python-package.yml/badge.svg)
1111
![Code Quality](https://github.com/QubiPy-Labs/QubiPy/actions/workflows/pylint.yml/badge.svg)

qubipy/rpc/rpc_client.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ def broadcast_transaction(self, tx: bytes) -> Dict[str, Any]:
5454
QubiPy_Exceptions: If there is an issue broadcasting the transaction.
5555
"""
5656

57-
check_bytes(tx)
57+
if is_tx_bytes_invalid(tx):
58+
raise QubiPy_Exceptions(QubiPy_Exceptions.INVALID_TX_BYTES)
5859

5960
tx_encoded = base64.b64encode(tx).decode('utf-8')
6061
payload = json.dumps({
@@ -128,11 +129,10 @@ def get_balance(self, wallet_id: str | None = None) -> Dict[str, Any]:
128129
QubiPy_Exceptions: If there is an issue with the API request (e.g., network error, invalid response, or timeout).
129130
"""
130131

131-
if not wallet_id:
132+
if not wallet_id or is_wallet_id_invalid(wallet_id):
132133
raise QubiPy_Exceptions(QubiPy_Exceptions.INVALID_ADDRESS_ID)
133134

134-
135-
endpoint = WALLET_BALANCE.format(id = wallet_id)
135+
endpoint = WALLET_BALANCE.format(id = wallet_id.upper())
136136

137137
try:
138138
response = requests.get(f'{self.rpc_url}{endpoint}', headers=HEADERS, timeout=self.timeout)
@@ -355,7 +355,7 @@ def get_transfer_transactions_per_tick(self, identity: str | None = None, start_
355355
QubiPy_Exceptions: If there is an issue with the API request (e.g., network error, invalid response, or timeout).
356356
"""
357357

358-
if not identity:
358+
if not identity or is_wallet_id_invalid(identity):
359359
raise QubiPy_Exceptions(QubiPy_Exceptions.INVALID_ADDRESS_ID)
360360

361361

@@ -508,7 +508,7 @@ def get_issued_assets(self, identity: str | None = None) -> Dict[str, Any]:
508508
QubiPy_Exceptions: If there is an issue with the API request (e.g., network error, invalid response, or timeout).
509509
"""
510510

511-
if not identity:
511+
if not identity or is_wallet_id_invalid(identity):
512512
raise QubiPy_Exceptions(QubiPy_Exceptions.INVALID_ADDRESS_ID)
513513

514514
endpoint = ISSUED_ASSETS.format(identity = identity)
@@ -537,9 +537,10 @@ def get_owned_assets(self, identity: str | None = None) -> Dict[str, Any]:
537537
QubiPy_Exceptions: If there is an issue with the API request (e.g., network error, invalid response, or timeout).
538538
"""
539539

540-
if not identity:
540+
if not identity or is_wallet_id_invalid(identity):
541541
raise QubiPy_Exceptions(QubiPy_Exceptions.INVALID_ADDRESS_ID)
542542

543+
543544
endpoint = OWNED_ASSETS.format(identity = identity)
544545

545546
try:
@@ -566,9 +567,10 @@ def get_possessed_assets(self, identity: str | None = None) -> Dict[str, Any]:
566567
QubiPy_Exceptions: If there is an issue with the API request (e.g., network error, invalid response, or timeout).
567568
"""
568569

569-
if not identity:
570+
if not identity or is_wallet_id_invalid(identity):
570571
raise QubiPy_Exceptions(QubiPy_Exceptions.INVALID_ADDRESS_ID)
571572

573+
572574
endpoint = POSSESSED_ASSETS.format(identity = identity)
573575

574576
try:

qubipy/utils.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,30 @@ def check_ticks_format(start_tick: int, end_tick: int):
4242

4343
if start_tick <= 0 or end_tick <= 0:
4444
raise QubiPy_Exceptions(QubiPy_Exceptions.INVALID_START_TICK_AND_END_TICK)
45-
46-
def check_bytes(tx: bytes):
4745

46+
47+
def is_tx_bytes_invalid(tx: bytes) -> bool:
4848
"""
4949
Validates that the input transaction data is in bytes format.
5050
5151
Args:
52-
tx (bytes): The transaction data to validate. Must be of type bytes or bytearray.
52+
tx (bytes): The transaction data to validate. Must be of type bytes or bytearray
53+
and not empty.
5354
54-
Raises:
55-
QubiPy_Exceptions: If the transaction data is not in bytes or bytearray format.
55+
Returns:
56+
bool: True if the transaction data is invalid, False if valid
5657
"""
57-
58-
if not isinstance(tx, (bytes, bytearray)):
59-
raise QubiPy_Exceptions(QubiPy_Exceptions.INVALID_TX_BYTES)
58+
return not isinstance(tx, (bytes, bytearray)) or len(tx) == 0
59+
60+
61+
def is_wallet_id_invalid(wallet_id: str) -> bool:
62+
"""
63+
Checks if the provided wallet ID is invalid.
64+
65+
Args:
66+
wallet_id (str): The wallet ID to validate. Must be exactly 60 characters long.
67+
68+
Returns:
69+
bool: True if the wallet ID is invalid, False if valid
70+
"""
71+
return not isinstance(wallet_id, str) or len(wallet_id) != 60 or not wallet_id.isalpha()

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from setuptools import setup, find_packages
22

3-
__version__ = '0.2.5'
3+
__version__ = '0.2.6'
44

55

66
with open("README.md", "r", encoding="utf-8") as fh:

0 commit comments

Comments
 (0)