Source code for digital_world_sdk.network
from .utils import sha256
__all__ = ["Network"]
[docs]
class Network:
"""The :class:`Network` object, which represents a Digital World network.
:param network_passphrase: The passphrase for the network.
(ex. ``"Digital World Network ; June 2021"``)
"""
PUBLIC_NETWORK_PASSPHRASE: str = "Digital World Network ; June 2021"
"""The Public network passphrase."""
TESTNET_NETWORK_PASSPHRASE: str = "Test Digital World Network ; March 2025"
"""The Test network passphrase."""
def __init__(self, network_passphrase: str) -> None:
self.network_passphrase: str = network_passphrase
[docs]
def network_id(self) -> bytes:
"""Get the network ID of the network, which is an hash of the
passphrase.
:returns: The network ID of the network.
"""
return sha256(self.network_passphrase.encode())
[docs]
@classmethod
def public_network(cls) -> "Network":
"""Get the :class:`Network` object representing the PUBLIC Network.
:return: PUBLIC Network
"""
return cls(cls.PUBLIC_NETWORK_PASSPHRASE)
[docs]
@classmethod
def testnet_network(cls) -> "Network":
"""Get the :class:`Network` object representing the TESTNET Network.
:return: TESTNET Network
"""
return cls(cls.TESTNET_NETWORK_PASSPHRASE)
def __hash__(self):
return hash(self.network_passphrase)
def __eq__(self, other: object) -> bool:
if not isinstance(other, self.__class__):
return NotImplemented
return self.network_passphrase == other.network_passphrase
def __repr__(self):
return f"<Network [network_passphrase={self.network_passphrase}]>"