From 1f8d2d069ea090c21ad32995248e895cc393e920 Mon Sep 17 00:00:00 2001 From: Bartek Wrona Date: Mon, 22 Sep 2025 08:23:17 +0200 Subject: [PATCH 1/3] Python wax_factory uses lazy imports to load WaxBase and WaxChain implementations --- python/wax/wax_factory.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/python/wax/wax_factory.py b/python/wax/wax_factory.py index 82efe7e7a..0befadf69 100644 --- a/python/wax/wax_factory.py +++ b/python/wax/wax_factory.py @@ -2,16 +2,16 @@ from __future__ import annotations from typing import TYPE_CHECKING -from wax._private.base_api import WaxBaseApi -from wax._private.chain_api import HiveChainApi -from wax.wax_options import WaxChainOptions, WaxOptions - if TYPE_CHECKING: from wax.interfaces import IHiveChainInterface, IWaxBaseInterface + from wax.wax_options import WaxChainOptions, WaxOptions def create_wax_foundation(options: WaxOptions | None = None) -> IWaxBaseInterface: """Factory function to provide wax base interface functionality.""" + from wax._private.base_api import WaxBaseApi + from wax.wax_options import WaxOptions + chain_id = options.chain_id if options is not None else WaxOptions().chain_id return WaxBaseApi(chain_id, _private=True) @@ -19,6 +19,9 @@ def create_wax_foundation(options: WaxOptions | None = None) -> IWaxBaseInterfac def create_hive_chain(options: WaxChainOptions | None = None) -> IHiveChainInterface: """Factory function to provide hive chain interface functionality.""" + from wax._private.chain_api import HiveChainApi + from wax.wax_options import WaxChainOptions + options = options if options is not None else WaxChainOptions() chain_id = options.chain_id endpoint_url = options.endpoint_url -- GitLab From 269fcf3d758b2ea0c26052edf9566b54cd1196f2 Mon Sep 17 00:00:00 2001 From: Bartek Wrona Date: Mon, 22 Sep 2025 08:25:41 +0200 Subject: [PATCH 2/3] ProtoTransaction and JsonTransaction type aliases moved to separate file to avoid immediate loading whole proto definitions while importing wax interface. --- python/wax/_private/base_api.py | 3 ++- python/wax/_private/transaction.py | 6 +++--- python/wax/interfaces.py | 9 ++------- python/wax/transaction_type_aliases.py | 16 ++++++++++++++++ 4 files changed, 23 insertions(+), 11 deletions(-) create mode 100644 python/wax/transaction_type_aliases.py diff --git a/python/wax/_private/base_api.py b/python/wax/_private/base_api.py index 60beae3e3..d85ea0227 100644 --- a/python/wax/_private/base_api.py +++ b/python/wax/_private/base_api.py @@ -48,7 +48,7 @@ from wax.cpp_python_bridge import ( # type: ignore[attr-defined] validate_operation, validate_proto_operation, ) -from wax.interfaces import ChainConfig, IWaxBaseInterface, JsonTransaction, ProtoTransaction, TTimestamp +from wax.interfaces import ChainConfig, IWaxBaseInterface, TTimestamp from wax.models.asset import ( AssetFactory, AssetName, @@ -64,6 +64,7 @@ if TYPE_CHECKING: from wax.interfaces import ITransaction from wax.models.basic import AccountName, ChainId, PublicKey, SigDigest, Signature from wax.models.operations import Operation + from wax.transaction_type_aliases import JsonTransaction, ProtoTransaction class WaxBaseApi(IWaxBaseInterface): diff --git a/python/wax/_private/transaction.py b/python/wax/_private/transaction.py index 616d3d813..937fed195 100644 --- a/python/wax/_private/transaction.py +++ b/python/wax/_private/transaction.py @@ -34,13 +34,13 @@ from wax.cpp_python_bridge import ( # type: ignore[attr-defined] tx_to_json, tx_validate, ) -from wax.interfaces import ITransaction, JsonTransaction, ProtoTransaction -from wax.proto.transaction import transaction as proto_transaction +from wax.interfaces import ITransaction +from wax.transaction_type_aliases import JsonTransaction, ProtoTransaction, proto_transaction if TYPE_CHECKING: from datetime import timedelta - from beekeepy import AsyncUnlockedWallet + from beekeepy._interface.abc import AsyncUnlockedWallet from wax import IWaxBaseInterface from wax.models.basic import AccountName, Hex, PublicKey, SigDigest, Signature, TransactionId from wax.models.operations import WaxMetaOperation diff --git a/python/wax/interfaces.py b/python/wax/interfaces.py index ffc273837..8795132b1 100644 --- a/python/wax/interfaces.py +++ b/python/wax/interfaces.py @@ -8,12 +8,11 @@ from typing import TYPE_CHECKING, Any, Generic, TypeAlias from typing_extensions import Self, TypeVar from wax.api.collection import WaxApiCollection -from wax.proto.transaction import transaction as proto_transaction if TYPE_CHECKING: from decimal import Decimal - from beekeepy import AsyncUnlockedWallet + from beekeepy._interface.abc import AsyncUnlockedWallet from beekeepy.interfaces import HttpUrl from wax.models.asset import ( AssetFactory, @@ -26,12 +25,8 @@ if TYPE_CHECKING: from wax.models.basic import AccountName, ChainId, Hex, PublicKey, SigDigest, Signature, TransactionId from wax.models.key_data import IBrainKeyData, IPrivateKeyData from wax.models.operations import Operation, WaxMetaOperation + from wax.transaction_type_aliases import JsonTransaction, ProtoTransaction - -ProtoTransaction: TypeAlias = proto_transaction -"""Type alias for a transaction in proto format.""" -JsonTransaction: TypeAlias = str -"""Type alias for a transaction in JSON format, which is used in Hive API calls.""" TTimestamp: TypeAlias = datetime | timedelta """TTimestamp is a type alias for a timestamp that can be either a datetime object or a timedelta object.""" diff --git a/python/wax/transaction_type_aliases.py b/python/wax/transaction_type_aliases.py new file mode 100644 index 000000000..653af9ab9 --- /dev/null +++ b/python/wax/transaction_type_aliases.py @@ -0,0 +1,16 @@ +from __future__ import annotations + +from typing import TypeAlias + +from wax.proto.transaction import transaction as proto_transaction + +ProtoTransaction: TypeAlias = proto_transaction +"""Type alias for a transaction in proto format.""" +JsonTransaction: TypeAlias = str +"""Type alias for a transaction in JSON format, which is used in Hive API calls.""" + +__all__ = [ + "JsonTransaction", + "proto_transaction", + "ProtoTransaction", +] -- GitLab From 474150e0cbf374bfd7352f1ed9fee658d9f912b9 Mon Sep 17 00:00:00 2001 From: Bartek Wrona Date: Mon, 22 Sep 2025 08:29:04 +0200 Subject: [PATCH 3/3] HiveHandleCommonHelpers removed from WaxApiCaller inheritance --- python/wax/_private/api/api_caller.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/python/wax/_private/api/api_caller.py b/python/wax/_private/api/api_caller.py index a1a448025..b37541da0 100644 --- a/python/wax/_private/api/api_caller.py +++ b/python/wax/_private/api/api_caller.py @@ -4,9 +4,7 @@ import atexit from functools import partial from typing import TYPE_CHECKING, Any, ClassVar -from beekeepy import Settings from beekeepy.handle.remote import AbstractAsyncHandle, AsyncBatchHandle, RemoteHandleSettings -from wax.helpy._handles.hived.common_helpers import HiveHandleCommonHelpers from wax.interfaces import ApiCollectionT if TYPE_CHECKING: @@ -23,13 +21,13 @@ def api_collection_factory(api_collection: ApiCollectionT, owner: AsyncSendable) return api_collection -class WaxApiCaller(AbstractAsyncHandle[RemoteHandleSettings, ApiCollectionT], HiveHandleCommonHelpers): # type: ignore[type-var] +class WaxApiCaller(AbstractAsyncHandle[RemoteHandleSettings, ApiCollectionT]): # type: ignore[type-var] _INSTANCES: ClassVar[set[WaxApiCaller[Any]]] = set() def __init__(self, api_collection: ApiCollectionT, endpoint_url: HttpUrl) -> None: self._api_collection = api_collection # assigned here because `_constuct_api` method # is called in the constructor of the parent class - settings = Settings() + settings = RemoteHandleSettings() settings.http_endpoint = endpoint_url super().__init__(settings=settings) self._INSTANCES.add(self) @@ -57,7 +55,7 @@ class WaxApiCaller(AbstractAsyncHandle[RemoteHandleSettings, ApiCollectionT], Hi return api_collection_factory(self._api_collection, self) def _target_service(self) -> str: - return self._hived_target_service_name() + return "wax_api_caller" def _cleanup_instances() -> None: -- GitLab