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.
📝 Summary
This PR introduces a concept developed as part of #70, the
dispatcher
. Thedispatcher
is an object that stores all the list of MEVM precompiles and can invoke each one of them on runtime without needing the generated code for encoding/decoding.Writing a new precompile
Now, writing a precompile is two steps.
First, write a struct that fulfills the
SuavePrecompile
interface:Methods:
Address
: Returns the address assigned to this precompile.Name
: Returns the name of the precompile. This will be the name used on theSuave.sol
library.RequiredGas
: The gas required by the precompile.Do
: A function with the typed inputs/outputs for the precompile. It must have as a first argumentSuaveContext
and as last output anerror
.Second, the precompile gets registered in the dispatcher:
Suave library code generation
With the introduction of the dynamic runtime, the Go code generation is not required anymore.
Besides, now, it is the Go precompiles and the dispatcher the new source of truth about the precompiles. Thus, the yaml specification is not required anymore.
The code generation is still used to generate
Suave.sol
but it uses the methods registered in the dispatcher.Benefits
suave-as-a-contract
model.📚 References