nectar.instance module

class nectar.instance.SharedInstance

Bases: object

Singleton for the shared Blockchain Instance (Hive-only).

config = {}
instance = None
nectar.instance.clear_cache() None

Clear cached blockchain object state.

Performs a lazy import of BlockchainObject and calls its clear_cache() method to purge any in-memory caches of blockchain objects (used when the shared Hive instance or configuration changes).

nectar.instance.set_shared_blockchain_instance(blockchain_instance: Any) None

Override the shared Hive instance used by the module and clear related caches.

This sets SharedInstance.instance to the provided blockchain instance and calls clear_cache() to invalidate any cached blockchain objects so consumers observe the new instance immediately.

nectar.instance.set_shared_config(config: Dict[str, Any]) None

Set configuration for the shared Hive instance without creating the instance.

Updates the global SharedInstance.config with the provided mapping. If a shared instance already exists, clears internal caches and resets the shared instance to None so the new configuration will take effect on next access.

Parameters:

config (dict): Configuration options to merge into the shared instance configuration.

Raises:

AssertionError: If config is not a dict.

nectar.instance.set_shared_hive_instance(hive_instance: Any) None

Override the global shared Hive instance used by the module.

Replaces the current SharedInstance.instance with the provided hive_instance and clears related caches so subsequent calls return the new instance.

Parameters:

hive_instance: The nectar.Hive instance to set as the shared global instance.

nectar.instance.shared_blockchain_instance() Any

Initialize and return the shared Hive instance.

Hive-only: this always returns a nectar.Hive instance, regardless of any legacy configuration that may have referenced other chains.

nectar.instance.shared_hive_instance() Any

Initialize (if needed) and return the shared Hive instance.