Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Machinery for the variadic transfer
function.
Synopsis
- type family FTransferResult emit :: Type where ...
- data TransferResult
- data WithContractEvents = WithContractEvents
- class DoTransfer mode where
- doTransfer :: (HasCallStack, MonadOpsInternal m) => GenericTransferData mode -> m [ContractEvent]
- class (forall mod am emit a. (SingI emit, DoTransfer mod, a ~ FTransferResult emit) => TransferFunc mod emit am (m a)) => MonadTransfer m
- type family MatchModes from to :: Constraint where ...
- type family NoDuplicateEmit am :: Constraint where ...
- type family NoDuplicateAmount am :: Constraint where ...
- class TransferFunc (mode :: TransferMode) (emit :: TransferResult) (hasAmount :: HasAmount) r where
- transfer'r :: HasCallStack => GenericTransferData mode -> r
- data HasAmount
- type family InitialTransferMode addr :: TransferMode where ...
- data GenericTransferData mode = GenericTransferData {
- gtdAddr :: L1Address
- gtdCall :: GenericCall mode
- gtdAmount :: Mutez
- data GenericCall mode where
- CheckedCall :: (NiceParameter epArg, HasEntrypointArg param epRef epArg) => epRef -> epArg -> GenericCall ('Checked param)
- UncheckedCall :: NiceParameter epArg => EpName -> epArg -> GenericCall 'Unchecked
- UnspecifiedCall :: GenericCall ('Incomplete param)
- data TransferMode
- data STransferResult :: TransferResult -> Type where
- type family TransferWithEmitsSym0 :: TransferResult where ...
- type family TransferIgnoreResultSym0 :: TransferResult where ...
- transfer :: forall addr r. (HasCallStack, TransferFunc ('Incomplete (InitialTransferMode addr)) 'TransferIgnoreResult 'HasNoAmount r, ToL1Address addr) => addr -> r
- initialData :: ToL1Address addr => addr -> GenericTransferData ('Incomplete (InitialTransferMode addr))
- runTransfer :: (HasCallStack, MonadOpsInternal m) => TransferData -> m [ContractEvent]
- calling :: forall mname. EntrypointRef mname -> forall epArg param. (NiceParameter epArg, HasEntrypointArg param (EntrypointRef mname) epArg) => epArg -> GenericCall ('Checked param)
- unsafeCalling :: EpName -> forall epArg. NiceParameter epArg => epArg -> GenericCall 'Unchecked
Documentation
type family FTransferResult emit :: Type where ... Source #
Type family encoding the actual transfer
result depending on
TransferResult
data TransferResult Source #
Simple flag to track whether we want to return list of emitted events.
Instances
SingKind TransferResult Source # | |
Defined in Test.Cleveland.Internal.Actions.Transfer type Demote TransferResult = (r :: Type) # fromSing :: forall (a :: TransferResult). Sing a -> Demote TransferResult # toSing :: Demote TransferResult -> SomeSing TransferResult # | |
SingI 'TransferIgnoreResult Source # | |
Defined in Test.Cleveland.Internal.Actions.Transfer | |
SingI 'TransferWithEmits Source # | |
Defined in Test.Cleveland.Internal.Actions.Transfer sing :: Sing 'TransferWithEmits # | |
type Demote TransferResult Source # | |
Defined in Test.Cleveland.Internal.Actions.Transfer | |
type Sing Source # | |
Defined in Test.Cleveland.Internal.Actions.Transfer |
data WithContractEvents Source #
transfer
flag to signal we want contract events emitted by EMIT
returned. Passed in the variadic part of transfer
, e.g.
transfer addr [tz|123u|] WithContractEvents $ calling (ep @"Entrypoint") ()
Instances
(TransferFunc mode 'TransferWithEmits am r, NoDuplicateEmit emit, emit ~ 'TransferIgnoreResult) => TransferFunc mode emit am (WithContractEvents -> r) Source # | |
Defined in Test.Cleveland.Internal.Actions.Transfer transfer'r :: GenericTransferData mode -> WithContractEvents -> r Source # |
class DoTransfer mode where Source #
Typeclass abstracting making the actual transfer.
doTransfer :: (HasCallStack, MonadOpsInternal m) => GenericTransferData mode -> m [ContractEvent] Source #
Instances
DoTransfer 'Unchecked Source # | |
Defined in Test.Cleveland.Internal.Actions.Transfer doTransfer :: (HasCallStack, MonadOpsInternal m) => GenericTransferData 'Unchecked -> m [ContractEvent] Source # | |
DoTransfer ('Checked param) Source # | |
Defined in Test.Cleveland.Internal.Actions.Transfer doTransfer :: (HasCallStack, MonadOpsInternal m) => GenericTransferData ('Checked param) -> m [ContractEvent] Source # | |
HasEntrypointArg param (EntrypointRef ('Nothing :: Maybe Symbol)) () => DoTransfer ('Incomplete ('Checked param)) Source # | |
Defined in Test.Cleveland.Internal.Actions.Transfer doTransfer :: (HasCallStack, MonadOpsInternal m) => GenericTransferData ('Incomplete ('Checked param)) -> m [ContractEvent] Source # | |
DoTransfer ('Incomplete 'Unchecked) Source # | |
Defined in Test.Cleveland.Internal.Actions.Transfer doTransfer :: (HasCallStack, MonadOpsInternal m) => GenericTransferData ('Incomplete 'Unchecked) -> m [ContractEvent] Source # |
class (forall mod am emit a. (SingI emit, DoTransfer mod, a ~ FTransferResult emit) => TransferFunc mod emit am (m a)) => MonadTransfer m Source #
A convenient synonym class to require the terminating instance for a given monad without leaking too much implementation detail.
Instances
(forall (mod :: TransferMode) (am :: HasAmount) (emit :: TransferResult) a. (SingI emit, DoTransfer mod, a ~ FTransferResult emit) => TransferFunc mod emit am (m a)) => MonadTransfer m Source # | |
Defined in Test.Cleveland.Internal.Actions.Transfer |
type family MatchModes from to :: Constraint where ... Source #
Type family that defines possible mode conversions in TransferFunc
.
Basically, we don't allow unchecked calls to become checked, and we require
that checked calls do not change the parameter type mid-way.
MatchModes ('Incomplete _) 'Unchecked = () | |
MatchModes ('Incomplete ('Checked param1)) ('Checked param2) = param1 ~ param2 | |
MatchModes ('Incomplete 'Unchecked) _ = TypeError ('Text "Can not use this type of call with an untyped address." :$$: 'Text "Try using 'unsafeCalling' instead.") | |
MatchModes _ _ = TypeError ('Text "Call is specified more than once.") |
type family NoDuplicateEmit am :: Constraint where ... Source #
Type family raising a type error on TransferWithEmits
argument. Used to
improve error reporting for TransferFunc
instances with equality
constraints.
NoDuplicateEmit 'TransferWithEmits = TypeError ('Text "WithContractEvents is specified more than once.") | |
NoDuplicateEmit 'TransferIgnoreResult = () |
type family NoDuplicateAmount am :: Constraint where ... Source #
Type family raising a type error on HasAmount
argument. Used to improve
error reporting for TransferFunc
instances with equality constraints.
NoDuplicateAmount 'HasAmount = TypeError ('Text "Amount is specified more than once.") | |
NoDuplicateAmount 'HasNoAmount = () |
class TransferFunc (mode :: TransferMode) (emit :: TransferResult) (hasAmount :: HasAmount) r where Source #
The class implementing a guarded "printf trick" for the transfer
function.
If you see GHC asking for this constraint, you most likely need to add
MonadTransfer
constraint on the return monad instead.
transfer'r :: HasCallStack => GenericTransferData mode -> r Source #
Instances
type family InitialTransferMode addr :: TransferMode where ... Source #
Choose the initial TransferMode
based on the type of destination address.
InitialTransferMode ContractAddress = 'Unchecked | |
InitialTransferMode ImplicitAddress = 'Unchecked | |
InitialTransferMode L1Address = 'Unchecked | |
InitialTransferMode (L1TAddress param _) = 'Checked param | |
InitialTransferMode (ContractHandle param _ _) = 'Checked param |
data GenericTransferData mode Source #
Generic version of TransferData
GenericTransferData | |
|
data GenericCall mode where Source #
Data-kind for call specification.
CheckedCall :: (NiceParameter epArg, HasEntrypointArg param epRef epArg) => epRef -> epArg -> GenericCall ('Checked param) | |
UncheckedCall :: NiceParameter epArg => EpName -> epArg -> GenericCall 'Unchecked | |
UnspecifiedCall :: GenericCall ('Incomplete param) |
Instances
(TransferFunc modeTo emit am r, MatchModes modeFrom modeTo) => TransferFunc modeFrom emit am (GenericCall modeTo -> r) Source # | |
Defined in Test.Cleveland.Internal.Actions.Transfer transfer'r :: GenericTransferData modeFrom -> GenericCall modeTo -> r Source # |
data TransferMode Source #
Data-kind for tracking what type of call we're making.
data STransferResult :: TransferResult -> Type where Source #
type family TransferWithEmitsSym0 :: TransferResult where ... Source #
type family TransferIgnoreResultSym0 :: TransferResult where ... Source #
transfer :: forall addr r. (HasCallStack, TransferFunc ('Incomplete (InitialTransferMode addr)) 'TransferIgnoreResult 'HasNoAmount r, ToL1Address addr) => addr -> r Source #
Base method for making a transfer.
You can specify additional arguments after the destination address to modify
optional transfer arguments. Those can either be Mutez
to specify transfer
amount (0 by default), or a specially constructed call descriptor. The order
is arbitrary, but it is usually more convenient to specify transfer amount
first. For example:
transfer addr [tz|123u|] $ calling (ep @"Entrypoint") () transfer addr [tz|123u|]
If the call isn't specified, then the default entrypoint will be called with
()
, i.e.
transfer addr
is functionally the same as
transfer addr $ calling def ()
If the address in the first argument is untyped, the transfer is unchecked.
Unchecked transfers must use unsafeCalling
for the call specification. You
can also use unsafeCalling
with typed address to force an unchecked
transfer.
See Test.Cleveland.Internal.Actions.Transfer for further explanation of the interface.
By default, the sender is the account associated with the moneybag
alias.
This can be overridden with the --cleveland-moneybag-alias
command line
option, the TASTY_CLEVELAND_MONEYBAG_ALIAS
env var, or withSender
.
initialData :: ToL1Address addr => addr -> GenericTransferData ('Incomplete (InitialTransferMode addr)) Source #
Construct initial GenericTransferData
for a given address.
runTransfer :: (HasCallStack, MonadOpsInternal m) => TransferData -> m [ContractEvent] Source #
Make the transfer given TransferData
calling :: forall mname. EntrypointRef mname -> forall epArg param. (NiceParameter epArg, HasEntrypointArg param (EntrypointRef mname) epArg) => epArg -> GenericCall ('Checked param) Source #
Safely call an entrypoint specified by the first argument with the provided parameter.
The first character of the entrypoint name must be capitalized.
This is "safe" in the sense that the contract is checked if it indeed has the specified entrypoint and the entrypoint in question accepts the argument provided, a type error is raised otherwise.
transfer addr $ calling (ep @"Entrypoint") ()
Use CallDefault
or def
to call the default entrypoint.
transfer addr $ calling def ()
Notice that type variables for entrypoint argument and full parameter are specified after the entrypoint. This is done so more for readability. F. ex.:
transfer addr $ calling def @Integer 123
This does also marginally simplify type inference in the case of partial application.
unsafeCalling :: EpName -> forall epArg. NiceParameter epArg => epArg -> GenericCall 'Unchecked Source #
Unsafely call an entrypoint specified by the first argument with the provided parameter.
This is "unsafe" in the sense that there is no check that the contract indeed has the specified entrypoint or that the entrypoint in question accepts the argument provided.
Also, no compile-time checks are performed on the entrypoint name, so it can be malformed.
transfer addr $ unsafeCalling (ep @"Entrypoint") ()
Overloaded labels are supported with unsafeCalling
, so you can specify the
entrypoint as an overloaded label:
transfer addr $ unsafeCalling #entrypoint ()
Use DefEpName
or def
to call the default entrypoint.
Notice that the type variable for the entrypoint argument is specified after the entrypoint. This is done so more for readability. F. ex.:
transfer addr $ calling def @Integer 123
This does also marginally simplify type inference in the case of partial application.