-
Notifications
You must be signed in to change notification settings - Fork 44
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
Improved SmartContract
classes inheritance lookup used during the zkApps deployment procedure.
#640
Merged
Conversation
This file contains 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
shimkiv
changed the title
Improved the classes
Improved May 11, 2024
SmartContract
inheritance lookup used during the zkApps deployment procedure.SmartContract
classes inheritance lookup used during the zkApps deployment procedure.
ymekuria
approved these changes
May 15, 2024
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.
LGTM.
This was referenced May 16, 2024
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.
Closes #636
Includes dependencies and tests upgrade/update.
Description (a bit outdated after the last commit)
This PR introduces the mechanism to identify classes extending or implementing the o1js
SmartContract
class in a given JavaScript file that are scanned using pattern./build/**/*.js
.The core method
findIfClassExtendsOrImplementsSmartContract(entryFilePath)
performs this operation.Below is a
step-by-step
breakdown of how this method works, with explanations of the intermediate methods it invokes, using an example:./build/src/SomeZkApp.js
findIfClassExtendsOrImplementsSmartContract(entryFilePath)
This method identifies all classes in the provided file that extend or implement the
SmartContract
class (Note
: theo1js
belonging is yet to be fixed).It is being invoked with the file path to process like this:
It returns:
This data then used by zkapp-cli
deploy
method to proceed (if only 1 SC is available) or prompt user to select which SC to deploy.Steps:
buildClassHierarchy(entryFilePath)
to generate a map of class names to class information.resolveImports(entryFilePath)
to map local import names to their resolved file paths.SmartContract
by callingcheckClassInheritance()
.Intermediate methods involved
buildClassHierarchy(filePath)
:This function parses the file to build a hierarchy of class declarations.
Returns:
resolveImports(filePath)
:SmartContract
indirectly through imports from other files.This function parses the file to resolve import statements to their respective file paths.
Returns:
resolveModulePath(moduleName, basePath)
:checkClassInheritance(className, targetClass, classesMap, visitedClasses, importMappings)
:This recursive function checks if a given class (or its ancestors) extends or implements the target class.
Returns:
true
Steps
Other code segments
className
) is not found in the current class hierarchy map (classesMap
).importMappings
) and then extends the class hierarchy by parsing the resolved file.