Ipv4
- class cometa.pool_params.ipv4.IPv4(ptr)[source]
Bases:
objectRepresents an IPv4 address used in Cardano stake pool relay configuration.
IPv4 addresses are 4 bytes (32 bits) and are used to identify single-host address relays in stake pool registration certificates.
- IP_SIZE = 4
- __init__(ptr)[source]
Initializes an IPv4 address from a C pointer.
- Parameters:
ptr – A C pointer to the cardano_ipv4_t object.
- Raises:
CardanoError – If the pointer is NULL.
- Return type:
None
- __enter__()[source]
Enables context manager support for the IPv4 object.
- Returns:
The IPv4 instance.
- Return type:
- __exit__(exc_type, exc_val, exc_tb)[source]
Exits the context manager.
- Parameters:
exc_type – The exception type (if any).
exc_val – The exception value (if any).
exc_tb – The exception traceback (if any).
- Return type:
None
- __repr__()[source]
Returns a detailed string representation of the IPv4 address.
- Returns:
A string representation in the format “IPv4(address)”.
- Return type:
str
- __str__()[source]
Returns the IPv4 address in dotted-decimal notation.
- Returns:
A string representation of the IPv4 address.
- Return type:
str
- __eq__(other)[source]
Compares two IPv4 addresses for equality.
- Parameters:
other (object) – The object to compare with.
- Returns:
True if the addresses are equal, False otherwise.
- Return type:
bool
- __hash__()[source]
Returns a hash value for the IPv4 address.
- Returns:
The hash value based on the IPv4 bytes.
- Return type:
int
- classmethod from_bytes(data)[source]
Creates an IPv4 address from raw bytes.
- Parameters:
data (bytes | bytearray) – The raw IPv4 bytes (must be exactly 4 bytes).
- Returns:
A new IPv4 address.
- Raises:
CardanoError – If the bytes are invalid.
- Return type:
Example
>>> ipv4 = IPv4.from_bytes(bytes([192, 168, 1, 1])) >>> str(ipv4) '192.168.1.1'
- classmethod from_string(ip_string)[source]
Creates an IPv4 address from a dotted-decimal string.
- Parameters:
ip_string (str) – The IPv4 address in dotted-decimal notation (e.g., “192.168.1.1”).
- Returns:
A new IPv4 address.
- Raises:
CardanoError – If the string is not a valid IPv4 address.
- Return type:
Example
>>> ipv4 = IPv4.from_string("192.168.1.1") >>> ipv4.to_bytes() b'\xc0\xa8\x01\x01'
- classmethod from_cbor(reader)[source]
Deserializes an IPv4 address from CBOR data.
- Parameters:
reader (CborReader) – A CborReader positioned at the IPv4 data.
- Returns:
A new IPv4 address deserialized from the CBOR data.
- Raises:
CardanoError – If deserialization fails.
- Return type:
- to_bytes()[source]
Returns the raw IPv4 bytes.
- Returns:
The IPv4 address as a 4-byte bytes object.
- Return type:
bytes
Example
>>> ipv4 = IPv4.from_string("192.168.1.1") >>> ipv4.to_bytes() b'\xc0\xa8\x01\x01'
- to_string()[source]
Returns the IPv4 address in dotted-decimal notation.
- Returns:
The IPv4 address as a string (e.g., “192.168.1.1”).
- Return type:
str
Example
>>> ipv4 = IPv4.from_bytes(bytes([192, 168, 1, 1])) >>> ipv4.to_string() '192.168.1.1'
- to_cbor(writer)[source]
Serializes the IPv4 address to CBOR format.
- Parameters:
writer (CborWriter) – A CborWriter to write the serialized data to.
- Raises:
CardanoError – If serialization fails.
- Return type:
None