Transactions¶
This section is part of the
Ledger.Conway.Transaction
module of the formal ledger
specification,
where we define transactions.
A transaction consists of a transaction body, a collection of witnesses and some optional auxiliary data.
Some key ingredients in the transaction body are:
-
A set
txins
of transaction inputs, each of which identifies an output from a previous transaction. A transaction input consists of a transaction id and an index to uniquely identify the output. -
An indexed collection
txouts
of transaction outputs. TheTxOut
type is an address paired with a coin value. -
A transaction fee. This value will be added to the fee pot.
-
The hash
txid
of the serialized form of the transaction that was included in the block.
Conway specifics
Ingredients of the transaction body introduced in the Conway era are the following:
-
txvote
, the list of votes for goverance actions; -
txprop
, the list of governance proposals; -
txdonation
, amount ofCoin
to donate to treasury, e.g., to return money to the treasury after a governance action; -
curTreasury
, the current value of the treasury. This field serves as a precondition to executing Plutus scripts that access the value of the treasury.
Transactions and related types¶
Abstract types
Ix TxId AuxiliaryData : Type
Derived types
TxIn = TxId × Ix TxOut = Addr × Value × Maybe (Datum ⊎ DataHash) × Maybe Script UTxO = TxIn ⇀ TxOut Wdrl = RwdAddr ⇀ Coin RdmrPtr = Tag × Ix ProposedPPUpdates = KeyHash ⇀ PParamsUpdate Update = ProposedPPUpdates × Epoch
Transaction types
record TxBody : Type where field txins : ℙ TxIn refInputs : ℙ TxIn txouts : Ix ⇀ TxOut txfee : Coin mint : Value txvldt : Maybe Slot × Maybe Slot txcerts : List DCert txwdrls : Wdrl txvote : List GovVote txprop : List GovProposal txdonation : Coin txup : Maybe Update txADhash : Maybe ADHash txNetworkId : Maybe Network curTreasury : Maybe Coin txid : TxId collateral : ℙ TxIn reqSigHash : ℙ KeyHash scriptIntHash : Maybe ScriptHash
record TxWitnesses : Type where field vkSigs : VKey ⇀ Sig scripts : ℙ Script txdats : ℙ Datum txrdmrs : RdmrPtr ⇀ Redeemer × ExUnits scriptsP1 : ℙ P1Script scriptsP1 = mapPartial toP1Script scripts record Tx : Type where field body : TxBody wits : TxWitnesses txsize : ℕ isValid : Bool txAD : Maybe AuxiliaryData
Functions related to transactions¶
getValue : TxOut → Value getValue (_ , v , _) = v TxOutʰ = Addr × Value × Maybe (Datum ⊎ DataHash) × Maybe ScriptHash txOutHash : TxOut → TxOutʰ txOutHash (a , v , d , s) = a , (v , (d , M.map hash s)) getValueʰ : TxOutʰ → Value getValueʰ (_ , v , _) = v txinsVKey : ℙ TxIn → UTxO → ℙ TxIn txinsVKey txins utxo = txins ∩ dom (utxo ∣^' (isVKeyAddr ∘ proj₁)) scriptOuts : UTxO → UTxO scriptOuts utxo = filter (λ (_ , addr , _) → isScriptAddr addr) utxo txinsScript : ℙ TxIn → UTxO → ℙ TxIn txinsScript txins utxo = txins ∩ dom (proj₁ (scriptOuts utxo)) refScripts : Tx → UTxO → ℙ Script refScripts tx utxo = mapPartial (proj₂ ∘ proj₂ ∘ proj₂) (range (utxo ∣ (txins ∪ refInputs))) where open Tx; open TxBody (tx .body) txscripts : Tx → UTxO → ℙ Script txscripts tx utxo = scripts (tx .wits) ∪ refScripts tx utxo where open Tx; open TxWitnesses lookupScriptHash : ScriptHash → Tx → UTxO → Maybe Script lookupScriptHash sh tx utxo = lookupᵐ? m sh where m = setToMap (mapˢ < hash , id > (txscripts tx utxo))