Cardano.Utxo

Handling outputs.

Definitions

type alias OutputReference =
{ transactionId : Bytes TransactionId
, outputIndex : Int
}

The reference for a eUTxO.

Phantom type for 32-bytes transaction IDs. This is a Blake2b-256 hash.

type alias Output =
{ address : Address
, amount : Value
, datumOption : Maybe DatumOption
, referenceScript : Maybe Reference
}

The content of a eUTxO.

Phantom type for 32-bytes datum hashes. This is a Blake2b-256 hash.

= DatumHash (Bytes DatumHash)
| DatumValue { rawBytes : Bytes Data }

Nickname for data stored in a eUTxO.

Dictionary with [OutputReference] keys

type alias RefDict a =
AnyDict ( String, Int ) OutputReference a

Convenience type for Dict with [OutputReference] keys.

WARNING: do not compare them with == since they contain functions.

emptyRefDict : RefDict a

Convenience empty initialization for Dict with [OutputReference] keys.

WARNING: do not compare them with == since they contain functions.

refDictFromList : List ( OutputReference, a ) -> RefDict a

Convenience function to create a Dict with [OutputReference] keys from a list.

WARNING: do not compare them with == since they contain functions.

Build

fromLovelace : Address -> Natural -> Output

Construct an Output from an Address and a lovelace amount

simpleOutput : Address -> Value -> Output

Create a simple [Output] with just an [Address] and a [Value].

Display

refAsString : OutputReference -> String

Display the [OutputReference] as a String.

Query

lovelace : Output -> Natural

Extract the amount of lovelace in an Output

totalLovelace : List Output -> Natural

Calculate the total number of lovelace in a collection of Output

compareLovelace : Output -> Output -> Order

Compare UTxOs by lovelace value.

isAdaOnly : Output -> Bool

Check if the output contains only Ada. Nothing else is allowed, no tokens, no datum, no ref script.

isAssetsOnly : Output -> Bool

Check if the output contains only assets (Ada or tokens). Datums and ref scripts are not allowed.

Compute

minAda : Output -> Natural

Compute minimum Ada lovelace for a given [Output].

Since the size of the lovelace field may impact minAda, we adjust its value if it is too low before computation.

The formula is given by CIP 55, with current value of 4310 for coinsPerUTxOByte.

TODO: provide coinsPerUTxOByte in function arguments?

checkMinAda : Output -> Result String Output

Check that an [Output] has enough ada to cover its size.

minAdaForAssets : Address -> MultiAsset Natural -> Natural

Compute minimum Ada lovelace for a given [MultiAsset] that would be sent to a given address.

TODO: provide coinsPerUTxOByte in function arguments?

freeAda : Output -> Natural

Amount of Ada Lovelace "free" in the output, meaning the amount above the minimum required for the output.

bytesWidth : Output -> Int

Computes the bytes width of the output if we encode it to CBOR.

Convert

encodeOutputReference : OutputReference -> Encoder

CBOR encoder for [OutputReference].

encodeOutput : Output -> Encoder

CBOR encoder for [Output].

CBOR encoder for [DatumOption].

decodeOutputReference : Decoder OutputReference

Decode an [OutputReference], such as for transaction inputs.

decodeOutput : Decoder Output

CBOR decoder for an [Output].

outputReferenceToData : OutputReference -> Data

[Data] encoder function for [OutputReference].

Create a DatumOption with a value from a Data object.