Ledger ADTs and operations upon them

Compact language version 0.13.0, compiler version 0.20.0.

Kernel()

This ADT is a special ADT defining various built-in operations and valid only as a top-level ADT type.

checkpoint(): void

Marks all execution up to this point as being a single atomic unit, allowing partial transaction failures to be split across it.

claim_contract_call(addr: Bytes<32>, entry_point: Bytes<32>, comm: Field): void

Require the presence of another contract call in the containing transaction, with a match address, entry point hash, and communication commitment, that is not claimed by any other call.

claim_zswap_coin_receive(note: Bytes<32>): void

Requires the presence of a commitment in the containing transaction and that no other call claims it as a receive.

claim_zswap_coin_spend(note: Bytes<32>): void

Requires the presence of a commitment in the containing transaction and that no other call claims it as a spend.

claim_zswap_nullifier(nul: Bytes<32>): void

Requires the presence of a nullifier in the containing transaction and that no other call claims it.

mint(domain_sep: Bytes<32>, amount: Unsigned Integer<128>): void

Mints a given amount of coins with a token type derived from the contract's address, adn a given domain separator.

self(): ContractAddress

Returns the current contract's address. ContractAddress is defined in CompactStandardLibrary.

available from Typescript as self(): ContractAddress

Counter()

This ADT is a simple counter.

decrement(amount: Unsigned Integer<16>): void

Decrements the counter by a given amount. Decrementing below zero results in a run-time error.

increment(amount: Unsigned Integer<16>): void

Increments the counter by the given amount.

less_than(threshold: Unsigned Integer<64>): Boolean

Returns if the counter is less than the given threshold value.

read(): Unsigned Integer<64>

Retrieves the current value of the counter.

available from Typescript as a getter on the ledger field

reset_to_default(): void

Resets this Counter to its default value of 0.

Cell(value_type)

This ADT is a single cell containing a value of type type value_type.

read(): value_type

Returns the current contents of this Cell.

available from Typescript as a getter on the ledger field

reset_to_default(): void

Resets this Cell to the default value of its type.

write(value: value_type): void

Overwrites the content of this Cell with the given value.

write_coin(coin: CoinInfo, recipient: Either<ZswapCoinPublicKey, ContractAddress>): void

Writes a CoinInfo to this Cell, which is transformed into a QualifiedCoinInfo at runtime by looking up the relevant Merkle tree index. This index must have been allocated within the current transaction or this write fails. CoinInfo, ContractAddress, Either, and ZswapCoinPublicKey are defined in CompactStandardLibrary.

available only for qualified-coin-info value_type

Set(value_type)

This ADT is an unbounded set of values of type value_type.

insert(elem: value_type): void

Updates this Set to include a given element.

insert_coin(coin: CoinInfo, recipient: Either<ZswapCoinPublicKey, ContractAddress>): void

Inserts a CoinInfo into this Set, which is transformed into a QualifiedCoinInfo at runtime by looking up the relevant Merkle tree index. This index must have been allocated within the current transaction or this insertion fails. CoinInfo, ContractAddress, Either, and ZswapCoinPublicKey are defined in CompactStandardLibrary.

available only for qualified-coin-info value_type

is_empty(): Boolean

Returns whether this Set is the empty set.

available from Typescript as isEmpty(): boolean

member(elem: value_type): Boolean

Returns if an element is contained within this Set.

available from Typescript as member(elem: value_type): boolean

remove(elem: value_type): void

Update this Set to not include a given element.

reset_to_default(): void

Resets this Set to the empty set.

size(): Unsigned Integer<64>

Returns the number of unique entries in this Set.

available from Typescript as size(): bigint

[Symbol.iterator](): Iterator<value_type>

Iterates over the entries in this Set.

callable only from Typescript

Map(key_type, value_type)

This ADT is an unbounded set of mappings between values of type key_type and values of type value_type.

insert(key: key_type, value: value_type): void

Updates this Map to include a new value at a given key.

insert_coin(key: key_type, coin: CoinInfo, recipient: Either<ZswapCoinPublicKey, ContractAddress>): void

Inserts a CoinInfo into this Map at a given key, where the CoinInfo is transformed into a QualifiedCoinInfo at runtime by looking up the relevant Merkle tree index. This index must have been allocated within the current transaction or this insertion fails. CoinInfo, ContractAddress, Either, and ZswapCoinPublicKey are defined in CompactStandardLibrary.

available only for qualified-coin-info value_type

insert_default(key: key_type): void

Updates this Map to include the value type's default value at a given key.

is_empty(): Boolean

Returns if this Map is the empty map.

available from Typescript as isEmpty(): boolean

lookup(key: key_type): value_type

Looks up the value of a key within this Map. The returned value may be another ADT.

available from Typescript as lookup(key: key_type): value_type

member(key: key_type): Boolean

Returns if a key is contained within this Map.

available from Typescript as member(key: key_type): boolean

remove(key: key_type): void

Updates this Map to not include a given key.

reset_to_default(): void

Resets this Map to the empty map.

size(): Unsigned Integer<64>

Returns the number of entries in this Map.

available from Typescript as size(): bigint

[Symbol.iterator](): Iterator<[key_type, value_type]>

Iterates over the key-value pairs contained in this Map.

callable only from Typescript

List(value_type)

This ADT is an unbounded list of values of type value_type.

head(): Maybe<value_type>

Retrieves the head of this List, returning a Maybe, ensuring this call succeeds on the empty list. Maybe is defined in CompactStandardLibrary (compact-runtime runtime.ts from Typescript).

available from Typescript as head(): Maybe<value_type>

is_empty(): Boolean

Returns if this List is the empty list.

