Skip to content

Storage example#36

Draft
mohammadfawaz wants to merge 1 commit intomainfrom
mohammadfawaz/storage_example
Draft

Storage example#36
mohammadfawaz wants to merge 1 commit intomainfrom
mohammadfawaz/storage_example

Conversation

@mohammadfawaz
Copy link
Copy Markdown
Collaborator

@mohammadfawaz mohammadfawaz commented Apr 16, 2026

Adds a storage example demonstrating storage singletons, struct storage, vector storage, and external storage access in Leo 4.

What's in the example

Two programs that together showcase on-chain storage and cross-program reads:

  • treasury.aleo — Declares and manages on-chain state using Leo 4 storage variables:

    • Singletons: storage balance: u64, storage is_frozen: bool, storage deposit_count: u32
    • Struct storage: storage config: FeeConfig — stored and read atomically
    • Vector storage: storage deposit_log: [u64] — dynamically-sized on-chain list with push, pop, get, len, clear
    • Demonstrates unwrap / unwrap_or for reading optional slots, none assignment for clearing, and the Final return type
  • auditor.aleo — Reads treasury storage externally without any getter functions:

    • External singleton reads: treasury.aleo::balance.unwrap_or(0u64)
    • External struct reads: treasury.aleo::config.unwrap_or(treasury.aleo::FeeConfig { ... })
    • External vector reads: treasury.aleo::deposit_log.len(), treasury.aleo::deposit_log.get(0u32)
    • Cross-program struct type references: treasury.aleo::FeeConfig

How to run

run.sh handles the full flow:

  1. Part 1 (local, no devnode): runs treasury operations locally — initialize, deposit, withdraw, freeze, unfreeze, config update
  2. Part 2 (requires leo devnode): deploys both programs, performs treasury operations on-chain, then runs auditor functions that read treasury storage cross-program — including detecting a treasury freeze

@mohammadfawaz mohammadfawaz force-pushed the mohammadfawaz/storage_example branch from 6a86ed0 to 716997b Compare April 16, 2026 15:38
@mohammadfawaz mohammadfawaz marked this pull request as draft April 16, 2026 15:47
@mohammadfawaz mohammadfawaz force-pushed the mohammadfawaz/storage_example branch from 716997b to 5f014e0 Compare April 16, 2026 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant