-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Emit events for all transfers #88
Conversation
The `TransferEvent` was not expressive enough to capture all transfers, only two party a -> b transfers. Furthermore, even a transfer of that type would not emit an event unless it was initiated using `FungibleToken.transfer()`. We now emit individual events per `AccountUpdate` that's using the token.
5b8b08c
to
1bdd370
Compare
FungibleToken.ts
Outdated
@@ -169,6 +168,12 @@ export class FungibleToken extends TokenContract { | |||
let totalBalance = Int64.from(0) | |||
this.forEachUpdate(updates, (update, usesToken) => { | |||
this.checkPermissionsUpdate(update) | |||
if (usesToken) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can't use if (usesToken)
, it's not a boolean but a Bool
(o1js class) and is always truthy
doing things conditionally in a circuit typically involves Provable.if()
or some form of option type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we will have to implement a conditional version of this.emitEvent()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ultimately, emitEvent()
just updates this.body.events
(which is a hash) and the conditional version does the same but with Provable.if()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I pushed a change that assembles an array of Option(BalanceChangeEvent)
, then filters our the none()
values, and emits an event for those remaining.
Is there a simpler way of doing this, or is that how I should do it?
FungibleToken.ts
Outdated
value: Option<BalanceChangeEvent>, | ||
_index: number, | ||
_array: Option<BalanceChangeEvent>[], | ||
) => value.isSome) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same issue as before, we can't filter on value.isSome
, it's a Bool
, always truthy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, right!
Is there an equivalent function to filter on a Bool
?
No description provided.