available from Typescript as isEmpty(): boolean

length(): Unsigned Integer<64>

Returns the number of elements contained in this List.

available from Typescript as length(): bigint

pop_front(): void

Removes the first element from the front of this list.

push_front(value: value_type): void

Pushes a new element onto the front of this list.

push_front_coin(coin: CoinInfo, recipient: Either<ZswapCoinPublicKey, ContractAddress>): void

Pushes a CoinInfo onto the front of this List, where the CoinInfo is transformed into a QualifiedCoinInfo at runtime by looking up the relevant Merkle tree index. This index must have been allocated within the current transaction or this push fails. CoinInfo, ContractAddress, Either, and ZswapCoinPublicKey are defined in CompactStandardLibrary.

available only for qualified-coin-info value_type

reset_to_default(): void

Resets this List to the empty list.

[Symbol.iterator](): Iterator<value_type>

Iterates over the entries in this List.

callable only from Typescript

MerkleTree(nat, value_type)

This ADT is a bounded Merkle tree of depth nat containing values of type value_type.

check_root(rt: MerkleTreeDigest): Boolean

Tests if the given Merkle tree root is the root for this Merkle tree. MerkleTreeDigest is defined in CompactStandardLibrary (compact-runtime runtime.ts from Typescript).

available from Typescript as checkRoot(rt: MerkleTreeDigest): boolean

insert(item: value_type): void

Inserts a new leaf at the first free index in this Merkle tree.

insert_hash(hash: Bytes<32>): void

Inserts a new leaf with a given hash at the first free index in this Merkle tree.

insert_hash_index(hash: Bytes<32>, index: Unsigned Integer<64>): void

Inserts a new leaf with a given hash at a specific index in this Merkle tree.

insert_index(item: value_type, index: Unsigned Integer<64>): void

Inserts a new leaf at a specific index in this Merkle tree.

insert_index_default(index: Unsigned Integer<64>): void

Inserts a default value leaf at a specific index in this Merkle tree. This can be used to emulate a removal from the tree.

is_full(): Boolean

Returns if this Merkle tree is full and further items cannot be directly inserted.

available from Typescript as isFull(): boolean

reset_to_default(): void

Resets this Merkle tree to the empty Merkle tree.

findPathForLeaf(leaf: value_type): MerkleTreePath<value_type> | undefined

Finds the path for a given leaf in a Merkle tree. Be warned that this is O(n) and should be avoided for large trees. Returns undefined if no such leaf exists. MerkleTreePath is defined in compact-runtime runtime.ts.

callable only from Typescript

firstFree(): bigint

Retrieves the first (guaranteed) free index in the Merkle tree.

callable only from Typescript

pathForLeaf(index: bigint, leaf: value_type): MerkleTreePath<value_type>

Returns the Merkle path, given the knowledge that a specified leaf is at the given index. It is an error to call this if this leaf is not contained at the given index. MerkleTreePath is defined in compact-runtime runtime.ts.

callable only from Typescript

root(): MerkleTreeDigest

Retrieves the root of the Merkle tree. MerkleTreeDigest is defined in compact-runtime runtime.ts.

callable only from Typescript

HistoricMerkleTree(nat, value_type)

This ADT is a bounded Merkle tree of depth nat containing values of type value_type, with history.

check_root(rt: MerkleTreeDigest): Boolean

Tests if the given Merkle tree root is one of the past roots for this Merkle tree. MerkleTreeDigest is defined in CompactStandardLibrary (compact-runtime runtime.ts from Typescript).

available from Typescript as checkRoot(rt: MerkleTreeDigest): boolean

insert(item: value_type): void

Inserts a new leaf at the first free index in this Merkle tree.

insert_hash(hash: Bytes<32>): void

Inserts a new leaf with a given hash at the first free index in this Merkle tree.

insert_hash_index(hash: Bytes<32>, index: Unsigned Integer<64>): void

Inserts a new leaf with a given hash at a specific index in this Merkle tree.

insert_index(item: value_type, index: Unsigned Integer<64>): void

Inserts a new leaf at a specific index in this Merkle tree.

insert_index_default(index: Unsigned Integer<64>): void

Inserts a default value leaf at a specific index in this Merkle tree. This can be used to emulate a removal from the tree.

is_full(): Boolean

Returns if this Merkle tree is full and further items cannot be directly inserted.

available from Typescript as isFull(): boolean

reset_history(): void

Resets the history for this Merkle tree, leaving only the current root valid.

reset_to_default(): void

Resets this Merkle tree to the empty Merkle tree.

findPathForLeaf(leaf: value_type): MerkleTreePath<value_type> | undefined

Finds the path for a given leaf in a Merkle tree. Be warned that this is O(n) and should be avoided for large trees. Returns undefined if no such leaf exists. MerkleTreePath is defined in compact-runtime runtime.ts.

callable only from Typescript

firstFree(): bigint

Retrieves the first (guaranteed) free index in the Merkle tree.

callable only from Typescript

history(): Iterator<MerkleTreeDigest>

An iterator over the roots that are considered valid past roots for this Merkle tree. MerkleTreeDigest is defined in compact-runtime runtime.ts.

callable only from Typescript

pathForLeaf(index: bigint, leaf: value_type): MerkleTreePath<value_type>

Returns the Merkle path, given the knowledge that a specified leaf is at the given index. It is an error to call this if this leaf is not contained at the given index. MerkleTreePath is defined in compact-runtime runtime.ts.

callable only from Typescript

root(): MerkleTreeDigest

Retrieves the root of the Merkle tree. MerkleTreeDigest is defined in compact-runtime runtime.ts.

callable only from Typescript