Utxo

class cometa.common.utxo.Utxo(ptr=None)[source]

Bases: object

Represents an Unspent Transaction Output (UTxO).

A UTxO links a transaction input to its corresponding output, representing spendable value in the Cardano blockchain. UTxOs are fundamental to Cardano’s accounting model and are used as inputs in new transactions.

Example

>>> from cometa import Utxo, TransactionInput, TransactionOutput, Address
>>> tx_input = TransactionInput.from_hex("abc123...", 0)
>>> address = Address.from_string("addr_test1...")
>>> tx_output = TransactionOutput.new(address, 1000000)
>>> utxo = Utxo.new(tx_input, tx_output)
>>> print(utxo.input.index)
0
__init__(ptr=None)[source]
Return type:

None

__enter__()[source]
Return type:

Utxo

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

None

__repr__()[source]

Return repr(self).

Return type:

str

__eq__(other)[source]

Return self==value.

Parameters:

other (object)

Return type:

bool

classmethod new(tx_input, tx_output)[source]

Creates a new UTXO by associating a transaction input with its corresponding transaction output.

Parameters:
  • tx_input (TransactionInput) – The transaction input representing the source of the UTXO.

  • tx_output (TransactionOutput) – The transaction output representing the value and recipient.

Returns:

A new Utxo instance.

Raises:

CardanoError – If creation fails.

Return type:

Utxo

Example

>>> utxo = Utxo.new(tx_input, tx_output)
classmethod from_cbor(reader)[source]

Deserializes a Utxo from CBOR data.

Parameters:

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

Returns:

A new Utxo instance deserialized from the CBOR data.

Raises:

CardanoError – If deserialization fails.

Return type:

Utxo

to_cbor(writer)[source]

Serializes the UTXO 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

property input: TransactionInput

Gets the transaction input associated with this UTXO.

Returns:

The TransactionInput representing the source of the UTXO.

__hash__ = None
property output: TransactionOutput

Gets the transaction output associated with this UTXO.

Returns:

The TransactionOutput representing the value and recipient.