DRep

class cometa.common.drep.DRep(ptr)[source]

Bases: object

Represents a Delegated Representative (DRep) for governance participation.

In Voltaire, stake credentials can delegate their voting power to DReps for governance decisions. DReps can be identified by:

  • A verification key (Ed25519) - KEY_HASH type

  • A native or Plutus script - SCRIPT_HASH type

Additionally, two pre-defined options are available: - ABSTAIN: Actively marks stake as not participating in governance - NO_CONFIDENCE: Votes “Yes” on No Confidence actions, “No” on all others

Example

>>> cred = Credential.from_key_hash("00" * 28)
>>> drep = DRep.new(DRepType.KEY_HASH, cred)
__init__(ptr)[source]
Return type:

None

__enter__()[source]
Return type:

DRep

__exit__(exc_type, exc_val, exc_tb)[source]
Return type:

None

__repr__()[source]

Return repr(self).

Return type:

str

classmethod new(drep_type, credential=None)[source]

Creates a new DRep with the specified type and optional credential.

Parameters:
  • drep_type (DRepType) – The type of DRep (KEY_HASH, SCRIPT_HASH, ABSTAIN, or NO_CONFIDENCE).

  • credential (Credential | None) – The credential for KEY_HASH or SCRIPT_HASH types. Must be None for ABSTAIN and NO_CONFIDENCE types.

Returns:

A new DRep instance.

Raises:

CardanoError – If creation fails.

Return type:

DRep

Example

>>> cred = Credential.from_key_hash("00" * 28)
>>> drep = DRep.new(DRepType.KEY_HASH, cred)
>>> abstain = DRep.new(DRepType.ABSTAIN)
classmethod from_string(bech32_string)[source]

Creates a DRep from a Bech32-encoded string (CIP-105 or CIP-129 format).

Supports both: - CIP-105 format: Key hash directly as Bech32 - CIP-129 format: Includes header byte with governance key type and credential type

Parameters:

bech32_string (str) – The Bech32-encoded DRep string.

Returns:

A new DRep instance.

Raises:

CardanoError – If parsing fails.

Return type:

DRep

Example

>>> drep = DRep.from_string("drep1...")
classmethod from_cbor(reader)[source]

Deserializes a DRep from CBOR data.

Parameters:

reader (CborReader) – A CborReader positioned at the DRep data.

Returns:

A new DRep deserialized from the CBOR data.

Raises:

CardanoError – If deserialization fails.

Return type:

DRep

classmethod abstain()[source]

Creates a DRep representing the Abstain voting option.

Returns:

A new DRep with type ABSTAIN.

Return type:

DRep

classmethod no_confidence()[source]

Creates a DRep representing the No Confidence voting option.

Returns:

A new DRep with type NO_CONFIDENCE.

Return type:

DRep

property drep_type: DRepType

Returns the type of this DRep.

property credential: Credential | None

Returns the credential associated with this DRep.

Returns None for ABSTAIN and NO_CONFIDENCE types.

to_cbor(writer)[source]

Serializes the DRep to CBOR format.

Parameters:

writer (CborWriter) – A CborWriter to write the serialized data to.

Raises:

CardanoError – If serialization fails.

Return type:

None

to_cip116_json(writer)[source]

Converts this object to CIP-116 compliant JSON representation.

CIP-116 defines a standard JSON format for Cardano data structures.

Parameters:

writer (JsonWriter) – A JsonWriter to write the serialized data to.

Raises:

CardanoError – If conversion fails.

Return type:

None

to_cip129_string()[source]

Returns the CIP-129 string representation of the DRep.

Return type:

str

__str__()[source]

Returns the CIP-129 string representation of the DRep.

Return type:

str

__eq__(other)[source]

Checks equality with another DRep.

Parameters:

other (object)

Return type:

bool

__hash__()[source]

Returns a Python hash for use in sets and dicts.

Return type:

int