| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Morley.Michelson.Untyped.Entrypoints
Synopsis
- newtype EpName = UnsafeEpName {}
- pattern DefEpName :: EpName
- isDefEpName :: EpName -> Bool
- epNameFromParamAnn :: FieldAnn -> Maybe EpName
- epNameToParamAnn :: EpName -> FieldAnn
- epNameFromRefAnn :: FieldAnn -> Either EpNameFromRefAnnError EpName
- epNameFromSelfAnn :: FieldAnn -> EpName
- epNameToRefAnn :: EpName -> FieldAnn
- data EpNameFromRefAnnError = InEpNameBadAnnotation FieldAnn
- buildEpName :: Text -> Either String EpName
- mkEntrypointsMap :: HandleImplicitDefaultEp -> ParameterType -> Map EpName Ty
- data HandleImplicitDefaultEp
Documentation
Entrypoint name.
There are two properties we care about:
- Special treatment of the
defaultentrypoint name.defaultis prohibited in theCONTRACTinstruction and in values ofaddressandcontracttypes. However, it is not prohibited in theSELFinstruction. Hence, the value insideEpNamecan be"default", so that we can distinguishSELFandSELF %default. It is important to distinguish them because their binary representation that is inserted into blockchain is different. For example, typecheckingSELF %defaultconsumes more gas thanSELF. In this module, we provide several smart constructors with different handling ofdefault, please use the appropriate one for your use case. - The set of permitted characters. Intuitively, an entrypoint name should
be valid only if it is a valid annotation (because entrypoints are defined
using field annotations). However, it is not enforced in Tezos.
It is not clear whether this behavior is intended. There is an upstream
issue which received
buglabel, so probably it is considered a bug. Currently we treat it as a bug and deviate from upstream implementation by probiting entrypoint names that are not valid annotations. If Tezos developers fix it soon, we will be happy. If they don't, we should (maybe temporarily) remove this limitation from our code. There is an issue in our repo as well.
Constructors
| UnsafeEpName | |
Instances
| FromJSON EpName Source # | |
| ToJSON EpName Source # | |
Defined in Morley.Michelson.Untyped.Entrypoints | |
| Generic EpName Source # | |
| Show EpName Source # | |
| NFData EpName Source # | |
Defined in Morley.Michelson.Untyped.Entrypoints | |
| Buildable EpName Source # | |
Defined in Morley.Michelson.Untyped.Entrypoints | |
| Eq EpName Source # | |
| Ord EpName Source # | |
Defined in Morley.Michelson.Untyped.Entrypoints | |
| HasCLReader EpName Source # | |
Defined in Morley.Michelson.Untyped.Entrypoints | |
| type Rep EpName Source # | |
Defined in Morley.Michelson.Untyped.Entrypoints | |
pattern DefEpName :: EpName Source #
This is a bidirectional pattern that can be used for two purposes:
- Construct an
EpNamereferring to the default entrypoint. - Use it in pattern-matching or in equality comparison to check whether
EpNamerefers to the default entrypoint. This is trickier because there are two possibleEpNamevalues referring to the default entrypoints.DefEpNamewill match only the most common one (no entrypoint). However, there is a special case:SELFinstruction can have explicit%defaultreference. For this reason, it is recommended to useisDefEpNameinstead. Pattern-matching onDefEpNameis still permitted for backwards compatibility and for the cases when you are sure thatEpNamedoes not come from theSELFinstruction.
isDefEpName :: EpName -> Bool Source #
epNameToParamAnn :: EpName -> FieldAnn Source #
Turn entrypoint name into annotation for contract parameter declaration.
epNameFromRefAnn :: FieldAnn -> Either EpNameFromRefAnnError EpName Source #
Make up EpName from annotation which is reference to an entrypoint.
Note that it's more common for Michelson to prohibit explicit default
entrypoint reference.
Specifically, %default annotation is probitited in values of address
and contract types. It's also prohibited in the CONTRACT instruction.
However, there is an exception: SELF %default is a perfectly valid
instruction. Hence, when you construct an EpName from an annotation
that's part of SELF, you should use epNameFromSelfAnn instead.
epNameFromSelfAnn :: FieldAnn -> EpName Source #
Make up an EpName from an annotation which is part of the
SELF instruction.
epNameToRefAnn :: EpName -> FieldAnn Source #
Turn entrypoint name into annotation used as reference to entrypoint.
data EpNameFromRefAnnError Source #
Constructors
| InEpNameBadAnnotation FieldAnn |
Instances
buildEpName :: Text -> Either String EpName Source #
Make a valid entrypoint name from an arbitrary text. This
function prohibits explicit default entrypoint name which is
permitted by Michelson inside the SELF instruction. This
limitation shouldn't be restrictive because SELF is equivalent to
SELF %default.
mkEntrypointsMap :: HandleImplicitDefaultEp -> ParameterType -> Map EpName Ty Source #
Given an untyped parameter type, extract a map that maps entrypoint names to the their parameter types. If there are duplicate entrypoints in the given Type then the duplicate entrypoints at a deeper nesting level will get overwritten with the ones that are on top.
data HandleImplicitDefaultEp Source #
A simple enum flag to choose how to handle implicit default entrypoint in
mkEntrypointsMap.
Constructors
| WithoutImplicitDefaultEp | Omit the default entrypoint unless it's specified explicitly. |
| WithImplicitDefaultEp | Include the default entrypoint even if it's not specified explicitly. This produces exactly the full set of entrypoints as per Michelson spec. |