Skip to main content

TokenAccountUpdateIterator

o1js / Modules / TokenAccountUpdateIterator

Class: TokenAccountUpdateIterator

Data structure to represent a forest of account updates that is being iterated over, in the context of a token manager contract.

The iteration is done in a depth-first manner.

let forest: AccountUpdateForest = ...;
let tokenIterator = TokenAccountUpdateIterator.create(forest, tokenId);

// process the first 5 account updates in the tree
for (let i = 0; i < 5; i++) {
let { accountUpdate, usesThisToken } = tokenIterator.next();
// ... do something with the account update ...
}

Important: Since this is specifically used by token manager contracts to process their entire subtree of account updates, the iterator skips subtrees that don't inherit token permissions and can therefore definitely not use the token.

So, the assumption is that the consumer of this iterator is only interested in account updates that use the token. We still can't avoid processing some account updates that don't use the token, therefore the iterator returns a boolean usesThisToken alongside each account update.

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new TokenAccountUpdateIterator(forest, mayUseToken, selfToken)

Parameters

NameType
forestMerkleListIterator\<AccountUpdateTreeBase>
mayUseTokenObject
mayUseToken.inheritFromParentBool
mayUseToken.parentsOwnTokenBool
selfTokenField

Defined in

lib/mina/token/forest-iterator.ts:59

Properties

currentLayer

currentLayer: Layer

Defined in

lib/mina/token/forest-iterator.ts:55


selfToken

selfToken: Field

Defined in

lib/mina/token/forest-iterator.ts:57


unfinishedParentLayers

unfinishedParentLayers: MerkleList\<Layer>

Defined in

lib/mina/token/forest-iterator.ts:56

Methods

assertFinished

assertFinished(message?): void

Parameters

NameType
message?string

Returns

void

Defined in

lib/mina/token/forest-iterator.ts:140


next

next(): Object

Make a single step along a tree of account updates.

This function is guaranteed to visit each account update in the tree that uses the token exactly once, when called repeatedly.

The method makes a best effort to avoid visiting account updates that are not using the token, and in particular, to avoid returning dummy updates. However, neither can be ruled out. We're returning { update, usesThisToken: Bool } and let the caller handle the irrelevant case where usesThisToken is false.

Returns

Object

NameType
accountUpdateAccountUpdate
usesThisTokenBool

Defined in

lib/mina/token/forest-iterator.ts:88


create

Static create(forest, selfToken): TokenAccountUpdateIterator

Parameters

NameType
forestAccountUpdateForest
selfTokenField

Returns

TokenAccountUpdateIterator

Defined in

lib/mina/token/forest-iterator.ts:69