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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
# Change Log
## v0.2.6-beta - December 26, 2024
* Added a check function to verify and validate the wallet ID before making a call to the Qubic network
* Optimized network calls by preventing invalid requests
* Added input validation to enhance security and reliability
* Refactored transaction bytes validation for better data integrity
* Added empty bytes check for transaction data validation

## v0.2.5-beta - December 22, 2024
* Added new advanced code examples
* Reorganized documentation structure
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Currently, QubiPy is in a very early development phase, so please take this into

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

![release](https://img.shields.io/badge/release-v0.2.5--beta-blue)
![release](https://img.shields.io/badge/release-v0.2.6--beta-blue)
![python](https://img.shields.io/badge/python-3.10_%7C_3.11_%7C_3.12-blue)
![Python Package](https://github.com/QubiPy-Labs/QubiPy/actions/workflows/python-package.yml/badge.svg)
![Code Quality](https://github.com/QubiPy-Labs/QubiPy/actions/workflows/pylint.yml/badge.svg)
Expand Down
7 changes: 7 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
# Change Log
## v0.2.6-beta - December 26, 2024
* Added a check function to verify and validate the wallet ID before making a call to the Qubic network
* Optimized network calls by preventing invalid requests
* Added input validation to enhance security and reliability
* Refactored transaction bytes validation for better data integrity
* Added empty bytes check for transaction data validation

## v0.2.5-beta - December 22, 2024
* Added new advanced code examples
* Reorganized documentation structure
Expand Down
4 changes: 2 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Welcome to the **QubiPy** official documentation, a Python Library for the QUBIC RPC API

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

**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.

![release](https://img.shields.io/badge/release-v0.2.5--beta-blue)
![release](https://img.shields.io/badge/release-v0.2.6--beta-blue)
![python](https://img.shields.io/badge/python-3.10_%7C_3.11_%7C_3.12-blue)
![Python Package](https://github.com/QubiPy-Labs/QubiPy/actions/workflows/python-package.yml/badge.svg)
![Code Quality](https://github.com/QubiPy-Labs/QubiPy/actions/workflows/pylint.yml/badge.svg)
Expand Down
7 changes: 6 additions & 1 deletion docs/stylesheets/extra.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,9 @@
.md-nav__link:hover {
color: #B0F9FE !important;
text-shadow: 0 0 10px rgba(176, 249, 254, 0.5);
}
}

.md-header__button.md-logo img {
width: 40px;
height: auto;
}
2 changes: 2 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ repo_url: https://github.com/QubiPy-Labs/QubiPy
repo_name: QubiPy
theme:
name: material
logo: assets/images/logo.png
favicon: assets/images/favicon.ico
palette:
scheme: slate
primary: custom
Expand Down
18 changes: 10 additions & 8 deletions 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 Expand Up @@ -128,11 +129,10 @@ def get_balance(self, wallet_id: str | None = None) -> Dict[str, Any]:
QubiPy_Exceptions: If there is an issue with the API request (e.g., network error, invalid response, or timeout).
"""

if not wallet_id:
if not wallet_id or is_wallet_id_invalid(wallet_id):
raise QubiPy_Exceptions(QubiPy_Exceptions.INVALID_ADDRESS_ID)


endpoint = WALLET_BALANCE.format(id = wallet_id)
endpoint = WALLET_BALANCE.format(id = wallet_id.upper())

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

if not identity:
if not identity or is_wallet_id_invalid(identity):
raise QubiPy_Exceptions(QubiPy_Exceptions.INVALID_ADDRESS_ID)


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

if not identity:
if not identity or is_wallet_id_invalid(identity):
raise QubiPy_Exceptions(QubiPy_Exceptions.INVALID_ADDRESS_ID)

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

if not identity:
if not identity or is_wallet_id_invalid(identity):
raise QubiPy_Exceptions(QubiPy_Exceptions.INVALID_ADDRESS_ID)


endpoint = OWNED_ASSETS.format(identity = identity)

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

if not identity:
if not identity or is_wallet_id_invalid(identity):
raise QubiPy_Exceptions(QubiPy_Exceptions.INVALID_ADDRESS_ID)


endpoint = POSSESSED_ASSETS.format(identity = identity)

try:
Expand Down
28 changes: 20 additions & 8 deletions qubipy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,30 @@ 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:
"""
Checks if the provided wallet ID is invalid.

Args:
wallet_id (str): The wallet ID to validate. Must be exactly 60 characters long.

Returns:
bool: True if the wallet ID is invalid, False if valid
"""
return not isinstance(wallet_id, str) or len(wallet_id) != 60 or not wallet_id.isalpha()
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from setuptools import setup, find_packages

__version__ = '0.2.5'
__version__ = '0.2.6'


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