Dynamic entries V3
Motivation and Context
Helpers to define initial dynamic entries and an interface for update.
To define a contract with dynamic entries:
- define a storage type of the form
{dynamic_entries ; storage = <ty> }(using type puning) - if any, define initial dynamic entries using attribute
@dyn_entry
closes #1791 (closed)
Description
Following @alistair.obrien design here
New entry in std_lib:
- the
dynamic_entrypointstype: just(nat,bytes) big_map - the
(p,s) dynamic_entrypointtype: an abstract type used as a typed key intodynamic_entrypointswhich winds up being casted to nat - two helping function in module
Dynamic_entrypointsletting you set and get dynamic entries directly from the@dyn_entrydeclarations:val set_entrypoint (type p s) : (p, s) dynamic_entrypoint -> (p, s) entrypoint option -> dynamic_entrypoints -> dynamic_entrypointsval get_entrypoint (type p s) : (p, s) dynamic_entrypoint -> dynamic_entrypoints -> (p, s) entrypoint option
Changes in the typechecking:
-
C_CAST_DYNAMIC_ENTRYPOINTused to cast any(p, s) dynamic_entrypointto a nat -
C_OPT_OUT_ENTRYused as a placeholder for entries which should not appear in the initial storage[%external ("OPT_OUT_ENTRY", ())] -
storagetypes holding adynamic_entrypointsfield must only have one other fieldstorage -
[@dyn_entry] let x = eis type checked as:e : ('param, 'storage) entrypoint x : ('param, 'storage) dynamic_entrypoint
In a dedicated pass (self_ast_typed) and for each module with a contract sort:
- Generate a binder
$initial_dynamic_entrypointsof typedyn_entrypointsholding inital dynamic entrypoints definition - Morph
@dyn_entrydeclarations right-end sides into natural numbers - Morph all applications
C_CAST_DYNAMIC_ENTRYPOINT xtox
LIGO CLI:
If a contract storage has two fields: dynamic_entrypoints and storage then compile storage command expects an expression of type storage and will automatically fill up the dynamic_entrypoints field
Component
-
compiler -
website -
webide -
vscode-plugin -
debugger
Types of changes
-
Bug fix (non-breaking change which fixes an issue) -
New feature (non-breaking change which adds functionality) -
Breaking change (fix or feature that would cause existing functionality to not work as expected) -
Performance improvement (non-breaking change that improves performance) -
None (change with no changelog)
Changelog
Dynamic entrypoints helpers in LIGO
Checklist:
-
If a new syntax has been introduced, put a message on slack ligo-lsp -
Changes follow the existing coding style (use dune @fmtto check). -
Tests for the changes have been added (for bug fixes / feature). -
Documentation has been updated. -
Changelog description has been added (if appropriate). -
Start titles under ## Changelogsection with #### (if appropriate). -
There is no image or uploaded file in changelog -
Examples in changed behaviour have been added to the changelog (for breaking change / feature).