⚙️ MICHELSON RUNE DIFFICULTY: Adept Creational

The Builder Pattern in Michelson

Constructing complex smart contract states step-by-step in Michelson.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Builder
ARCANUM SCHOOL: Conjuration // Stackmancy
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// MICHELSON PATTERN //
parameter (or (string %add_component) (unit %finalize));
storage (pair (list string) (option string));
code {
  UNPAIR;
  IF_LEFT {
    # %add_component
    SWAP; UNPAIR;
    DIG 2; CONS;
    SWAP; PAIR;
    NIL operation; PAIR
  } {
    # %finalize
    DROP;
    UNPAIR;
    PUSH (option string) (Some "Finalized_Construct");
    SWAP; DROP;
    SWAP; PAIR;
    NIL operation; PAIR
  }
}
Runic Tags: #creational #builder #stack-based smart contracts #michelson #tezos