TokenAccountUpdateIterator
Defined in: lib/mina/v1/token/forest-iterator.ts:54
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()
new TokenAccountUpdateIterator(
forest: MerkleListIterator<AccountUpdateTreeBase>,
mayUseToken: MayUseToken,
selfToken: Field): TokenAccountUpdateIterator
Defined in: lib/mina/v1/token/forest-iterator.ts:59
Parameters
forest
MerkleListIterator
<AccountUpdateTreeBase
>
mayUseToken
MayUseToken
selfToken
Returns
Properties
currentLayer
currentLayer: Layer;
Defined in: lib/mina/v1/token/forest-iterator.ts:55
selfToken
selfToken: Field;
Defined in: lib/mina/v1/token/forest-iterator.ts:57
unfinishedParentLayers
unfinishedParentLayers: MerkleList<Layer>;
Defined in: lib/mina/v1/token/forest-iterator.ts:56
Methods
assertFinished()
assertFinished(message?: string): void
Defined in: lib/mina/v1/token/forest-iterator.ts:129
Parameters
message?
string
Returns
void
next()
next(): {
accountUpdate: AccountUpdate;
usesThisToken: Bool;
}
Defined in: lib/mina/v1/token/forest-iterator.ts:88
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: AccountUpdate;
usesThisToken: Bool;
}
accountUpdate
accountUpdate: AccountUpdate = update;
usesThisToken
usesThisToken: Bool;
create()
static create(forest: AccountUpdateForest, selfToken: Field): TokenAccountUpdateIterator
Defined in: lib/mina/v1/token/forest-iterator.ts:69