diff --git a/python/cpp_python_bridge.pxd b/python/cpp_python_bridge.pxd index 08c5064f87d789693e222fed2bfd096c23e05097..b375200403bd08910767c7d93543c28b9dce982d 100644 --- a/python/cpp_python_bridge.pxd +++ b/python/cpp_python_bridge.pxd @@ -194,3 +194,4 @@ cdef extern from "cpython_interface.hpp" namespace "cpp": result cpp_proto_to_api( string operation_or_tx ) result cpp_proto_to_legacy_api( string operation_or_tx ) result cpp_api_to_proto( string operation_or_tx ) + bool cpp_is_valid_account_name (string name ) diff --git a/python/cpp_python_bridge.pyx b/python/cpp_python_bridge.pyx index e32bc31a25c396e3f8e60e681df6db8853ad5025..ea55625dbfa87efe07d36fe2dba188bc408222df 100644 --- a/python/cpp_python_bridge.pyx +++ b/python/cpp_python_bridge.pyx @@ -4,6 +4,7 @@ from typing import Callable from functools import wraps +from libcpp cimport bool from libcpp.string cimport string as cppstring from libcpp.set cimport set as cppset from libcpp.map cimport map as cppmap @@ -280,6 +281,10 @@ def estimate_hive_collateral(current_median_history: python_price, current_min_h response = obj.cpp_estimate_hive_collateral(_current_median_history, _current_min_history, _hbd_amount_to_get) return response.amount, response.precision, response.nai +def is_valid_account_name(account_name: bytes) -> bool: + cdef proto_protocol obj + return obj.cpp_is_valid_account_name(account_name) + def proto_operation_get_impacted_accounts(operation: bytes) -> vector[string]: cdef proto_protocol obj return obj.cpp_operation_get_impacted_accounts(operation) diff --git a/python/wax/_private/base_api.py b/python/wax/_private/base_api.py index 843769c1531f332b967ebf52c457967a1e25617a..2950c4f573c5b722f0ef9152d81a98c2b68475d0 100644 --- a/python/wax/_private/base_api.py +++ b/python/wax/_private/base_api.py @@ -48,6 +48,7 @@ from wax.cpp_python_bridge import ( # type: ignore[attr-defined] generate_password_based_private_key, get_hive_protocol_config, get_public_key_from_signature, + is_valid_account_name, operation_get_impacted_accounts, suggest_brain_key, validate_operation, @@ -85,6 +86,10 @@ class WaxBaseApi(IWaxBaseInterface): def address_prefix(self) -> str: return self.config.get("HIVE_ADDRESS_PREFIX", PUBLIC_KEY_ADDRESS_PREFIX) + @staticmethod + def is_valid_account_name(account_name: AccountName) -> bool: + return is_valid_account_name(to_cpp_string(account_name)) + @staticmethod def get_operation_impacted_accounts(operation: Operation) -> list[AccountName]: validation_result = validate_operation(prepare_operation_to_validate(operation)) diff --git a/python/wax/cpp_python_bridge.pyi b/python/wax/cpp_python_bridge.pyi index 6a049397b7199ca6cf85cacd11af41c9f2a7831c..f8c27caa334cd6d5f51adb6d143e99b23d4005db 100644 --- a/python/wax/cpp_python_bridge.pyi +++ b/python/wax/cpp_python_bridge.pyi @@ -16,6 +16,7 @@ from .wax_result import ( python_minimize_required_signatures_data, ) +def is_valid_account_name(account_name: bytes) -> bool: ... def validate_operation(operation: bytes) -> python_result: ... def validate_transaction(transaction: bytes) -> python_result: ... def calculate_transaction_id(transaction: bytes) -> python_result: ... diff --git a/python/wax/interfaces.py b/python/wax/interfaces.py index ba65b6bf9105fa33e31315320d7ee3d7cab1eb8d..1f2c003a5ee9870c15880ca8521fbf9faeb45c95 100644 --- a/python/wax/interfaces.py +++ b/python/wax/interfaces.py @@ -279,6 +279,19 @@ class IWaxBaseInterface(ABC): def address_prefix(self) -> str: """Returns the public key address prefix.""" + @staticmethod + @abstractmethod + def is_valid_account_name(account_name: AccountName) -> bool: + """ + Checks if the given account name is valid. + + Args: + account_name: Account name to be checked. + + Returns: + bool: True if the account name is valid, False otherwise. + """ + @staticmethod @abstractmethod def get_operation_impacted_accounts(operation: Operation) -> list[AccountName]: