Plutus.V1.Ledger.DCert

  • 1. 📜 Overview

  • 2. 🔧 LANGUAGE EXTENSIONS AND IMPORTS

  • 3. 🗄️ Data Type

    • 3.1 📜 DCert Constructors

  • 4. 🤝 Typeclass Instances

    • 4.1 🧮 PlutusTx.Eq DCert

    • 4.2 📖 Pretty DCert

  • 5. 🏭 On-chain Derivations

  • 6. 📚 Glossary


1 📜 Overview

The Plutus.V1.Ledger.DCert module defines a compact representation of delegation and stake pool certificates included in Cardano transactions. It provides:

  • A single DCert algebraic data type capturing all certificate variants.

  • On-chain equality and pretty-printing instances.

  • Serialization and lifting support for Plutus Core.


2 🔧 LANGUAGE EXTENSIONS AND IMPORTS

{-# LANGUAGE DataKinds         #-}
{-# LANGUAGE DeriveAnyClass    #-}
{-# LANGUAGE DerivingVia       #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell   #-}
{-# OPTIONS_GHC -fno-specialise #-}
{-# OPTIONS_GHC -Wno-simplifiable-class-constraints #-}
{-# OPTIONS_GHC -fno-omit-interface-pragmas #-}

module Plutus.V1.Ledger.DCert (DCert(..)) where

import Control.DeepSeq (NFData)
import GHC.Generics    (Generic)
import Plutus.V1.Ledger.Credential (StakingCredential)
import Plutus.V1.Ledger.Crypto      (PubKeyHash)
import PlutusTx                    qualified as PlutusTx
import PlutusTx.Prelude            qualified as P
import Prettyprinter                (Pretty(..), viaShow)
  • Pragmas:

    • DataKinds, DeriveAnyClass, DerivingVia, OverloadedStrings, TemplateHaskell for generic and on-chain support.

    • GHC options to control specialization and interface pragmas.

  • Imports:

    • StakingCredential, PubKeyHash for certificate fields.

    • PlutusTx and P for on-chain utilities.

    • Prettyprinter for human-readable output.


3 🗄️ Data Type

3.1 📜 DCert Constructors

-- | Digests of certificates that are included in transactions.
data DCert
  = DCertDelegRegKey    StakingCredential       -- ^ Register delegation key
  | DCertDelegDeRegKey  StakingCredential       -- ^ Deregister delegation key
  | DCertDelegDelegate  StakingCredential
                        PubKeyHash             -- ^ Delegate to a pool operator
  | DCertPoolRegister   PubKeyHash
                        PubKeyHash             -- ^ Register stake pool (poolId, VRF key)
  | DCertPoolRetire     PubKeyHash
                        Integer                -- ^ Retire pool at epoch N
  | DCertGenesis                                   -- ^ Genesis certificate
  | DCertMir                                       -- ^ MIR (move instantaneous rewards)
  deriving stock (Eq, Ord, Show, Generic)
  deriving anyclass (NFData)
  • Constructors capture each certificate kind:

    • Delegation: register, deregister, delegate to a pool.

    • Pool: register or retire a stake pool.

    • System: genesis and MIR certificates.

Example:

let cert1 = DCertDelegRegKey someStakingCred
let cert2 = DCertPoolRetire somePoolId 120
print cert1   -- uses Show: DCertDelegRegKey ...

4 🤝 Typeclass Instances

4.1 🧮 PlutusTx.Eq DCert

instance P.Eq DCert where
  {-# INLINABLE (==) #-}
  DCertDelegRegKey sc == DCertDelegRegKey sc'               = sc P.== sc'
  DCertDelegDeRegKey sc == DCertDelegDeRegKey sc'           = sc P.== sc'
  DCertDelegDelegate sc pkh == DCertDelegDelegate sc' pkh'  = sc P.== sc' && pkh P.== pkh'
  DCertPoolRegister pid vrf == DCertPoolRegister pid' vrf'  = pid P.== pid' && vrf P.== vrf'
  DCertPoolRetire pid i  == DCertPoolRetire pid' i'         = pid P.== pid' && i P.== i'
  DCertGenesis          == DCertGenesis                    = True
  DCertMir              == DCertMir                        = True
  _ == _                                                    = False
  • Class: Eq from PlutusTx, used in on-chain comparisons.

  • INLINABLE for GHC specialization in Plutus Core.

4.2 📖 Pretty DCert

instance Pretty DCert where
  pretty = viaShow
  • Derives pretty-printing via the Show instance for simplicity.


5 🏭 On-chain Derivations

PlutusTx.makeIsDataIndexed ''DCert
  [ ('DCertDelegRegKey,0)
  , ('DCertDelegDeRegKey,1)
  , ('DCertDelegDelegate,2)
  , ('DCertPoolRegister,3)
  , ('DCertPoolRetire,4)
  , ('DCertGenesis,5)
  , ('DCertMir,6)
  ]
PlutusTx.makeLift ''DCert
  • makeIsDataIndexed: creates IsData for serialization to on-chain data, mapping each constructor to an index.

  • makeLift: generates Lift instance to embed DCert values in PlutusTx code.


6 📚 Glossary

  • DCert: digest of a delegation or stake pool certificate.

  • StakingCredential: credential identifying staking key (hash or pointer).

  • PubKeyHash: hash of a public key, identifying pool operator.

  • Genesis Certificate: initial certificate present in the genesis distribution.

  • MIR: Move Instantaneous Rewards certificate.

  • makeIsDataIndexed: Template Haskell for on-chain serialization.

  • makeLift: Template Haskell for lifting values into PlutusTx.

  • INLINABLE: GHC pragma allowing specialization and inclusion in on-chain code.

Last updated