| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Michelson.Typed.Entrypoints
Contents
Description
Utilities for lightweight entrypoints support.
Synopsis
- data EpAddress = EpAddress {}
- data ParseEpAddressError
- formatEpAddress :: EpAddress -> Text
- mformatEpAddress :: EpAddress -> MText
- parseEpAddress :: Text -> Either ParseEpAddressError EpAddress
- unsafeParseEpAddress :: HasCallStack => Text -> EpAddress
- parseEpAddressRaw :: ByteString -> Either ParseEpAddressError EpAddress
- unsafeParseEpAddressRaw :: ByteString -> EpAddress
- data ParamNotes (t :: T) = ParamNotesUnsafe {}
- pattern ParamNotes :: Notes t -> RootAnn -> ParamNotes t
- starParamNotes :: SingI t => ParamNotes t
- data ArmCoord
- type ArmCoords = [ArmCoord]
- data ParamEpError
- mkParamNotes :: Notes t -> RootAnn -> Either ParamEpError (ParamNotes t)
- data EpLiftSequence (arg :: T) (param :: T) where
- EplArgHere :: EpLiftSequence arg arg
- EplWrapLeft :: (KnownT subparam, KnownT r) => EpLiftSequence arg subparam -> EpLiftSequence arg ('TOr subparam r)
- EplWrapRight :: (KnownT l, KnownT subparam) => EpLiftSequence arg subparam -> EpLiftSequence arg ('TOr l subparam)
- data EntrypointCallT (param :: T) (arg :: T) = ParameterScope arg => EntrypointCall {
- epcName :: EpName
- epcParamProxy :: Proxy param
- epcLiftSequence :: EpLiftSequence arg param
- epcPrimitive :: forall p. (ParameterScope p, ForbidOr p) => EntrypointCallT p p
- epcCallRootUnsafe :: ParameterScope param => EntrypointCallT param param
- data SomeEntrypointCallT (arg :: T) = forall param.ParameterScope param => SomeEpc (EntrypointCallT param arg)
- sepcCallRootUnsafe :: ParameterScope param => SomeEntrypointCallT param
- sepcPrimitive :: forall t. (ParameterScope t, ForbidOr t) => SomeEntrypointCallT t
- sepcName :: SomeEntrypointCallT arg -> EpName
- type family ForbidOr (t :: T) :: Constraint where ...
- data MkEntrypointCallRes param where
- MkEntrypointCallRes :: ParameterScope arg => Notes arg -> EntrypointCallT param arg -> MkEntrypointCallRes param
- mkEntrypointCall :: ParameterScope param => EpName -> ParamNotes param -> Maybe (MkEntrypointCallRes param)
- tyImplicitAccountParam :: ParamNotes 'TUnit
- newtype EpName = EpNameUnsafe {}
- pattern DefEpName :: EpName
- epNameFromParamAnn :: FieldAnn -> Maybe EpName
- epNameToParamAnn :: EpName -> FieldAnn
- epNameFromRefAnn :: FieldAnn -> Either EpNameFromRefAnnError EpName
- epNameToRefAnn :: EpName -> FieldAnn
- data EpNameFromRefAnnError = InEpNameBadAnnotation FieldAnn
Documentation
Address with optional entrypoint name attached to it. TODO: come up with better name?
Constructors
| EpAddress | |
Fields
| |
Instances
data ParseEpAddressError Source #
Constructors
Instances
formatEpAddress :: EpAddress -> Text Source #
mformatEpAddress :: EpAddress -> MText Source #
parseEpAddress :: Text -> Either ParseEpAddressError EpAddress Source #
Parse an address which can be suffixed with entrypoint name (e.g. "tz1faswCTDciRzE4oJ9jn2Vm2dvjeyA9fUzU%entrypoint").
unsafeParseEpAddress :: HasCallStack => Text -> EpAddress Source #
parseEpAddressRaw :: ByteString -> Either ParseEpAddressError EpAddress Source #
Parses byte representation of entrypoint address.
For every address
KT1QbdJ7M7uAQZwLpvzerUyk7LYkJWDL7eDh%foo%bar
we get the following byte representation
01afab866e7f1e74f9bba388d66b246276ce50bf4700666f6f25626172
______________________________________//__/____
address % ep1 % ep2
data ParamNotes (t :: T) Source #
Annotations for contract parameter declaration.
Following the Michelson specification, this type has the following invariants:
1. No entrypoint name is duplicated.
2. If default entrypoint is explicitly assigned, no "arm" remains uncallable.
Constructors
| ParamNotesUnsafe | |
Instances
| Eq (ParamNotes t) Source # | |
Defined in Michelson.Typed.Entrypoints | |
| Show (ParamNotes t) Source # | |
Defined in Michelson.Typed.Entrypoints Methods showsPrec :: Int -> ParamNotes t -> ShowS # show :: ParamNotes t -> String # showList :: [ParamNotes t] -> ShowS # | |
| Generic (ParamNotes t) Source # | |
Defined in Michelson.Typed.Entrypoints Associated Types type Rep (ParamNotes t) :: Type -> Type # | |
| NFData (ParamNotes t) Source # | |
Defined in Michelson.Typed.Entrypoints Methods rnf :: ParamNotes t -> () # | |
| type Rep (ParamNotes t) Source # | |
Defined in Michelson.Typed.Entrypoints type Rep (ParamNotes t) = D1 ('MetaData "ParamNotes" "Michelson.Typed.Entrypoints" "morley-1.9-inplace" 'False) (C1 ('MetaCons "ParamNotesUnsafe" 'PrefixI 'True) (S1 ('MetaSel ('Just "pnNotes") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (Notes t)) :*: S1 ('MetaSel ('Just "pnRootAnn") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 RootAnn))) | |
pattern ParamNotes :: Notes t -> RootAnn -> ParamNotes t Source #
starParamNotes :: SingI t => ParamNotes t Source #
Parameter without annotations.
data ParamEpError Source #
Errors specific to parameter type declaration (entrypoints).
Constructors
| ParamEpDuplicatedNames (NonEmpty EpName) | |
| ParamEpUncallableArm ArmCoords |
Instances
mkParamNotes :: Notes t -> RootAnn -> Either ParamEpError (ParamNotes t) Source #
Construct ParamNotes performing all necessary checks.
data EpLiftSequence (arg :: T) (param :: T) where Source #
Describes how to construct full contract parameter from given entrypoint argument.
This could be just wrapper over Value arg -> Value param, but we cannot
use Value type in this module easily.
Constructors
| EplArgHere :: EpLiftSequence arg arg | |
| EplWrapLeft :: (KnownT subparam, KnownT r) => EpLiftSequence arg subparam -> EpLiftSequence arg ('TOr subparam r) | |
| EplWrapRight :: (KnownT l, KnownT subparam) => EpLiftSequence arg subparam -> EpLiftSequence arg ('TOr l subparam) |
Instances
| Eq (EpLiftSequence arg param) Source # | |
Defined in Michelson.Typed.Entrypoints Methods (==) :: EpLiftSequence arg param -> EpLiftSequence arg param -> Bool # (/=) :: EpLiftSequence arg param -> EpLiftSequence arg param -> Bool # | |
| Show (EpLiftSequence arg param) Source # | |
Defined in Michelson.Typed.Entrypoints Methods showsPrec :: Int -> EpLiftSequence arg param -> ShowS # show :: EpLiftSequence arg param -> String # showList :: [EpLiftSequence arg param] -> ShowS # | |
| NFData (EpLiftSequence param arg) Source # | |
Defined in Michelson.Typed.Entrypoints Methods rnf :: EpLiftSequence param arg -> () # | |
| Buildable (EpLiftSequence arg param) Source # | |
Defined in Michelson.Typed.Entrypoints Methods build :: EpLiftSequence arg param -> Builder # | |
data EntrypointCallT (param :: T) (arg :: T) Source #
Reference for calling a specific entrypoint of type arg.
Constructors
| ParameterScope arg => EntrypointCall | |
Fields
| |
Instances
| Eq (EntrypointCallT param arg) Source # | |
Defined in Michelson.Typed.Entrypoints Methods (==) :: EntrypointCallT param arg -> EntrypointCallT param arg -> Bool # (/=) :: EntrypointCallT param arg -> EntrypointCallT param arg -> Bool # | |
| Show (EntrypointCallT param arg) Source # | |
Defined in Michelson.Typed.Entrypoints Methods showsPrec :: Int -> EntrypointCallT param arg -> ShowS # show :: EntrypointCallT param arg -> String # showList :: [EntrypointCallT param arg] -> ShowS # | |
| NFData (EntrypointCallT param arg) Source # | |
Defined in Michelson.Typed.Entrypoints Methods rnf :: EntrypointCallT param arg -> () # | |
| Buildable (EntrypointCallT param arg) Source # | |
Defined in Michelson.Typed.Entrypoints Methods build :: EntrypointCallT param arg -> Builder # | |
epcPrimitive :: forall p. (ParameterScope p, ForbidOr p) => EntrypointCallT p p Source #
Call parameter which has no entrypoints, always safe.
epcCallRootUnsafe :: ParameterScope param => EntrypointCallT param param Source #
Construct EntrypointCallT which calls no entrypoint and assumes that
there is no explicit "default" one.
Validity of such operation is not ensured.
data SomeEntrypointCallT (arg :: T) Source #
EntrypointCallT with hidden parameter type.
This requires argument to satisfy ParameterScope constraint.
Strictly speaking, entrypoint argument may one day start having different
set of constraints comparing to ones applied to parameter, but this seems
unlikely.
Constructors
| forall param.ParameterScope param => SomeEpc (EntrypointCallT param arg) |
Instances
| Eq (SomeEntrypointCallT arg) Source # | |
Defined in Michelson.Typed.Entrypoints Methods (==) :: SomeEntrypointCallT arg -> SomeEntrypointCallT arg -> Bool # (/=) :: SomeEntrypointCallT arg -> SomeEntrypointCallT arg -> Bool # | |
| Show (SomeEntrypointCallT arg) Source # | |
Defined in Michelson.Typed.Entrypoints Methods showsPrec :: Int -> SomeEntrypointCallT arg -> ShowS # show :: SomeEntrypointCallT arg -> String # showList :: [SomeEntrypointCallT arg] -> ShowS # | |
| NFData (SomeEntrypointCallT arg) Source # | |
Defined in Michelson.Typed.Entrypoints Methods rnf :: SomeEntrypointCallT arg -> () # | |
| Buildable (SomeEntrypointCallT arg) Source # | |
Defined in Michelson.Typed.Entrypoints Methods build :: SomeEntrypointCallT arg -> Builder # | |
sepcCallRootUnsafe :: ParameterScope param => SomeEntrypointCallT param Source #
Construct SomeEntrypointCallT which calls no entrypoint and assumes that
there is no explicit "default" one.
Validity of such operation is not ensured.
sepcPrimitive :: forall t. (ParameterScope t, ForbidOr t) => SomeEntrypointCallT t Source #
Call parameter which has no entrypoints, always safe.
sepcName :: SomeEntrypointCallT arg -> EpName Source #
type family ForbidOr (t :: T) :: Constraint where ... Source #
data MkEntrypointCallRes param where Source #
Constructors
| MkEntrypointCallRes :: ParameterScope arg => Notes arg -> EntrypointCallT param arg -> MkEntrypointCallRes param |
mkEntrypointCall :: ParameterScope param => EpName -> ParamNotes param -> Maybe (MkEntrypointCallRes param) Source #
Build EntrypointCallT.
Here we accept entrypoint name and type information for the parameter of target contract.
Returns Nothing if entrypoint is not found.
tyImplicitAccountParam :: ParamNotes 'TUnit Source #
Parameter type of implicit account.
Re-exports
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
| EpNameUnsafe | |
Instances
| Eq EpName Source # | |
| Ord EpName Source # | |
| Show EpName Source # | |
| Generic EpName Source # | |
| ToJSON EpName Source # | |
Defined in Michelson.Untyped.Entrypoints | |
| FromJSON EpName Source # | |
| NFData EpName Source # | |
Defined in Michelson.Untyped.Entrypoints | |
| Buildable EpName Source # | |
Defined in Michelson.Untyped.Entrypoints | |
| HasCLReader EpName Source # | |
Defined in Michelson.Untyped.Entrypoints | |
| type Rep EpName Source # | |
Defined in 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.
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.
epNameToRefAnn :: EpName -> FieldAnn Source #
Turn entrypoint name into annotation used as reference to entrypoint.
data EpNameFromRefAnnError Source #
Constructors
| InEpNameBadAnnotation FieldAnn |