Plutus.V2.Ledger.Contexts
1. π Overview
2. π§ LANGUAGE PRAGMAS & IMPORTS
3. ποΈ Data Structures
3.1 πͺ TxInInfo
3.2 π TxInfo
3.3 ποΈ ScriptContext
3.4 π― ScriptPurpose
4. βοΈ Core Functions
4.1 π findOwnInput
4.2 π findDatum / findDatumHash
4.3 π findTxInByTxOutRef
4.4 π findContinuingOutputs / getContinuingOutputs
4.5 β txSignedBy
4.6 π ownHashes / ownHash
4.7 π scriptOutputsAt
4.8 π° valueLockedBy / valuePaidTo
4.9 πΈ valueSpent / valueProduced
4.10 π·οΈ spendsOutput
5. π€ Typeclass Instances
6. π On-Chain Derivations
7. π Glossary
1 π Overview
The Plutus.V2.Ledger.Contexts module defines the on-chain view of pending transactions for Plutus V2 scripts. It provides:
Data structures:
TxInInfo,TxInfo, andScriptContextcapturing inputs, outputs, redeemers, and transaction metadata.ScriptPurpose: tags indicating why a script is run (e.g. spending, minting).
Functions: to locate the current input, retrieve datums, compute continuing outputs, and summarize values.
Instances: on-chain equality,
Pretty, and serialization viamakeIsDataIndexedandmakeLift.
2 π§ LANGUAGE PRAGMAS & IMPORTS
NoImplicitPrelude: uses
PlutusTx.Preludeon-chain.DerivingVia and TemplateHaskell for instances.
Imports core V1 modules for reuse of types and functions.
3 ποΈ Data Structures
3.1 πͺ TxInInfo
Usage: Each input pairs a pointer with the resolved
TxOutdata.
3.2 π TxInfo
Enhancements in V2: adds
txInfoReferenceInputsandtxInfoRedeemersfields.
3.3 ποΈ ScriptContext
Encapsulates the entire transaction view plus why the script runs.
3.4 π― ScriptPurpose
Imported from V1:
Indicates the role (minting, spending, etc.) for lookup of the own input.
4 βοΈ Core Functions
4.1 π findOwnInput
Purpose: locates the
TxInInfocorresponding to the current spending reference.Logic: matches
Spending txOutRefagainsttxInfoInputs.
4.2 π findDatum / findDatumHash
findDatum: looks up a datum by its hash in
txInfoData.findDatumHash: reverse-lookup of a datum value to its hash.
4.3 π findTxInByTxOutRef
Purpose: get the input information given its reference.
4.4 π findContinuingOutputs / getContinuingOutputs
findContinuingOutputs: indices of outputs at the same script address.
getContinuingOutputs: full
TxOutvalues at that address.Error: calls
traceErrorif no own input found.
4.5 β
txSignedBy
Checks if a public key is among
txInfoSignatories.
4.6 π ownHashes / ownHash
Extracts the validator hash and attached datum for the current input.
ownHash: convenience returning only the validator hash.
4.7 π scriptOutputsAt
Filters
txInfoOutputsfor those paying to a given validator.
4.8 π° valueLockedBy / valuePaidTo
valueLockedBy: sums values at script address.
valuePaidTo: sums values to a public key address.
4.9 πΈ valueSpent / valueProduced
valueSpent: total of all inputsβ resolved
txOutValue.valueProduced: sum of all output values.
4.10 π·οΈ spendsOutput
Checks if any input matches a given
(TxId, index)pair.
5 π€ Typeclass Instances
Eq TxInInfo,Eq TxInfo,Eq ScriptContext:V2 includes custom
INLINABLE (==)onTxInfoto compare all fields, including maps.
Prettyinstances for human-friendly debugging.
6 π On-Chain Derivations
makeLiftandmakeIsDataIndexedprovide on-chainLiftandIsDatainstances for serialization.
7 π Glossary
TxInInfo: input record pairing a reference and resolved output.
TxInfo: full transaction view available to validators, including redeemers and reference inputs.
ScriptContext: wraps
TxInfoplusScriptPurposefor the current script.ScriptPurpose: reason code (e.g.
Spending txOutRef,Minting cs).OutputDatum: datum attached to a
TxOut(could be inline or by hash).Continuing outputs: new UTXOs at the same script address as the one being spent.
traceError: abort execution with an error message when invariants fail.
makeLift / makeIsDataIndexed: Template Haskell for on-chain data conversion.
Last updated