Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
On-chain view utilities.
Synopsis
- callView :: forall name arg ret cp st vd m caps. (MonadCleveland caps m, HasView vd name arg ret, NiceParameter arg, NiceViewable ret, NiceStorage ret, NiceParameter cp, KnownSymbol name, HasRPCRepr ret, IsoValue (AsRPC ret)) => ContractHandle cp st vd -> Label name -> arg -> m (AsRPC ret)
- unsafeCallView :: forall ret arg name addr m caps. (MonadCleveland caps m, NiceParameter arg, NiceViewable ret, NiceStorage ret, KnownSymbol name, HasRPCRepr ret, IsoValue (AsRPC ret), ToContractAddress addr) => addr -> Label name -> arg -> m (AsRPC ret)
- runnerContract :: forall name arg ret. (NiceParameter arg, NiceViewable ret, NiceStorage ret, KnownSymbol name) => ContractAddress -> Contract arg (Maybe ret) ()
Documentation
:: forall name arg ret cp st vd m caps. (MonadCleveland caps m, HasView vd name arg ret, NiceParameter arg, NiceViewable ret, NiceStorage ret, NiceParameter cp, KnownSymbol name, HasRPCRepr ret, IsoValue (AsRPC ret)) | |
=> ContractHandle cp st vd | Contract to call. |
-> Label name | View name. Use |
-> arg | Parameter to pass to the view. |
-> m (AsRPC ret) |
Call an on-chain view by name. The existence of the view is checked at
compile time. If you don't have compile-time information about views, see
unsafeCallView
.
Example:
callView contract #sum (123, -321)
:: forall ret arg name addr m caps. (MonadCleveland caps m, NiceParameter arg, NiceViewable ret, NiceStorage ret, KnownSymbol name, HasRPCRepr ret, IsoValue (AsRPC ret), ToContractAddress addr) | |
=> addr | Contract to call. |
-> Label name | View name. Use |
-> arg | Parameter to pass to the view. |
-> m (AsRPC ret) |
Version of callView
that doesn't check if the view exists in the type.
You'll have to specify the return type. You can use TypeApplications
syntax
for that.
If the view doesn't exist or has incorrect type, a test failure will be thrown.
Note that first type argument is return type, the second is parameter type. The reason for this inversion is you often only need to specify the return type, while the parameter type can be either inferred or explicitly specified with a type annotation on the parameter argument value.
Examples:
unsafeCallView @() contract #id ()
Calls view id
with argument unit
and return type unit
.
unsafeCallView @(Integer, MText) contract #query [mt|hello|]
Calls view query
with argument string
and return type pair int string
.
unsafeCallView @Integer contract #sum (123 :: Natural, -321 :: Integer)
Calls view sum
with argument pair nat int
and return type int
. Type
annotations are required due to polymorphic numeric literals.
This last example could also be written as
unsafeCallView @Integer @(Natural, Integer) contract #sum (123, -321)
runnerContract :: forall name arg ret. (NiceParameter arg, NiceViewable ret, NiceStorage ret, KnownSymbol name) => ContractAddress -> Contract arg (Maybe ret) () Source #
Contract that calls a view and saves the result to storage.