Dynamic entrypoints
Definition
Dynamic entrypoints are lazy entrypoints stored in the contract within a big_map. They can then be updated or removed without deploying a new contract.
A contract with dynamic entrypoints must have at least one @entry declaration (as any other contract); must obey some convention on storage type definition and have at least one @dyn_entry declaration.
LIGO will then include the defined dynamic entries into the contract initial storage.
Storage
The contract storage must be a record with two fields (storage and dynamic_entrypoints).
storageis your contract's storage type (as a normal contract)dynamic_entrypointsmust be of type(nat,bytes) big_map
NOTE: the
dynamic_entrypointstype is defined in the standard library so you can use type puning
e.g.
@dyn_entry declaration
Dynamic entries, just like static entries must be declared in contract's top-level and have the type of an entrypoint.
The dynamic entry storage type will typically coincide with the contract storage type but can be different
Opted out dynamic entrypoints
Sometime you know an entrypoint might be defined in your contract's lifetime but you don't have any implementation yet. In this case, you can add a @dyn_entry declaration to your contract; give it a type and use a special expression to make ligo aware that this entry exists but should not be included in the initial storage.
Set and call dynamic entrypoints
Once your dynamic entrypoints defined you can now update or call them.
One important thing is that the variables associated to dynamic entrypoints are understood by LIGO as typed keys into the dynamic_entrypoints big map.
LIGO uses an abstract type dynamic_entrypoint<a, b> to denote such keys.
i.e. the one entry defined above, would type as follow:
As a consequence, dynamic entrypoints are not callable:
NOTE: Of course, it is possible to make an entry callable with an intermediary function
LIGO standard library exposes three function to help you set and call your dynamic entrypoints:
Set an entrypoint
To set an dynamic entrypoint within a static entrypoint, just use Dynamic_entrypoints.set:
NOTE: Alternatively, you can use
Dynamic_entrypoints.set_entrypoint_bytesto set an entrypoints to its bytes encoding directly. If your encoding is wrong, any call toDynamic_entrypoints.getwill fail at run-time
Get an entrypoint
To get an dynamic entrypoint within a static entrypoint and call it just use Dynamic_entrypoints.get:
Misc
compile storage
When using compile storage on a contract holding dynamic entrypoints, you are expected to provide a value of your storage field type.
testing
In the testing framework, you can use to 'Test.storage_with_dynamic_entrypoints' to obtain your contract initial storage.