⚙️ PLUTUS RUNE DIFFICULTY: Apprentice Creational

The Prototype of Datum Cloning

Cloning complex UTxO states (Datums) with minimal arcane mutation.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Prototype
ARCANUM SCHOOL: Illusion // State Cloning
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// PLUTUS PATTERN //
module LedgerMonad.Prototype where

import PlutusTx.Prelude
import Plutus.V2.Ledger.Api

-- The Complex Arcane Entity
data GolemState = GolemState
    { gCoreMana    :: Integer
    , gRunes       :: [BuiltinByteString]
    , gMaster      :: PubKeyHash
    , gIsAwake     :: Bool
    }

{-# INLINABLE cloneGolem #-}
-- The Illusionist's Trick (Record Update)
-- In functional realms, prototype cloning is built-in via record updates.
-- We clone the entity, only mutating the specific attributes we wish to change.
cloneGolem :: GolemState -> Integer -> GolemState
cloneGolem prototype newMana = prototype { gCoreMana = newMana, gIsAwake = True }

{-# INLINABLE validateCloningRitual #-}
validateCloningRitual :: GolemState -> GolemState -> ScriptContext -> Bool
validateCloningRitual inputDatum outputDatum ctx =
    let cloned = cloneGolem inputDatum (gCoreMana outputDatum)
    in traceIfFalse "Imperfect illusion!" (outputDatum == cloned)

The Prototype pattern in a pure functional environment like Plutus requires no complex memory manipulation or interface dispatch. The Illusionist achieves this via Haskell’s native record update syntax, efficiently duplicating the Datum of a consumed UTxO while substituting only the required fields for the continuing output.

Runic Tags: #prototype #plutus #illusion