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.
Constructors
new TokenAccountUpdateIterator(forest, mayUseToken, selfToken)
new TokenAccountUpdateIterator(
forest: MerkleListIterator<AccountUpdateTreeBase>,
mayUseToken: {},
selfToken: Field): TokenAccountUpdateIterator
Parameters
• forest: MerkleListIterator
\<AccountUpdateTreeBase
>
• mayUseToken
• selfToken: Field
Returns
Source
lib/mina/token/forest-iterator.ts:56
Properties
currentLayer
currentLayer: Layer;
Source
lib/mina/token/forest-iterator.ts:52
selfToken
selfToken: Field;
Source
lib/mina/token/forest-iterator.ts:54
unfinishedParentLayers
unfinishedParentLayers: MerkleList<Layer>;
Source
lib/mina/token/forest-iterator.ts:53
Methods
assertFinished()
assertFinished(message?: string): void
Parameters
• message?: string
Returns
void
Source
lib/mina/token/forest-iterator.ts:137
next()
next(): {
accountUpdate: update;
usesThisToken: Bool;
}
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
{
accountUpdate: update;
usesThisToken: Bool;
}
accountUpdate
accountUpdate: AccountUpdate = update;
usesThisToken
usesThisToken: Bool;
Source
lib/mina/token/forest-iterator.ts:85
create()
static create(forest: AccountUpdateForest, selfToken: Field): TokenAccountUpdateIterator
Parameters
• forest: AccountUpdateForest
• selfToken: Field