Dynamic dispatch example#31
Open
mohammadfawaz wants to merge 1 commit into
Open
Conversation
d4b3df1 to
0e1f71c
Compare
0e1f71c to
0dce7ca
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a dynamic dispatch example demonstrating two related Leo 4 features: interfaces and runtime program routing.
What's in the example
Three programs that together implement a pluggable governance voting system:
voting_power.aleo— Declares theVotingStrategyinterface and provides the linear implementation (1 token = 1 vote)quadratic_power.aleo— Implements the same interface with floor(√balance) voting power, reducing whale influencegovernance.aleo— Dispatch hub that accepts a strategyidentifierat runtime and routes calls to whichever program the caller names, with no redeployment neededFeatures showcased
VotingStrategyand Leo verifies the signatures matchVotingStrategy@(strategy)::compute_power(balance)— theidentifiertype resolves the target program at runtime'voting_power','quadratic_power') for compile-time-known dispatch targetsHow to run
run.shhandles the full flow: local execution of each strategy individually (no devnode needed), then deployment of all three programs and dynamic dispatch calls showing diverging outcomes under linear vs quadratic voting. Requiresleo devnoderunning in a separate terminal.🤖 Generated with Claude Code