The Chain of Responsibility in Validator Links
Passing execution constraints through a sequence of modular wards.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Chain of Responsibility
ARCANUM SCHOOL: Abjuration // Ward Chaining
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// PLUTUS PATTERN //
module LedgerMonad.ChainOfResponsibility where
import PlutusTx.Prelude
import Plutus.V2.Ledger.Api
import Plutus.V2.Ledger.Contexts
type Ward = Datum -> Redeemer -> ScriptContext -> Bool
-- Individual Wards
{-# INLINABLE checkSignatures #-}
checkSignatures :: Ward
checkSignatures _ _ ctx = txSignedBy (scriptContextTxInfo ctx) (PubKeyHash "abcd")
{-# INLINABLE checkTimeLock #-}
checkTimeLock :: Ward
checkTimeLock _ _ ctx = True -- placeholder time ward
-- The Chain Forge
{-# INLINABLE executeChain #-}
executeChain :: [Ward] -> Datum -> Redeemer -> ScriptContext -> Bool
executeChain [] _ _ _ = True
executeChain (w:ws) d r ctx =
if w d r ctx
then executeChain ws d r ctx
else traceError "Ward shattered!"
{-# INLINABLE chainedValidator #-}
chainedValidator :: Datum -> Redeemer -> ScriptContext -> Bool
chainedValidator = executeChain [checkSignatures, checkTimeLock]
When defending high-mana vaults, a single, monolithic validator becomes brittle. The Chain of Responsibility pattern allows the Abjurer to forge individual, modular Wards (functions returning Bool). These wards are strung together into a chain. The ScriptContext flows through each link. If any ward fails, the transaction is banished. If it survives the entire chain, the state transition succeeds.
Runic Tags:
#chain-of-responsibility
#plutus
#abjuration
#validation