Agent skill

compact-core:ledger-adts

Use when working with Compact on-chain state management using ledger ADTs including Cell, Counter, Map, Set, List, MerkleTree, or HistoricMerkleTree, or when needing to understand which operations are available in Compact vs TypeScript.

Stars 163
Forks 31

Install this agent skill to your Project

npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/ledger-adts

SKILL.md

Ledger ADTs

Reference for Midnight's ledger abstract data types for on-chain state management.

Available ADTs

ADT Purpose Key Operations
Cell<T> Single mutable value read, write
Counter Increment-only counter increment, value
Map<K, V> Key-value storage lookup, insert, remove
Set<T> Membership collection member, insert, remove
List<T> Ordered collection append, nth, length
MerkleTree<T> Membership proofs insert, root, pathForLeaf
HistoricMerkleTree<T> Historical roots Same + resetHistory

Quick Examples

Counter

compact
ledger counter: Counter;

export circuit increment(): Uint<64> {
    counter.increment(1);
    return counter.value();
}

Map

compact
ledger balances: Map<Bytes<32>, Uint<64>>;

export circuit get_balance(user: Bytes<32>): Uint<64> {
    const result = balances.lookup(user);
    return if result is Maybe::Some(balance) { balance } else { 0 };
}

MerkleTree

compact
ledger members: MerkleTree<Bytes<32>>;

export circuit prove_membership(
    leaf: Bytes<32>,
    path: Vector<Bytes<32>, 20>
): Boolean {
    const computed_root = merkleTreePathRoot(leaf, path);
    return computed_root == members.root();
}

Compact vs TypeScript Operations

Some ADT operations are only available in TypeScript:

ADT Compact TypeScript Only
Counter value, increment -
Map lookup, insert, remove entries, keys
Set member, insert, remove entries, size
List nth, append entries, length
MerkleTree insert, root pathForLeaf, iteration

References

  • Counter - Counter operations and patterns
  • Collections - Map, Set, List operations
  • Merkle Trees - MerkleTree and HistoricMerkleTree
  • Kernel - Special kernel operations

Expand your agent's capabilities with these related and highly-rated skills.

Didn't find tool you were looking for?

Be as detailed as possible for better results