Skip to content
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

Conditional zkApp method calls #1889

Open
mitschabaude opened this issue Oct 30, 2024 · 2 comments
Open

Conditional zkApp method calls #1889

mitschabaude opened this issue Oct 30, 2024 · 2 comments

Comments

@mitschabaude
Copy link
Collaborator

mitschabaude commented Oct 30, 2024

Currently, it's possible to add account updates to the tx conditionally with AccountUpdate.createIf(), but it's not possible to call another method conditionally.

Since a method call just means adding the account update that another method produces to the AU tree, it should be fairly easy to support conditional method calls. There's simply an additional boolean condition that needs to be considered before pushing the AU to the tree.

The API probably can't be as clean as the current zkApp call API, but I think that's ok, something like this should work well enough:

this.callIf(bool, otherContract, "methodName", [...arguments]);

note, the method name + arguments can be made type-safe if this is polymorphic over the contract, something like:

callIf<Contract extends SmartContract & { [k in MethodName]: Function }, MethodName extends string>(condition: Bool, contract: Contract, methodName: MethodName, arguments: Parameters<Contract[MethodName]>): void;
@mitschabaude
Copy link
Collaborator Author

@Trivo25 @nholland94 something to consider from the get-go in the new API

@mitschabaude
Copy link
Collaborator Author

mitschabaude commented Oct 30, 2024

a clear-cut use case for conditional method calls is spawning method calls from a reducer, where some of the input actions (necessarily) are dummy actions

see also discord discussion https://discord.com/channels/484437221055922177/1298526066394140672/1300855340522537084

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant