Michelson: add lightweight multiple entrypoints
This merge request implements a way for a transaction to target a specific code path of a smart contract using a name.
This feature has two purposes:
- user experience:
transfer 33 to bank --entrypoint deposit --arg "savings"if better than
transfer 33 to bank --arg 'Left (Right (Left "savings"))'(this is not only for the CLI, the convention can be followed by graphical UIs)
- polymorphism: several contracts can share an entrypoint by name, potentially targetting a different code path for each.
The lighweight qualifier relates to the simplicity of the implementation.
These entrypoints are simply implemented by piggy baking on Michelson's
or type and field annotations.
To take advantage of the multiple entrypoint feature, the
parameter type of a contract must have at its toplevel a tree of disjunctive types (
option). At each branching point in this tree, a field annotation (the ones with a
%) can appear, providing the name of the entrypoint.
Transactions now have to specify an entrypoint name.
When a transaction is executed, the appropriate
None constructors are automatically added to the value that is pushed onto the input stack, depending on the position of the entrypoint in the
parameter type tree.
This way, two contracts who share an entrypoint of the same type under the same name can be called exactly the same, even if the entrypoint is placed at a different point in their
parameter type tree. From inside the smart contract, nothing changes.
From within Michelson, this feature is also available.
contract t type now points to a specific entrypoint (of type
t) of the contract.
For this, the
CONTRACT instruction now takes an optional annotation (set to
%default if not passed).
TRANSFER_TOKEN will then use the entrypoint from the
contract t value that it consumes from the stack.
An exception to the semantics is made for the
default entrypoint : if present in the contract, it behaves as any other, however if not present,
default is automatically attributed to the root of the
A special check is made at origination that there is no two entrypoints with the same name, and that if a default is present somewhere, then all entrypoints must be named, as otherwise some parts of the code would be unreachable.