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
- 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