The Template Method of Ritual Scaffolding
Defining the skeleton of a spell, deferring exact steps to higher-order parameters.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Template Method
ARCANUM SCHOOL: Conjuration // Ritual Scaffolding
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// PLUTUS PATTERN //
module LedgerMonad.TemplateMethod where
import PlutusTx.Prelude
import Plutus.V2.Ledger.Api
import Plutus.V2.Ledger.Contexts
-- The Ritual Scaffolding (Template Method)
{-# INLINABLE baseRitual #-}
baseRitual :: (ScriptContext -> Bool) -> (ScriptContext -> Bool) -> ScriptContext -> Bool
baseRitual step1 step2 ctx =
traceIfFalse "Step 1 failed!" (step1 ctx) &&
traceIfFalse "Step 2 failed!" (step2 ctx)
-- Concrete Ritual Steps
{-# INLINABLE checkPhasesOfMoon #-}
checkPhasesOfMoon :: ScriptContext -> Bool
checkPhasesOfMoon _ = True -- Simplified
{-# INLINABLE checkBloodSacrifice #-}
checkBloodSacrifice :: ScriptContext -> Bool
checkBloodSacrifice ctx = length (txInfoInputs (scriptContextTxInfo ctx)) > 2
-- The Final Binding
{-# INLINABLE templateValidator #-}
templateValidator :: Datum -> Redeemer -> ScriptContext -> Bool
templateValidator _ _ ctx =
baseRitual checkPhasesOfMoon checkBloodSacrifice ctx
Some arcane rituals follow an uncompromising order of operations, even if the specific ingredients change. The Template Method is implemented in Haskell via higher-order functions. The base ritual dictates the absolute control flow (e.g., Ward A must evaluate before Ward B), while accepting the specific, concrete validation functions as parameters. This enforces structural integrity across many variations of a contract.
Runic Tags:
#template-method
#plutus
#conjuration
#higher-order-functions