{-# LANGUAGE UndecidableSuperClasses #-}
module Lorentz.Entrypoints.Core
( CanHaveEntrypoints
, EntrypointsDerivation (..)
, EpConstructionRes (..)
, EpCallingDesc (..)
, EpCallingStep (..)
, RequireAllUniqueEntrypoints
, ParameterHasEntrypoints (..)
, ParameterDeclaresEntrypoints
, GetParameterEpDerivation
, pepNotes
, pepCall
, pepDescs
, pepDescsWithDef
, AllParameterEntrypoints
, LookupParameterEntrypoint
, parameterEntrypointsToNotes
, GetEntrypointArg
, parameterEntrypointCall
, GetDefaultEntrypointArg
, parameterEntrypointCallDefault
, ForbidExplicitDefaultEntrypoint
, NoExplicitDefaultEntrypoint
, sepcCallRootChecked
, EntrypointRef (..)
, NiceEntrypointName
, eprName
, GetEntrypointArgCustom
, TrustEpName (..)
, HasEntrypointArg (..)
, HasDefEntrypointArg
, HasEntrypointOfType
, ParameterContainsEntrypoints
, parameterEntrypointCallCustom
, EpdNone
, (:>)
, RequireAllUniqueEntrypoints'
) where
import Data.Constraint ((\\))
import qualified Data.Kind as Kind
import Data.Typeable (typeRep)
import Data.Vinyl (Rec(..))
import Fcf (Eval, Exp)
import qualified Fcf
import qualified Fcf.Utils as Fcf
import Fmt (pretty)
import Michelson.Typed
import qualified Michelson.Untyped as U
import Util.Label
import Util.Type
import Util.TypeLits
import Lorentz.Annotation (FollowEntrypointFlag(..), HasAnnotation, getAnnotation)
import Lorentz.Constraints.Scopes
import Lorentz.Entrypoints.Helpers
class EntrypointsDerivation deriv cp where
type EpdAllEntrypoints deriv cp :: [(Symbol, Kind.Type)]
type EpdLookupEntrypoint deriv cp :: Symbol -> Exp (Maybe Kind.Type)
epdNotes :: (Notes (ToT cp), U.RootAnn)
epdCall
:: ParameterScope (ToT cp)
=> Label name
-> EpConstructionRes (ToT cp) (Eval (EpdLookupEntrypoint deriv cp name))
epdDescs :: Rec EpCallingDesc (EpdAllEntrypoints deriv cp)
type RequireAllUniqueEntrypoints' deriv cp =
RequireAllUnique
"entrypoint name"
(Eval (Fcf.Map Fcf.Fst $ EpdAllEntrypoints deriv cp))
type RequireAllUniqueEntrypoints cp =
RequireAllUniqueEntrypoints' (ParameterEntrypointsDerivation cp) cp
data EpConstructionRes (param :: T) (marg :: Maybe Kind.Type) where
EpConstructed
:: ParameterScope (ToT arg)
=> EpLiftSequence (ToT arg) param -> EpConstructionRes param ('Just arg)
EpConstructionFailed
:: EpConstructionRes param 'Nothing
data EpCallingDesc (info :: (Symbol, Kind.Type)) where
EpCallingDesc ::
{ EpCallingDesc '(name, arg) -> Proxy arg
epcdArg :: Proxy (arg :: Kind.Type)
, EpCallingDesc '(name, arg) -> EpName
epcdEntrypoint :: EpName
, EpCallingDesc '(name, arg) -> [EpCallingStep]
epcdSteps :: [EpCallingStep]
} -> EpCallingDesc '(name, arg)
deriving stock instance Show (EpCallingDesc info)
data EpCallingStep
= EpsWrapIn Text
deriving stock (Int -> EpCallingStep -> ShowS
[EpCallingStep] -> ShowS
EpCallingStep -> String
(Int -> EpCallingStep -> ShowS)
-> (EpCallingStep -> String)
-> ([EpCallingStep] -> ShowS)
-> Show EpCallingStep
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EpCallingStep] -> ShowS
$cshowList :: [EpCallingStep] -> ShowS
show :: EpCallingStep -> String
$cshow :: EpCallingStep -> String
showsPrec :: Int -> EpCallingStep -> ShowS
$cshowsPrec :: Int -> EpCallingStep -> ShowS
Show, EpCallingStep -> EpCallingStep -> Bool
(EpCallingStep -> EpCallingStep -> Bool)
-> (EpCallingStep -> EpCallingStep -> Bool) -> Eq EpCallingStep
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EpCallingStep -> EpCallingStep -> Bool
$c/= :: EpCallingStep -> EpCallingStep -> Bool
== :: EpCallingStep -> EpCallingStep -> Bool
$c== :: EpCallingStep -> EpCallingStep -> Bool
Eq)
class ( EntrypointsDerivation (ParameterEntrypointsDerivation cp) cp
, RequireAllUniqueEntrypoints cp
) =>
ParameterHasEntrypoints cp where
type ParameterEntrypointsDerivation cp :: Kind.Type
type ParameterDeclaresEntrypoints cp =
( If (CanHaveEntrypoints cp)
(ParameterHasEntrypoints cp)
(() :: Constraint)
, NiceParameter cp
, EntrypointsDerivation (GetParameterEpDerivation cp) cp
)
type GetParameterEpDerivation cp =
If (CanHaveEntrypoints cp)
(ParameterEntrypointsDerivation cp)
EpdNone
pepNotes :: forall cp. ParameterDeclaresEntrypoints cp => (Notes (ToT cp), U.RootAnn)
pepNotes :: (Notes (ToT cp), RootAnn)
pepNotes = EntrypointsDerivation (GetParameterEpDerivation cp) cp =>
(Notes (ToT cp), RootAnn)
forall k (deriv :: k) cp.
EntrypointsDerivation deriv cp =>
(Notes (ToT cp), RootAnn)
epdNotes @(GetParameterEpDerivation cp) @cp
pepCall
:: forall cp name.
(ParameterDeclaresEntrypoints cp, ParameterScope (ToT cp))
=> Label name
-> EpConstructionRes (ToT cp) (Eval (LookupParameterEntrypoint cp name))
pepCall :: Label name
-> EpConstructionRes
(ToT cp) (Eval (LookupParameterEntrypoint cp name))
pepCall = forall (name :: Symbol).
(EntrypointsDerivation (GetParameterEpDerivation cp) cp,
ParameterScope (ToT cp)) =>
Label name
-> EpConstructionRes
(ToT cp)
(Eval (EpdLookupEntrypoint (GetParameterEpDerivation cp) cp name))
forall k (deriv :: k) cp (name :: Symbol).
(EntrypointsDerivation deriv cp, ParameterScope (ToT cp)) =>
Label name
-> EpConstructionRes
(ToT cp) (Eval (EpdLookupEntrypoint deriv cp name))
epdCall @(GetParameterEpDerivation cp) @cp
pepDescs
:: forall cp.
(ParameterDeclaresEntrypoints cp)
=> Rec EpCallingDesc (AllParameterEntrypoints cp)
pepDescs :: Rec EpCallingDesc (AllParameterEntrypoints cp)
pepDescs = EntrypointsDerivation (GetParameterEpDerivation cp) cp =>
Rec
EpCallingDesc (EpdAllEntrypoints (GetParameterEpDerivation cp) cp)
forall k (deriv :: k) cp.
EntrypointsDerivation deriv cp =>
Rec EpCallingDesc (EpdAllEntrypoints deriv cp)
epdDescs @(GetParameterEpDerivation cp) @cp
pepDescsWithDef
:: forall cp.
(ParameterDeclaresEntrypoints cp)
=> [Some1 EpCallingDesc]
pepDescsWithDef :: [Some1 EpCallingDesc]
pepDescsWithDef = Rec
EpCallingDesc
(EpdAllEntrypoints
(If
(CanHaveEntrypoints cp)
(ParameterEntrypointsDerivation cp)
EpdNone)
cp)
-> [Some1 EpCallingDesc]
addDefaultIfImplicit (Rec
EpCallingDesc
(EpdAllEntrypoints
(If
(CanHaveEntrypoints cp)
(ParameterEntrypointsDerivation cp)
EpdNone)
cp)
-> [Some1 EpCallingDesc])
-> Rec
EpCallingDesc
(EpdAllEntrypoints
(If
(CanHaveEntrypoints cp)
(ParameterEntrypointsDerivation cp)
EpdNone)
cp)
-> [Some1 EpCallingDesc]
forall a b. (a -> b) -> a -> b
$ ParameterDeclaresEntrypoints cp =>
Rec EpCallingDesc (AllParameterEntrypoints cp)
forall cp.
ParameterDeclaresEntrypoints cp =>
Rec EpCallingDesc (AllParameterEntrypoints cp)
pepDescs @cp
where
addDefaultIfImplicit :: Rec
EpCallingDesc
(EpdAllEntrypoints
(If
(CanHaveEntrypoints cp)
(ParameterEntrypointsDerivation cp)
EpdNone)
cp)
-> [Some1 EpCallingDesc]
addDefaultIfImplicit descsRec :: Rec
EpCallingDesc
(EpdAllEntrypoints
(If
(CanHaveEntrypoints cp)
(ParameterEntrypointsDerivation cp)
EpdNone)
cp)
descsRec =
let descs :: [Some1 EpCallingDesc]
descs = Rec
EpCallingDesc
(EpdAllEntrypoints
(If
(CanHaveEntrypoints cp)
(ParameterEntrypointsDerivation cp)
EpdNone)
cp)
-> [Some1 EpCallingDesc]
forall k (f :: k -> *) (l :: [k]). Rec f l -> [Some1 f]
recordToSomeList Rec
EpCallingDesc
(EpdAllEntrypoints
(If
(CanHaveEntrypoints cp)
(ParameterEntrypointsDerivation cp)
EpdNone)
cp)
descsRec
hasDef :: Bool
hasDef =
(Element [Some1 EpCallingDesc] -> Bool)
-> [Some1 EpCallingDesc] -> Bool
forall t. Container t => (Element t -> Bool) -> t -> Bool
any (\(Some1 EpCallingDesc{..}) -> EpName
epcdEntrypoint EpName -> EpName -> Bool
forall a. Eq a => a -> a -> Bool
== EpName
DefEpName) [Some1 EpCallingDesc]
descs
in if Bool
hasDef
then [Some1 EpCallingDesc]
descs
else EpCallingDesc '(Any, cp) -> Some1 EpCallingDesc
forall k (f :: k -> *) (a :: k). f a -> Some1 f
Some1 $WEpCallingDesc :: forall arg (name :: Symbol).
Proxy arg
-> EpName -> [EpCallingStep] -> EpCallingDesc '(name, arg)
EpCallingDesc
{ epcdArg :: Proxy cp
epcdArg = Proxy cp
forall k (t :: k). Proxy t
Proxy @cp
, epcdEntrypoint :: EpName
epcdEntrypoint = EpName
DefEpName
, epcdSteps :: [EpCallingStep]
epcdSteps = []
} Some1 EpCallingDesc
-> [Some1 EpCallingDesc] -> [Some1 EpCallingDesc]
forall a. a -> [a] -> [a]
: [Some1 EpCallingDesc]
descs
type family AllParameterEntrypoints (cp :: Kind.Type)
:: [(Symbol, Kind.Type)] where
AllParameterEntrypoints cp =
EpdAllEntrypoints (GetParameterEpDerivation cp) cp
type family LookupParameterEntrypoint (cp :: Kind.Type)
:: Symbol -> Exp (Maybe Kind.Type) where
LookupParameterEntrypoint cp =
EpdLookupEntrypoint (GetParameterEpDerivation cp) cp
parameterEntrypointsToNotes
:: forall cp. ParameterDeclaresEntrypoints cp
=> ParamNotes (ToT cp)
parameterEntrypointsToNotes :: ParamNotes (ToT cp)
parameterEntrypointsToNotes =
let (notes :: Notes (ToT cp)
notes, ra :: RootAnn
ra) = ParameterDeclaresEntrypoints cp => (Notes (ToT cp), RootAnn)
forall cp.
ParameterDeclaresEntrypoints cp =>
(Notes (ToT cp), RootAnn)
pepNotes @cp
in case Notes (ToT cp)
-> RootAnn -> Either ParamEpError (ParamNotes (ToT cp))
forall (t :: T).
Notes t -> RootAnn -> Either ParamEpError (ParamNotes t)
mkParamNotes Notes (ToT cp)
notes RootAnn
ra of
Right n :: ParamNotes (ToT cp)
n -> ParamNotes (ToT cp)
n
Left e :: ParamEpError
e -> Text -> ParamNotes (ToT cp)
forall a. HasCallStack => Text -> a
error (Text -> ParamNotes (ToT cp)) -> Text -> ParamNotes (ToT cp)
forall a b. (a -> b) -> a -> b
$ [Text] -> Text
forall a. Monoid a => [a] -> a
mconcat
[ "Lorentz unexpectedly compiled into contract with \
\illegal parameter declaration.\n"
, "Parameter: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> TypeRep -> Text
forall b a. (Show a, IsString b) => a -> b
show (Proxy cp -> TypeRep
forall k (proxy :: k -> *) (a :: k).
Typeable a =>
proxy a -> TypeRep
typeRep (Proxy cp
forall k (t :: k). Proxy t
Proxy @cp)) Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> "\n"
, "Derived annotations: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Notes (ToT cp) -> Text
forall b a. (Show a, IsString b) => a -> b
show Notes (ToT cp)
notes Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> "\n"
, "Failure reason: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> ParamEpError -> Text
forall a b. (Buildable a, FromBuilder b) => a -> b
pretty ParamEpError
e
]
parameterEntrypointCall
:: forall cp name.
ParameterDeclaresEntrypoints cp
=> Label name
-> EntrypointCall cp (GetEntrypointArg cp name)
parameterEntrypointCall :: Label name -> EntrypointCall cp (GetEntrypointArg cp name)
parameterEntrypointCall label :: Label name
label@Label name
Label =
((KnownValue cp,
(KnownT (ToT cp), FailOnOperationFound (ContainsOp (ToT cp)),
FailOnNestedBigMapsFound (ContainsNestedBigMaps (ToT cp))))
:- (KnownT (ToT cp), HasNoOp (ToT cp),
HasNoNestedBigMaps (ToT cp)))
-> ((KnownT (ToT cp), HasNoOp (ToT cp),
HasNoNestedBigMaps (ToT cp)) =>
EntrypointCallT
(ToT cp)
(ToT
(Eval
(FromMaybe
(TypeError ...)
(Eval
(EpdLookupEntrypoint
(If
(CanHaveEntrypoints cp)
(ParameterEntrypointsDerivation cp)
EpdNone)
cp
name))))))
-> EntrypointCallT
(ToT cp)
(ToT
(Eval
(FromMaybe
(TypeError ...)
(Eval
(EpdLookupEntrypoint
(If
(CanHaveEntrypoints cp)
(ParameterEntrypointsDerivation cp)
EpdNone)
cp
name)))))
forall (c :: Constraint) e r. HasDict c e => e -> (c => r) -> r
withDict ((KnownValue cp,
(KnownT (ToT cp), FailOnOperationFound (ContainsOp (ToT cp)),
FailOnNestedBigMapsFound (ContainsNestedBigMaps (ToT cp))))
:- (KnownT (ToT cp), HasNoOp (ToT cp), HasNoNestedBigMaps (ToT cp))
forall a. NiceParameter a :- ParameterScope (ToT a)
niceParameterEvi @cp) (((KnownT (ToT cp), HasNoOp (ToT cp),
HasNoNestedBigMaps (ToT cp)) =>
EntrypointCallT
(ToT cp)
(ToT
(Eval
(FromMaybe
(TypeError ...)
(Eval
(EpdLookupEntrypoint
(If
(CanHaveEntrypoints cp)
(ParameterEntrypointsDerivation cp)
EpdNone)
cp
name))))))
-> EntrypointCall cp (GetEntrypointArg cp name))
-> ((KnownT (ToT cp), HasNoOp (ToT cp),
HasNoNestedBigMaps (ToT cp)) =>
EntrypointCallT
(ToT cp)
(ToT
(Eval
(FromMaybe
(TypeError ...)
(Eval
(EpdLookupEntrypoint
(If
(CanHaveEntrypoints cp)
(ParameterEntrypointsDerivation cp)
EpdNone)
cp
name))))))
-> EntrypointCall cp (GetEntrypointArg cp name)
forall a b. (a -> b) -> a -> b
$
case Label name
-> EpConstructionRes
(ToT cp) (Eval (LookupParameterEntrypoint cp name))
forall cp (name :: Symbol).
(ParameterDeclaresEntrypoints cp, ParameterScope (ToT cp)) =>
Label name
-> EpConstructionRes
(ToT cp) (Eval (LookupParameterEntrypoint cp name))
pepCall @cp Label name
label of
EpConstructed liftSeq :: EpLiftSequence (ToT arg) (ToT cp)
liftSeq -> $WEntrypointCall :: forall (param :: T) (arg :: T).
ParameterScope arg =>
EpName
-> Proxy param
-> EpLiftSequence arg param
-> EntrypointCallT param arg
EntrypointCall
{ epcName :: EpName
epcName = (KnownSymbol name, HasCallStack) => EpName
forall (ctor :: Symbol). (KnownSymbol ctor, HasCallStack) => EpName
ctorNameToEp @name
, epcParamProxy :: Proxy (ToT cp)
epcParamProxy = Proxy (ToT cp)
forall k (t :: k). Proxy t
Proxy
, epcLiftSequence :: EpLiftSequence (ToT arg) (ToT cp)
epcLiftSequence = EpLiftSequence (ToT arg) (ToT cp)
liftSeq
}
EpConstructionFailed ->
Text
-> EntrypointCallT
(ToT cp)
(ToT
(Eval
(FromMaybe
(TypeError ...)
(Eval
(EpdLookupEntrypoint
(If
(CanHaveEntrypoints cp)
(ParameterEntrypointsDerivation cp)
EpdNone)
cp
name)))))
forall a. HasCallStack => Text -> a
error "impossible"
type GetEntrypointArg cp name = Eval
( Fcf.LiftM2
Fcf.FromMaybe
(Fcf.TError ('Text "Entrypoint not found: " ':<>: 'ShowType name ':$$:
'Text "In contract parameter `" ':<>: 'ShowType cp ':<>: 'Text "`"))
(LookupParameterEntrypoint cp name)
)
type DefaultEpName = "Default"
parameterEntrypointCallDefault
:: forall cp.
(ParameterDeclaresEntrypoints cp)
=> EntrypointCall cp (GetDefaultEntrypointArg cp)
parameterEntrypointCallDefault :: EntrypointCall cp (GetDefaultEntrypointArg cp)
parameterEntrypointCallDefault =
((KnownValue cp,
(KnownT (ToT cp), FailOnOperationFound (ContainsOp (ToT cp)),
FailOnNestedBigMapsFound (ContainsNestedBigMaps (ToT cp))))
:- (KnownT (ToT cp), HasNoOp (ToT cp),
HasNoNestedBigMaps (ToT cp)))
-> ((KnownT (ToT cp), HasNoOp (ToT cp),
HasNoNestedBigMaps (ToT cp)) =>
EntrypointCallT
(ToT cp)
(ToT
(Eval
(FromMaybe
cp
(Eval
(EpdLookupEntrypoint
(If
(CanHaveEntrypoints cp)
(ParameterEntrypointsDerivation cp)
EpdNone)
cp
DefaultEpName))))))
-> EntrypointCallT
(ToT cp)
(ToT
(Eval
(FromMaybe
cp
(Eval
(EpdLookupEntrypoint
(If
(CanHaveEntrypoints cp)
(ParameterEntrypointsDerivation cp)
EpdNone)
cp
DefaultEpName)))))
forall (c :: Constraint) e r. HasDict c e => e -> (c => r) -> r
withDict ((KnownValue cp,
(KnownT (ToT cp), FailOnOperationFound (ContainsOp (ToT cp)),
FailOnNestedBigMapsFound (ContainsNestedBigMaps (ToT cp))))
:- (KnownT (ToT cp), HasNoOp (ToT cp), HasNoNestedBigMaps (ToT cp))
forall a. NiceParameter a :- ParameterScope (ToT a)
niceParameterEvi @cp) (((KnownT (ToT cp), HasNoOp (ToT cp),
HasNoNestedBigMaps (ToT cp)) =>
EntrypointCallT
(ToT cp)
(ToT
(Eval
(FromMaybe
cp
(Eval
(EpdLookupEntrypoint
(If
(CanHaveEntrypoints cp)
(ParameterEntrypointsDerivation cp)
EpdNone)
cp
DefaultEpName))))))
-> EntrypointCall cp (GetDefaultEntrypointArg cp))
-> ((KnownT (ToT cp), HasNoOp (ToT cp),
HasNoNestedBigMaps (ToT cp)) =>
EntrypointCallT
(ToT cp)
(ToT
(Eval
(FromMaybe
cp
(Eval
(EpdLookupEntrypoint
(If
(CanHaveEntrypoints cp)
(ParameterEntrypointsDerivation cp)
EpdNone)
cp
DefaultEpName))))))
-> EntrypointCall cp (GetDefaultEntrypointArg cp)
forall a b. (a -> b) -> a -> b
$
case Label DefaultEpName
-> EpConstructionRes
(ToT cp) (Eval (LookupParameterEntrypoint cp DefaultEpName))
forall cp (name :: Symbol).
(ParameterDeclaresEntrypoints cp, ParameterScope (ToT cp)) =>
Label name
-> EpConstructionRes
(ToT cp) (Eval (LookupParameterEntrypoint cp name))
pepCall @cp (forall a. IsLabel DefaultEpName a => a
forall (x :: Symbol) a. IsLabel x a => a
fromLabel @DefaultEpName) of
EpConstructed liftSeq :: EpLiftSequence (ToT arg) (ToT cp)
liftSeq -> $WEntrypointCall :: forall (param :: T) (arg :: T).
ParameterScope arg =>
EpName
-> Proxy param
-> EpLiftSequence arg param
-> EntrypointCallT param arg
EntrypointCall
{ epcName :: EpName
epcName = EpName
DefEpName
, epcParamProxy :: Proxy (ToT cp)
epcParamProxy = Proxy (ToT cp)
forall k (t :: k). Proxy t
Proxy
, epcLiftSequence :: EpLiftSequence (ToT arg) (ToT cp)
epcLiftSequence = EpLiftSequence (ToT arg) (ToT cp)
liftSeq
}
EpConstructionFailed ->
$WEntrypointCall :: forall (param :: T) (arg :: T).
ParameterScope arg =>
EpName
-> Proxy param
-> EpLiftSequence arg param
-> EntrypointCallT param arg
EntrypointCall
{ epcName :: EpName
epcName = EpName
DefEpName
, epcParamProxy :: Proxy (ToT cp)
epcParamProxy = Proxy (ToT cp)
forall k (t :: k). Proxy t
Proxy
, epcLiftSequence :: EpLiftSequence (ToT cp) (ToT cp)
epcLiftSequence = EpLiftSequence (ToT cp) (ToT cp)
forall (arg :: T). EpLiftSequence arg arg
EplArgHere
}
type GetDefaultEntrypointArg cp = Eval
( Fcf.LiftM2
Fcf.FromMaybe
(Fcf.Pure cp)
(LookupParameterEntrypoint cp DefaultEpName)
)
type ForbidExplicitDefaultEntrypoint cp = Eval
(Fcf.LiftM3
Fcf.UnMaybe
(Fcf.Pure (Fcf.Pure (() :: Constraint)))
(Fcf.TError
('Text "Parameter used here must have no explicit \"default\" entrypoint" ':$$:
'Text "In parameter type `" ':<>: 'ShowType cp ':<>: 'Text "`"
)
)
(LookupParameterEntrypoint cp DefaultEpName)
)
type NoExplicitDefaultEntrypoint cp =
Eval (LookupParameterEntrypoint cp DefaultEpName) ~ 'Nothing
sepcCallRootChecked
:: forall cp.
(NiceParameter cp, ForbidExplicitDefaultEntrypoint cp)
=> SomeEntrypointCall cp
sepcCallRootChecked :: SomeEntrypointCall cp
sepcCallRootChecked = (KnownT (ToT cp), HasNoOp (ToT cp), HasNoNestedBigMaps (ToT cp)) =>
SomeEntrypointCall cp
forall (param :: T).
ParameterScope param =>
SomeEntrypointCallT param
sepcCallRootUnsafe ((KnownT (ToT cp), HasNoOp (ToT cp),
HasNoNestedBigMaps (ToT cp)) =>
SomeEntrypointCall cp)
-> ((KnownValue cp,
(KnownT (ToT cp), FailOnOperationFound (ContainsOp (ToT cp)),
FailOnNestedBigMapsFound (ContainsNestedBigMaps (ToT cp))))
:- (KnownT (ToT cp), HasNoOp (ToT cp),
HasNoNestedBigMaps (ToT cp)))
-> SomeEntrypointCall cp
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ (KnownValue cp,
(KnownT (ToT cp), FailOnOperationFound (ContainsOp (ToT cp)),
FailOnNestedBigMapsFound (ContainsNestedBigMaps (ToT cp))))
:- (KnownT (ToT cp), HasNoOp (ToT cp), HasNoNestedBigMaps (ToT cp))
forall a. NiceParameter a :- ParameterScope (ToT a)
niceParameterEvi @cp
where
_validUsage :: Dict (ForbidExplicitDefaultEntrypoint cp)
_validUsage = ForbidExplicitDefaultEntrypoint cp =>
Dict (ForbidExplicitDefaultEntrypoint cp)
forall (a :: Constraint). a => Dict a
Dict @(ForbidExplicitDefaultEntrypoint cp)
data EntrypointRef (mname :: Maybe Symbol) where
CallDefault :: EntrypointRef 'Nothing
Call :: NiceEntrypointName name => EntrypointRef ('Just name)
type NiceEntrypointName name = (KnownSymbol name, ForbidDefaultName name)
type family ForbidDefaultName (name :: Symbol) :: Constraint where
ForbidDefaultName "Default" =
TypeError ('Text "Calling `Default` entrypoint is not allowed here")
ForbidDefaultName _ = ()
eprName :: forall mname. EntrypointRef mname -> EpName
eprName :: EntrypointRef mname -> EpName
eprName = \case
CallDefault -> EpName
DefEpName
Call | (_ :: Proxy ('Just name)) <- Proxy mname
forall k (t :: k). Proxy t
Proxy @mname ->
FieldAnn -> Maybe EpName
epNameFromParamAnn ((KnownSymbol name, HasCallStack) => FieldAnn
forall (ctor :: Symbol).
(KnownSymbol ctor, HasCallStack) =>
FieldAnn
ctorNameToAnn @name)
Maybe EpName -> EpName -> EpName
forall a. Maybe a -> a -> a
?: Text -> EpName
forall a. HasCallStack => Text -> a
error "Empty constructor-entrypoint name"
parameterEntrypointCallCustom
:: forall cp mname.
(ParameterDeclaresEntrypoints cp)
=> EntrypointRef mname
-> EntrypointCall cp (GetEntrypointArgCustom cp mname)
parameterEntrypointCallCustom :: EntrypointRef mname
-> EntrypointCall cp (GetEntrypointArgCustom cp mname)
parameterEntrypointCallCustom = \case
CallDefault ->
ParameterDeclaresEntrypoints cp =>
EntrypointCall cp (GetDefaultEntrypointArg cp)
forall cp.
ParameterDeclaresEntrypoints cp =>
EntrypointCall cp (GetDefaultEntrypointArg cp)
parameterEntrypointCallDefault @cp
Call | (_ :: Proxy ('Just name)) <- Proxy mname
forall k (t :: k). Proxy t
Proxy @mname ->
Label name -> EntrypointCall cp (GetEntrypointArg cp name)
forall cp (name :: Symbol).
ParameterDeclaresEntrypoints cp =>
Label name -> EntrypointCall cp (GetEntrypointArg cp name)
parameterEntrypointCall @cp (forall a. IsLabel name a => a
forall (x :: Symbol) a. IsLabel x a => a
fromLabel @name)
type family GetEntrypointArgCustom cp mname :: Kind.Type where
GetEntrypointArgCustom cp 'Nothing = GetDefaultEntrypointArg cp
GetEntrypointArgCustom cp ('Just name) = GetEntrypointArg cp name
class HasEntrypointArg cp name arg where
useHasEntrypointArg :: name -> (Dict (ParameterScope (ToT arg)), EpName)
type HasDefEntrypointArg cp defEpName defArg =
( defEpName ~ EntrypointRef 'Nothing
, HasEntrypointArg cp defEpName defArg
)
instance
(GetEntrypointArgCustom cp mname ~ arg, ParameterDeclaresEntrypoints cp) =>
HasEntrypointArg cp (EntrypointRef mname) arg where
useHasEntrypointArg :: EntrypointRef mname -> (Dict (ParameterScope (ToT arg)), EpName)
useHasEntrypointArg epRef :: EntrypointRef mname
epRef =
((KnownValue cp,
(KnownT (ToT cp), FailOnOperationFound (ContainsOp (ToT cp)),
FailOnNestedBigMapsFound (ContainsNestedBigMaps (ToT cp))))
:- (KnownT (ToT cp), HasNoOp (ToT cp),
HasNoNestedBigMaps (ToT cp)))
-> ((KnownT (ToT cp), HasNoOp (ToT cp),
HasNoNestedBigMaps (ToT cp)) =>
(Dict (ParameterScope (ToT arg)), EpName))
-> (Dict (ParameterScope (ToT arg)), EpName)
forall (c :: Constraint) e r. HasDict c e => e -> (c => r) -> r
withDict ((KnownValue cp,
(KnownT (ToT cp), FailOnOperationFound (ContainsOp (ToT cp)),
FailOnNestedBigMapsFound (ContainsNestedBigMaps (ToT cp))))
:- (KnownT (ToT cp), HasNoOp (ToT cp), HasNoNestedBigMaps (ToT cp))
forall a. NiceParameter a :- ParameterScope (ToT a)
niceParameterEvi @cp) (((KnownT (ToT cp), HasNoOp (ToT cp),
HasNoNestedBigMaps (ToT cp)) =>
(Dict (ParameterScope (ToT arg)), EpName))
-> (Dict (ParameterScope (ToT arg)), EpName))
-> ((KnownT (ToT cp), HasNoOp (ToT cp),
HasNoNestedBigMaps (ToT cp)) =>
(Dict (ParameterScope (ToT arg)), EpName))
-> (Dict (ParameterScope (ToT arg)), EpName)
forall a b. (a -> b) -> a -> b
$
case EntrypointRef mname
-> EntrypointCall cp (GetEntrypointArgCustom cp mname)
forall cp (mname :: Maybe Symbol).
ParameterDeclaresEntrypoints cp =>
EntrypointRef mname
-> EntrypointCall cp (GetEntrypointArgCustom cp mname)
parameterEntrypointCallCustom @cp EntrypointRef mname
epRef of
EntrypointCall{} -> (Dict (ParameterScope (ToT arg))
forall (a :: Constraint). a => Dict a
Dict, EntrypointRef mname -> EpName
forall (mname :: Maybe Symbol). EntrypointRef mname -> EpName
eprName EntrypointRef mname
epRef)
newtype TrustEpName = TrustEpName EpName
instance (NiceParameter arg) =>
HasEntrypointArg cp TrustEpName arg where
useHasEntrypointArg :: TrustEpName -> (Dict (ParameterScope (ToT arg)), EpName)
useHasEntrypointArg (TrustEpName epName :: EpName
epName) = (Dict (ParameterScope (ToT arg))
forall (a :: Constraint). a => Dict a
Dict, EpName
epName) (ParameterScope (ToT arg) =>
(Dict (ParameterScope (ToT arg)), EpName))
-> (NiceParameter arg :- ParameterScope (ToT arg))
-> (Dict (ParameterScope (ToT arg)), EpName)
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ NiceParameter arg :- ParameterScope (ToT arg)
forall a. NiceParameter a :- ParameterScope (ToT a)
niceParameterEvi @arg
type HasEntrypointOfType param con exp
= (GetEntrypointArgCustom param ('Just con) ~ exp, ParameterDeclaresEntrypoints param)
data NamedEp = NamedEp Symbol Kind.Type
type n :> ty = 'NamedEp n ty
infixr 0 :>
type family
ParameterContainsEntrypoints param (fields :: [NamedEp]) :: Constraint
where
ParameterContainsEntrypoints _ '[] = ()
ParameterContainsEntrypoints param ((n :> ty) ': rest) =
(HasEntrypointOfType param n ty, ParameterContainsEntrypoints param rest)
data EpdNone
instance (HasAnnotation cp) => EntrypointsDerivation EpdNone cp where
type EpdAllEntrypoints EpdNone cp = '[]
type EpdLookupEntrypoint EpdNone cp = Fcf.ConstFn 'Nothing
epdNotes :: (Notes (ToT cp), RootAnn)
epdNotes = (FollowEntrypointFlag -> Notes (ToT cp)
forall a. HasAnnotation a => FollowEntrypointFlag -> Notes (ToT a)
getAnnotation @cp FollowEntrypointFlag
FollowEntrypoint, RootAnn
forall k (a :: k). Annotation a
U.noAnn)
epdCall :: Label name
-> EpConstructionRes
(ToT cp) (Eval (EpdLookupEntrypoint EpdNone cp name))
epdCall _ = EpConstructionRes
(ToT cp) (Eval (EpdLookupEntrypoint EpdNone cp name))
forall (param :: T). EpConstructionRes param 'Nothing
EpConstructionFailed
epdDescs :: Rec EpCallingDesc (EpdAllEntrypoints EpdNone cp)
epdDescs = Rec EpCallingDesc (EpdAllEntrypoints EpdNone cp)
forall u (a :: u -> *). Rec a '[]
RNil