module Test.Cleveland.Lorentz.Types
( ContractHandle (..)
, chNiceParameterEvi
, chNiceStorageEvi
, ToStorageType (..)
, NiceParameter
, NiceParameterFull
, NiceStorage
, NicePackedValue
, NiceUnpackedValue
, ToAddress
, toAddress
) where
import Data.Constraint (Dict(..), mapDict)
import Fmt (Buildable(..), (+|), (|+))
import Lorentz.Address
import Lorentz.Constraints
import Morley.Michelson.Typed qualified as T
data ContractHandle (cp :: Type) (st :: Type) (vd :: Type) =
(NiceParameter cp, NiceStorage st, NiceViewsDescriptor vd) =>
ContractHandle
{ ContractHandle cp st vd -> Text
chContractName :: Text
, ContractHandle cp st vd -> Address
chAddress :: Address
}
deriving stock instance Show (ContractHandle cp st vd)
instance Buildable (ContractHandle cp st vd) where
build :: ContractHandle cp st vd -> Builder
build (ContractHandle Text
name Address
addr) =
Builder
"<handler to '" Builder -> Builder -> Builder
forall b. FromBuilder b => Builder -> Builder -> b
+| Text
name Text -> Builder -> Builder
forall a b. (Buildable a, FromBuilder b) => a -> Builder -> b
|+ Builder
"' / " Builder -> Builder -> Builder
forall b. FromBuilder b => Builder -> Builder -> b
+| Address
addr Address -> Builder -> Builder
forall a b. (Buildable a, FromBuilder b) => a -> Builder -> b
|+ Builder
">"
instance ToAddress (ContractHandle cp st vd) where
toAddress :: ContractHandle cp st vd -> Address
toAddress = ContractHandle cp st vd -> Address
forall cp st vd. ContractHandle cp st vd -> Address
chAddress
instance (cp' ~ cp, vd ~ vd') => ToTAddress cp' vd' (ContractHandle cp st vd) where
toTAddress :: ContractHandle cp st vd -> TAddress cp' vd'
toTAddress = Address -> TAddress cp' vd'
forall cp vd a. ToTAddress cp vd a => a -> TAddress cp vd
toTAddress (Address -> TAddress cp' vd')
-> (ContractHandle cp st vd -> Address)
-> ContractHandle cp st vd
-> TAddress cp' vd'
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ContractHandle cp st vd -> Address
forall a. ToAddress a => a -> Address
toAddress
instance ToContractRef arg (TAddress cp vd) => ToContractRef arg (ContractHandle cp st vd) where
toContractRef :: ContractHandle cp st vd -> ContractRef arg
toContractRef = TAddress cp vd -> ContractRef arg
forall cp contract.
(ToContractRef cp contract, HasCallStack) =>
contract -> ContractRef cp
toContractRef (TAddress cp vd -> ContractRef arg)
-> (ContractHandle cp st vd -> TAddress cp vd)
-> ContractHandle cp st vd
-> ContractRef arg
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall vd a. ToTAddress cp vd a => a -> TAddress cp vd
forall cp vd a. ToTAddress cp vd a => a -> TAddress cp vd
toTAddress @cp
chNiceParameterEvi :: forall param st vd. ContractHandle param st vd -> Dict (T.ParameterScope $ T.ToT st)
chNiceParameterEvi :: ContractHandle param st vd -> Dict (ParameterScope $ ToT st)
chNiceParameterEvi ContractHandle{} = (((SingI (ToT st), WellTyped (ToT st),
FailOnOperationFound (ContainsOp (ToT st)),
FailOnNestedBigMapsFound (ContainsNestedBigMaps (ToT st))),
KnownValue st)
:- (ParameterScope $ ToT st))
-> Dict
((SingI (ToT st), WellTyped (ToT st),
FailOnOperationFound (ContainsOp (ToT st)),
FailOnNestedBigMapsFound (ContainsNestedBigMaps (ToT st))),
KnownValue st)
-> Dict (ParameterScope $ ToT st)
forall (a :: Constraint) (b :: Constraint).
(a :- b) -> Dict a -> Dict b
mapDict (((SingI (ToT st), WellTyped (ToT st),
FailOnOperationFound (ContainsOp (ToT st)),
FailOnNestedBigMapsFound (ContainsNestedBigMaps (ToT st))),
KnownValue st)
:- (ParameterScope $ ToT st)
forall a. NiceParameter a :- ParameterScope (ToT a)
niceParameterEvi @st) Dict
((SingI (ToT st), WellTyped (ToT st),
FailOnOperationFound (ContainsOp (ToT st)),
FailOnNestedBigMapsFound (ContainsNestedBigMaps (ToT st))),
KnownValue st)
forall (a :: Constraint). a => Dict a
Dict
chNiceStorageEvi :: forall param st vd. ContractHandle param st vd -> Dict (T.StorageScope $ T.ToT st)
chNiceStorageEvi :: ContractHandle param st vd -> Dict (StorageScope $ ToT st)
chNiceStorageEvi ContractHandle{} = (((SingI (ToT st), WellTyped (ToT st),
FailOnOperationFound (ContainsOp (ToT st)),
FailOnNestedBigMapsFound (ContainsNestedBigMaps (ToT st)),
FailOnContractFound (ContainsContract (ToT st))),
KnownValue st)
:- (StorageScope $ ToT st))
-> Dict
((SingI (ToT st), WellTyped (ToT st),
FailOnOperationFound (ContainsOp (ToT st)),
FailOnNestedBigMapsFound (ContainsNestedBigMaps (ToT st)),
FailOnContractFound (ContainsContract (ToT st))),
KnownValue st)
-> Dict (StorageScope $ ToT st)
forall (a :: Constraint) (b :: Constraint).
(a :- b) -> Dict a -> Dict b
mapDict (((SingI (ToT st), WellTyped (ToT st),
FailOnOperationFound (ContainsOp (ToT st)),
FailOnNestedBigMapsFound (ContainsNestedBigMaps (ToT st)),
FailOnContractFound (ContainsContract (ToT st))),
KnownValue st)
:- (StorageScope $ ToT st)
forall a. NiceStorage a :- StorageScope (ToT a)
niceStorageEvi @st) Dict
((SingI (ToT st), WellTyped (ToT st),
FailOnOperationFound (ContainsOp (ToT st)),
FailOnNestedBigMapsFound (ContainsNestedBigMaps (ToT st)),
FailOnContractFound (ContainsContract (ToT st))),
KnownValue st)
forall (a :: Constraint). a => Dict a
Dict
class ToAddress addr => ToStorageType st addr where
pickNiceStorage :: addr -> Dict (NiceStorage st)
instance NiceStorage st => ToStorageType st Address where
pickNiceStorage :: Address -> Dict (NiceStorage st)
pickNiceStorage Address
_ = Dict (NiceStorage st)
forall (a :: Constraint). a => Dict a
Dict
instance (st ~ st') => ToStorageType st' (ContractHandle cp st vd) where
pickNiceStorage :: ContractHandle cp st vd -> Dict (NiceStorage st')
pickNiceStorage ContractHandle{} = Dict (NiceStorage st')
forall (a :: Constraint). a => Dict a
Dict