Plutus.V2.Ledger.EvaluationContext

  • Plutus V2 EvaluationContext Tutorial

    Table of Contents

    1. 📖 Introduction

    2. 🔙 Module Re-exports 2.1 🔄 Re-exporting V1.EvaluationContext

    3. ⚙️ Cost Model Parameter Names 3.1 ⚙️ costModelParamNames

    4. 📝 Code Walkthrough

    5. 📖 Glossary of Terms

    1. 📖 Introduction

    This tutorial covers the Plutus.V2.Ledger.EvaluationContext module, which builds upon the V1 evaluation context and exposes the set of valid cost model parameter names for Plutus V2.

    2. 🔙 Module Re-exports

    2.1 🔄 Re-exporting V1.EvaluationContext

    module Plutus.V2.Ledger.EvaluationContext
        ( module V1.EvaluationContext
        , costModelParamNames
        ) where
    
    import Plutus.V1.Ledger.EvaluationContext as V1.EvaluationContext hiding (costModelParamNames)
    • What happens here: The entire V1 evaluation context API is made available under V2, except the old costModelParamNames, so you can reuse all existing context-building functions.

    3. ⚙️ Cost Model Parameter Names

    The key addition in this module is the costModelParamNames set, defining which cost model parameters are valid under Plutus V2.

    3.1 ⚙️ costModelParamNames

    costModelParamNames :: Set.Set Text.Text
    costModelParamNames = Map.keysSet $ fromJust Plutus.defaultCostModelParams
    • Type: Set.Set Text.Text — a set of textual parameter names.

    • Implementation:

      1. Plutus.defaultCostModelParams provides a Maybe (Map Text Text Integer) of default parameters.

      2. fromJust extracts the map (unsafe if defaults missing).

      3. Map.keysSet yields the set of keys (parameter names).

    4. 📝 Code Walkthrough

    1. Imports:

      • Plutus.V1.Ledger.EvaluationContext is brought in as V1.EvaluationContext.

      • PlutusCore.defaultCostModelParams gives the V2 defaults.

      • Standard Haskell libraries for Map, Maybe, Set, and Text.

    2. Re-exporting: All V1 context functions (e.g., mkEvaluationContext, CostModelApplyError) are available without change.

    3. Parameter Names: Use this set to validate incoming cost model parameters when syncing on-chain cost settings.

    5. 📖 Glossary of Terms

    Term
    Definition

    V1.EvaluationContext

    The original Plutus V1 evaluation context API.

    defaultCostModelParams

    Built-in default cost-model parameters from Plutus Core.

    Set.Set Text.Text

    A collection of unique Text values.

    Map.keysSet

    Extracts the set of keys from a Map.

    fromJust

    Unsafe extractor from Maybe, crashes on Nothing.

Last updated