-- SPDX-FileCopyrightText: 2022 Oxhead Alpha
-- SPDX-License-Identifier: LicenseRef-MIT-OA

-- | This module contains a type family for converting a type to its RPC representation,
-- and TemplateHaskell functions for deriving RPC representations for custom types.
module Morley.AsRPC
  ( TAsRPC
  , HasRPCRepr(..)
  , deriveRPC
  , deriveRPCWithStrategy
  , deriveManyRPC
  , deriveManyRPCWithStrategy
  -- * Conversions
  , valueAsRPC
  , replaceBigMapIds
  , notesAsRPC
  -- * Entailments
  , rpcSingIEvi
  , rpcHasNoOpEvi
  , rpcHasNoBigMapEvi
  , rpcHasNoNestedBigMapsEvi
  , rpcHasNoContractEvi
  , rpcStorageScopeEvi
  ) where

import Prelude hiding (Type)
import Prelude qualified

import Control.Lens.Plated (universe)
import Data.Constraint (Dict(..), (***), (:-)(Sub), (\\))
import Data.Generics (everything, mkQ)
import Data.List qualified as List ((\\))
import Data.Map qualified as Map
import Data.Singletons (Sing, withSingI)
import Data.Text qualified as T
import GHC.Generics qualified as G
import Language.Haskell.TH
  (Con(InfixC, NormalC, RecC), Cxt, Dec(DataD, NewtypeD, TySynD, TySynInstD),
  DerivStrategy(AnyclassStrategy), Info(TyConI), Kind, Loc(loc_module), Name, Q, TyLit(StrTyLit),
  TySynEqn(..), TyVarBndr(..), Type(..), cxt, instanceD, location, mkName, nameBase, ppr, reify,
  reifyInstances, standaloneDerivWithStrategyD)
import Language.Haskell.TH.ReifyMany (reifyManyTyCons)
import Language.Haskell.TH.ReifyMany.Internal (decConcreteNames)

import Morley.Michelson.Text (MText)
import Morley.Michelson.Typed
  (BigMap, BigMapId, ContractPresence(ContractAbsent), ContractRef, EpAddress, HasNoBigMap,
  HasNoContract, HasNoNestedBigMaps, HasNoOp, IsoValue, Notes(..), OpPresence(..), Operation,
  SingI(sing), SingT(..), StorageScope, T(..), ToT, Value, Value'(..), WellTyped,
  checkContractTypePresence, checkOpPresence, withDict)
import Morley.Tezos.Address (Address, TxRollupL2Address)
import Morley.Tezos.Core (ChainId, Mutez, Timestamp)
import Morley.Tezos.Crypto
import Morley.Util.CustomGeneric
  (GenericStrategy, customGeneric', deriveFullType, haskellBalanced,
  mangleGenericStrategyConstructors, mangleGenericStrategyFields, reifyDataType)
import Morley.Util.Named hiding (Name)
import Morley.Util.TH (isTypeAlias, lookupTypeNameOrFail)

{-# ANN module ("HLint: ignore Avoid lambda using `infix`" :: Text) #-}

-- $setup
-- >>> import Morley.Michelson.Typed
-- >>> import Morley.Michelson.Text (MText)

----------------------------------------------------------------------------
-- TAsRPC
----------------------------------------------------------------------------

{- | A type-level function that maps a Michelson type to its Tezos RPC representation.

For example, when we retrieve a contract's storage using the Tezos RPC,
all its @big_map@s will be replaced by @nat@, representing a big_map ID.

>>> :k! TAsRPC ('TBigMap 'TInt 'TString)
...
= 'TNat

>>> :k! TAsRPC ('TList ('TBigMap 'TInt 'TString))
...
= 'TList 'TNat

>>> :k! TAsRPC ('TPair 'TString ('TPair 'TAddress ('TBigMap 'TInt 'TString)))
...
= 'TPair 'TString ('TPair 'TAddress 'TNat)


NB: As far as we are aware, details of RPC representation of Michelson
types are not documented. We know empirically that @big_map@s are
represented as their ids, and are the only type with an explicitly
different representation.

Whether @TAsRPC@ needs to propagate into type parameters then depends on
whether a value can hold big_map values.

* Values of type @option a@, @list a@, @pair a b@, and @or a b@ can
  contain big_map values, so their RPC representations are @option (TAsRPC a)@,
  @list (TAsRPC a)@, @pair (TAsRPC a) (TAsRPC b)@ and @or (TAsRPC a) (TAsRPC b)@.
* The keys of a @map k v@ cannot be big_maps, but the values can, so its
  RPC representation is @map k (TAsRPC v)@.
* Values of type @set a@ cannot contain big_maps, so its RPC
  representation is just @set a@.
* Values of type @contract a@ cannot contain big_maps either, because
  it's just a wrapper for an address and an entrypoint name, so its RPC
  representation is just @contract a@. The same reasoning applies to
  @ticket a@ and @lambda a b@.

-}
type TAsRPC :: T -> T
type family TAsRPC t where
  TAsRPC 'TKey = 'TKey
  TAsRPC 'TUnit = 'TUnit
  TAsRPC 'TSignature = 'TSignature
  TAsRPC 'TChainId = 'TChainId
  TAsRPC ('TOption t) = 'TOption (TAsRPC t)
  TAsRPC ('TList t) = 'TList (TAsRPC t)
  TAsRPC ('TSet t) = 'TSet t
  TAsRPC 'TOperation = 'TOperation
  TAsRPC ('TContract t) = 'TContract t
  TAsRPC ('TTicket t) = 'TTicket t
  TAsRPC ('TPair t1 t2) = 'TPair (TAsRPC t1) (TAsRPC t2)
  TAsRPC ('TOr t1 t2) = 'TOr (TAsRPC t1) (TAsRPC t2)
  TAsRPC ('TLambda t1 t2) = 'TLambda t1 t2
  TAsRPC ('TMap k v) = 'TMap k (TAsRPC v)
  TAsRPC ('TBigMap _ _) = 'TNat
  TAsRPC 'TInt = 'TInt
  TAsRPC 'TNat = 'TNat
  TAsRPC 'TString = 'TString
  TAsRPC 'TBytes = 'TBytes
  TAsRPC 'TMutez = 'TMutez
  TAsRPC 'TBool = 'TBool
  TAsRPC 'TKeyHash = 'TKeyHash
  TAsRPC 'TTimestamp = 'TTimestamp
  TAsRPC 'TAddress = 'TAddress
  TAsRPC 'TNever = 'TNever
  TAsRPC 'TBls12381Fr = 'TBls12381Fr
  TAsRPC 'TBls12381G1 = 'TBls12381G1
  TAsRPC 'TBls12381G2 = 'TBls12381G2
  TAsRPC 'TChest = 'TChest
  TAsRPC 'TChestKey = 'TChestKey
  TAsRPC 'TTxRollupL2Address = 'TTxRollupL2Address
  TAsRPC ('TSaplingState n) = ('TSaplingState n)
  TAsRPC ('TSaplingTransaction n) = ('TSaplingTransaction n)

----------------------------------------------------------------------------
-- AsRPC
----------------------------------------------------------------------------

{- | A type-level function that maps a type to its Tezos RPC representation.

For example, when we retrieve a contract's storage using the Tezos RPC, all its 'BigMap's will be replaced
by 'BigMapId's.

So if a contract has a storage of type @T@, when we call the Tezos RPC
to retrieve it, we must deserialize the micheline expression to the type @AsRPC T@.

> AsRPC (BigMap Integer MText) ~ BigMapId Integer MText
> AsRPC [BigMap Integer MText] ~ [BigMapId Integer MText]
> AsRPC (MText, (Address, BigMap Integer MText)) ~ (MText, (Address, BigMapId Integer MText))

The following law must hold:

> TAsRPC (ToT t) ~ ToT (AsRPC t)

In other words, `ToT` and `AsRPC`/`TAsRPC` must be commutative.

@
   Storage ----------(applying ToT)-------------> ToT Storage
      |                                                |
      |                                                |
      |                                                |
(applying AsRPC)                                (applying TAsRPC)
      |                                                |
      |                                                |
      |                                                |
      |                                                V
      |                                        TAsRPC (ToT Storage)
      V                                                ~
AsRPC Storage ------(applying ToT)-----------> ToT (AsRPC Storage)
@


This law ensures that we can go from some type @Storage@ to @AsRPC Storage@ by
composing @fromVal . valueAsRPC . toVal@.

@
   Storage ------------(toVal)--------------> Value (ToT Storage)
      |                                                |
      |                                                |
      |                                                |
(fromVal . valueAsRPC . toVal)                    (valueAsRPC)
      |                                                |
      |                                                |
      |                                                |
      |                                                V
      |                                   Value (TAsRPC (ToT Storage))
      V                                                ~
AsRPC Storage <--------(fromVal)--------- Value (ToT (AsRPC Storage))
@

-}
class (TAsRPC (ToT t) ~ ToT (AsRPC t)) => HasRPCRepr (t :: Prelude.Type) where
  type AsRPC t :: Prelude.Type

-- Morley types

-- Note: We don't recursively apply @AsRPC@ to @k@ or @v@ because
-- bigmaps cannot contain nested bigmaps.
-- If this constraint is ever lifted, we'll have to change this instance
-- to @BigMapId k (AsRPC v)@
instance HasRPCRepr (BigMap k v) where type AsRPC (BigMap k v) = BigMapId k v
instance HasRPCRepr (Value t) where type AsRPC (Value t) = Value (TAsRPC t)
instance HasRPCRepr Integer where type AsRPC Integer = Integer
instance HasRPCRepr Natural where type AsRPC Natural = Natural
instance HasRPCRepr MText where type AsRPC MText = MText
instance HasRPCRepr Bool where type AsRPC Bool = Bool
instance HasRPCRepr ByteString where type AsRPC ByteString = ByteString
instance HasRPCRepr Mutez where type AsRPC Mutez = Mutez
instance HasRPCRepr KeyHash where type AsRPC KeyHash = KeyHash
instance HasRPCRepr Timestamp where type AsRPC Timestamp = Timestamp
instance HasRPCRepr Address where type AsRPC Address = Address
instance HasRPCRepr EpAddress where type AsRPC EpAddress = EpAddress
instance HasRPCRepr PublicKey where type AsRPC PublicKey = PublicKey
instance HasRPCRepr Signature where type AsRPC Signature = Signature
instance HasRPCRepr ChainId where type AsRPC ChainId = ChainId
instance HasRPCRepr Bls12381Fr where type AsRPC Bls12381Fr = Bls12381Fr
instance HasRPCRepr Bls12381G1 where type AsRPC Bls12381G1 = Bls12381G1
instance HasRPCRepr Bls12381G2 where type AsRPC Bls12381G2 = Bls12381G2
instance HasRPCRepr () where type AsRPC () = ()
instance HasRPCRepr a => HasRPCRepr [a] where
  type AsRPC [a] = [AsRPC a]
instance HasRPCRepr a => HasRPCRepr (Maybe a) where
  type AsRPC (Maybe a) = Maybe (AsRPC a)
instance (HasRPCRepr l, HasRPCRepr r) => HasRPCRepr (Either l r) where
  type AsRPC (Either l r) = Either (AsRPC l) (AsRPC r)
instance (HasRPCRepr a, HasRPCRepr b) => HasRPCRepr (a, b) where
  type AsRPC (a, b) = (AsRPC a, AsRPC b)
instance HasRPCRepr (Set a) where
  type AsRPC (Set a) = Set a
instance HasRPCRepr v => HasRPCRepr (Map k v) where
  type AsRPC (Map k v) = Map k (AsRPC v)
instance HasRPCRepr Operation where
  type AsRPC Operation = Operation
instance HasRPCRepr a => HasRPCRepr (Identity a) where
  type AsRPC (Identity a) = Identity (AsRPC a)
instance HasRPCRepr a => HasRPCRepr (NamedF Identity a name) where
  type AsRPC (NamedF Identity a name) = NamedF Identity (AsRPC a) name
instance HasRPCRepr a => HasRPCRepr (NamedF Maybe a name) where
  type AsRPC (NamedF Maybe a name) = NamedF Maybe (AsRPC a) name
instance Each '[HasRPCRepr] '[a, b, c] => HasRPCRepr (a, b, c) where
  type AsRPC (a, b, c) = (AsRPC a, AsRPC b, AsRPC c)
instance Each '[HasRPCRepr] '[a, b, c, d] => HasRPCRepr (a, b, c, d) where
  type AsRPC (a, b, c, d) = (AsRPC a, AsRPC b, AsRPC c, AsRPC d)
instance Each '[HasRPCRepr] '[a, b, c, d, e] => HasRPCRepr (a, b, c, d, e) where
  type AsRPC (a, b, c, d, e) = (AsRPC a, AsRPC b, AsRPC c, AsRPC d, AsRPC e)
instance Each '[HasRPCRepr] '[a, b, c, d, e, f] => HasRPCRepr (a, b, c, d, e, f) where
  type AsRPC (a, b, c, d, e, f) = (AsRPC a, AsRPC b, AsRPC c, AsRPC d, AsRPC e, AsRPC f)
instance Each '[HasRPCRepr] '[a, b, c, d, e, f, g] => HasRPCRepr (a, b, c, d, e, f, g) where
  type AsRPC (a, b, c, d, e, f, g) = (AsRPC a, AsRPC b, AsRPC c, AsRPC d, AsRPC e, AsRPC f, AsRPC g)
instance HasRPCRepr (ContractRef arg) where
  type AsRPC (ContractRef arg) = ContractRef arg
instance HasRPCRepr Chest where
  type AsRPC Chest = Chest
instance HasRPCRepr ChestKey where
  type AsRPC ChestKey = ChestKey
instance HasRPCRepr TxRollupL2Address where
  type AsRPC TxRollupL2Address = TxRollupL2Address

----------------------------------------------------------------------------
-- Derive RPC repr
----------------------------------------------------------------------------

-- | Derive an RPC representation for a type, as well as instances for 'Generic', 'IsoValue' and 'HasRPCRepr'.
--
-- > data ExampleStorage a b = ExampleStorage
-- >   { esField1 :: Integer
-- >   , esField2 :: [BigMap Integer MText]
-- >   , esField3 :: a
-- >   }
-- >   deriving stock Generic
-- >   deriving anyclass IsoValue
-- >
-- > deriveRPC "ExampleStorage"
--
-- Will generate:
--
-- > data ExampleStorageRPC a b = ExampleStorageRPC
-- >   { esField1RPC :: AsRPC Integer
-- >   , esField2RPC :: AsRPC [BigMap Integer MText]
-- >   , esField3RPC :: AsRPC a
-- >   }
-- >
-- > instance HasRPCRepr a => HasRPCRepr (ExampleStorage a b) where
-- >   type AsRPC (ExampleStorage a b) = ExampleStorageRPC a b
-- > deriving anyclass instance (IsoValue (AsRPC a), IsoValue (AsRPC b)) => IsoValue (ExampleStorageRPC a b)
-- > instance Generic (ExampleStorageRPC a b) where
-- >   ...
deriveRPC :: String -> Q [Dec]
deriveRPC :: String -> Q [Dec]
deriveRPC String
typeStr = String -> GenericStrategy -> Q [Dec]
deriveRPCWithStrategy String
typeStr GenericStrategy
haskellBalanced

-- | Recursively enumerate @data@, @newtype@ and @type@ declarations,
-- and derives an RPC representation for each type that doesn't yet have one.
--
-- You can also pass in a list of types for which you _don't_ want
-- an RPC representation to be derived.
--
-- In this example, 'deriveManyRPC' will generate an RPC
-- representation for @A@ and @B@,
-- but not for @C@ (because we explicitly said we don't want one)
-- or @D@ (because it already has one).
--
-- > data B = B
-- > data C = C
-- > data D = D
-- > deriveRPC "D"
-- >
-- > data A = A B C D
-- > deriveManyRPC "A" ["C"]
deriveManyRPC :: String -> [String] -> Q [Dec]
deriveManyRPC :: String -> [String] -> Q [Dec]
deriveManyRPC String
typeStr [String]
skipTypes =
  String -> [String] -> GenericStrategy -> Q [Dec]
deriveManyRPCWithStrategy String
typeStr [String]
skipTypes GenericStrategy
haskellBalanced

-- | Same as 'deriveManyRPC', but uses a custom strategy for deriving a 'Generic' instance.
deriveManyRPCWithStrategy :: String -> [String] -> GenericStrategy -> Q [Dec]
deriveManyRPCWithStrategy :: String -> [String] -> GenericStrategy -> Q [Dec]
deriveManyRPCWithStrategy String
typeStr [String]
skipTypes GenericStrategy
gs = do
  [Name]
skipTypeNames <- (String -> Q Name) -> [String] -> Q [Name]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse String -> Q Name
lookupTypeNameOrFail [String]
skipTypes
  Name
typeName <- String -> Q Name
lookupTypeNameOrFail String
typeStr
  Q Bool -> Q () -> Q ()
forall (m :: * -> *). Monad m => m Bool -> m () -> m ()
whenM (Name -> Q Bool
isTypeAlias Name
typeName) (Q () -> Q ()) -> Q () -> Q ()
forall a b. (a -> b) -> a -> b
$ String -> Q ()
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Q ()) -> String -> Q ()
forall a b. (a -> b) -> a -> b
$ String
typeStr String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
" is a 'type' alias but not 'data' or 'newtype'."
  [Name]
allTypeNames <- Name -> Q [Name]
findWithoutInstance Name
typeName
  [[Dec]] -> [Dec]
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join ([[Dec]] -> [Dec]) -> Q [[Dec]] -> Q [Dec]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Name] -> (Name -> Q [Dec]) -> Q [[Dec]]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM ([Name]
allTypeNames [Name] -> [Name] -> [Name]
forall a. Eq a => [a] -> [a] -> [a]
List.\\ [Name]
skipTypeNames) \Name
name -> Name -> GenericStrategy -> Q [Dec]
deriveRPCWithStrategy' Name
name GenericStrategy
gs
  where

    -- | Recursively enumerate @data@, @newtype@ and @type@ declarations,
    -- and returns the names of only @data@ and @newtype@ of those that
    -- don't yet have an 'AsRPC' instance. Type aliases don't need instances
    -- and respectively there is no need to derive 'AsRPC' for them.
    findWithoutInstance :: Name -> Q [Name]
    findWithoutInstance :: Name -> Q [Name]
findWithoutInstance Name
typeName =
      ((Name, Info) -> Name) -> [(Name, Info)] -> [Name]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Name, Info) -> Name
forall a b. (a, b) -> a
fst ([(Name, Info)] -> [Name]) -> Q [(Name, Info)] -> Q [Name]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
        ((Name, Dec) -> Q (Bool, [Name])) -> [Name] -> Q [(Name, Info)]
reifyManyTyCons
          (\(Name
name, Dec
dec) ->
            Q Bool -> Q (Bool, [Name]) -> Q (Bool, [Name]) -> Q (Bool, [Name])
forall (m :: * -> *) a. Monad m => m Bool -> m a -> m a -> m a
ifM (Name -> Q Bool
isTypeAlias Name
name)
              ((Bool, [Name]) -> Q (Bool, [Name])
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Bool
False, Dec -> [Name]
decConcreteNames Dec
dec))
              (Q Bool -> Q (Bool, [Name]) -> Q (Bool, [Name]) -> Q (Bool, [Name])
forall (m :: * -> *) a. Monad m => m Bool -> m a -> m a -> m a
ifM (Name -> Q Bool
hasRPCInstance Name
name)
                ((Bool, [Name]) -> Q (Bool, [Name])
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Bool
False, []))
                ((Bool, [Name]) -> Q (Bool, [Name])
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Bool
True, Dec -> [Name]
decConcreteNames Dec
dec)))
          )
          [Name
typeName]

    hasRPCInstance :: Name -> Q Bool
    hasRPCInstance :: Name -> Q Bool
hasRPCInstance Name
typeName = do
      Name -> Q (Maybe Type)
deriveFullTypeFromName Name
typeName Q (Maybe Type) -> (Maybe Type -> Q Bool) -> Q Bool
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
        Maybe Type
Nothing ->
          String -> Q Bool
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Q Bool) -> String -> Q Bool
forall a b. (a -> b) -> a -> b
$ String
"Found a field with a type that is neither a 'data' nor a 'newtype' nor a 'type': "
            String -> String -> String
forall a. Semigroup a => a -> a -> a
<> Name -> String
forall b a. (PrettyShow a, Show a, IsString b) => a -> b
show Name
typeName
        Just Type
typ ->
          Bool -> Bool
not (Bool -> Bool) -> ([Dec] -> Bool) -> [Dec] -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Dec] -> Bool
forall t. Container t => t -> Bool
null ([Dec] -> Bool) -> Q [Dec] -> Q Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Name -> [Type] -> Q [Dec]
reifyInstances ''AsRPC [Type
typ]

    -- | Given a type name, return the corresponding type expression
    -- (applied to any type variables, if necessary).
    --
    -- For example, assuming a data type like @data F a b = ...@ exists in the type environment,
    -- then @deriveFullTypeFromName ''F@ will return the type expression @[t|F a b|]@.
    --
    -- Note that only @data@, @newtype@ and @type@ declarations are supported at the moment.
    deriveFullTypeFromName :: Name -> Q (Maybe Type)
    deriveFullTypeFromName :: Name -> Q (Maybe Type)
deriveFullTypeFromName Name
typeName = do
      Info
typeInfo <- Name -> Q Info
reify Name
typeName
      case Info
typeInfo of
        TyConI (DataD [Type]
_ Name
_ [TyVarBndr ()]
vars Maybe Type
mKind [Con]
_ [DerivClause]
_) -> Type -> Maybe Type
forall a. a -> Maybe a
Just (Type -> Maybe Type) -> Q Type -> Q (Maybe Type)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Name -> Maybe Type -> [TyVarBndr ()] -> Q Type
forall flag. Name -> Maybe Type -> [TyVarBndr flag] -> Q Type
deriveFullType Name
typeName Maybe Type
mKind [TyVarBndr ()]
vars
        TyConI (NewtypeD [Type]
_ Name
_ [TyVarBndr ()]
vars Maybe Type
mKind Con
_ [DerivClause]
_) -> Type -> Maybe Type
forall a. a -> Maybe a
Just (Type -> Maybe Type) -> Q Type -> Q (Maybe Type)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Name -> Maybe Type -> [TyVarBndr ()] -> Q Type
forall flag. Name -> Maybe Type -> [TyVarBndr flag] -> Q Type
deriveFullType Name
typeName Maybe Type
mKind [TyVarBndr ()]
vars
        TyConI (TySynD Name
_ [TyVarBndr ()]
vars Type
_) -> Type -> Maybe Type
forall a. a -> Maybe a
Just (Type -> Maybe Type) -> Q Type -> Q (Maybe Type)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Name -> Maybe Type -> [TyVarBndr ()] -> Q Type
forall flag. Name -> Maybe Type -> [TyVarBndr flag] -> Q Type
deriveFullType Name
typeName Maybe Type
forall a. Maybe a
Nothing [TyVarBndr ()]
vars
        Info
_ -> Maybe Type -> Q (Maybe Type)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe Type
forall a. Maybe a
Nothing

-- | Same as 'deriveRPC', but uses a custom strategy for deriving a 'Generic' instance.
deriveRPCWithStrategy :: String -> GenericStrategy -> Q [Dec]
deriveRPCWithStrategy :: String -> GenericStrategy -> Q [Dec]
deriveRPCWithStrategy String
typeStr GenericStrategy
gs = do
  Name
typeName <- String -> Q Name
lookupTypeNameOrFail String
typeStr
  Q Bool -> Q () -> Q ()
forall (m :: * -> *). Monad m => m Bool -> m () -> m ()
whenM (Name -> Q Bool
isTypeAlias Name
typeName) (Q () -> Q ()) -> Q () -> Q ()
forall a b. (a -> b) -> a -> b
$ String -> Q ()
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Q ()) -> String -> Q ()
forall a b. (a -> b) -> a -> b
$ String
typeStr String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
" is a 'type' alias but not 'data' or 'newtype'."
  Name -> GenericStrategy -> Q [Dec]
deriveRPCWithStrategy' Name
typeName GenericStrategy
gs

deriveRPCWithStrategy' :: Name -> GenericStrategy -> Q [Dec]
deriveRPCWithStrategy' :: Name -> GenericStrategy -> Q [Dec]
deriveRPCWithStrategy' Name
typeName GenericStrategy
gs = do
  (Name
_, [Type]
decCxt, Maybe Type
mKind, [TyVarBndr ()]
tyVars, [Con]
constructors) <- Name -> Q (Name, [Type], Maybe Type, [TyVarBndr ()], [Con])
reifyDataType Name
typeName

  -- TODO [#722]: use `reifyInstances` to check that 'AsRPC' exists for `fieldType`
  -- Print user-friendly error msg if it doesn't.
  let typeNameRPC :: Name
typeNameRPC = Name -> Name
convertName Name
typeName
  [Con]
constructorsRPC <- (Con -> Q Con) -> [Con] -> Q [Con]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse Con -> Q Con
convertConstructor [Con]
constructors
  [Type]
fieldTypes <- [Con] -> Q [Type]
getFieldTypes [Con]
constructors
  [Type]
fieldTypesRPC <- [Con] -> Q [Type]
getFieldTypes [Con]
constructorsRPC

  Type
derivedType <- Name -> Maybe Type -> [TyVarBndr ()] -> Q Type
forall flag. Name -> Maybe Type -> [TyVarBndr flag] -> Q Type
deriveFullType Name
typeName Maybe Type
mKind [TyVarBndr ()]
tyVars
  Type
derivedTypeRPC <- Name -> Maybe Type -> [TyVarBndr ()] -> Q Type
forall flag. Name -> Maybe Type -> [TyVarBndr flag] -> Q Type
deriveFullType Name
typeNameRPC Maybe Type
mKind [TyVarBndr ()]
tyVars

  -- Note: we can't use `makeRep0Inline` to derive a `Rep` instance for `derivedTypeRPC`
  -- It internally uses `reify` to lookup info about `derivedTypeRPC`, and because `derivedTypeRPC` hasn't
  -- been spliced *yet*, the lookup fails.
  -- So, instead, we fetch the `Rep` instance for `derivedType`, and
  -- append "RPC" to the type/constructor/field names in its metadata.
  --
  -- If, for some reason, we find out that this approach doesn't work for some edge cases,
  -- we should get rid of it and patch the @generic-deriving@ package to export a version of `makeRep0Inline`
  -- that doesn't use `reify` (it should be easy enough).
  TySynEqn
repInstance <- Name -> Type -> Q TySynEqn
reifyRepInstance Name
typeName Type
derivedType
  String
currentModuleName <- Loc -> String
loc_module (Loc -> String) -> Q Loc -> Q String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Q Loc
location
  let repTypeRPC :: Type
repTypeRPC = String -> TySynEqn -> [TyVarBndr ()] -> Type
forall a. String -> TySynEqn -> [TyVarBndr a] -> Type
convertRep String
currentModuleName TySynEqn
repInstance [TyVarBndr ()]
tyVars
  Dec
typeDecOfRPC <- Name
-> [Type] -> Name -> [TyVarBndr ()] -> Maybe Type -> [Con] -> Q Dec
mkTypeDeclaration Name
typeName [Type]
decCxt Name
typeNameRPC [TyVarBndr ()]
tyVars Maybe Type
mKind [Con]
constructorsRPC

  -- Slightly modify the deriving strategy so that the field/constructor
  -- reordering function from original strategy acts on input field names in
  -- RPC type after stripping RPC suffix. Fix for #811
  let
    gs' :: GenericStrategy
gs' = (Text -> Text) -> GenericStrategy -> GenericStrategy
mangleGenericStrategyFields Text -> Text
dropRPCSuffix (GenericStrategy -> GenericStrategy)
-> GenericStrategy -> GenericStrategy
forall a b. (a -> b) -> a -> b
$
            (Text -> Text) -> GenericStrategy -> GenericStrategy
mangleGenericStrategyConstructors Text -> Text
dropRPCSuffix GenericStrategy
gs

  [[Dec]] -> [Dec]
forall a. Monoid a => [a] -> a
mconcat ([[Dec]] -> [Dec]) -> Q [[Dec]] -> Q [Dec]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Q [Dec]] -> Q [[Dec]]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence
    [ [Dec] -> Q [Dec]
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([Dec] -> Q [Dec]) -> (Dec -> [Dec]) -> Dec -> Q [Dec]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Dec -> [Dec]
forall x. One x => OneItem x -> x
one (Dec -> Q [Dec]) -> Dec -> Q [Dec]
forall a b. (a -> b) -> a -> b
$ Dec
typeDecOfRPC
    , Dec -> [Dec]
forall x. One x => OneItem x -> x
one (Dec -> [Dec]) -> Q Dec -> Q [Dec]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Type] -> Type -> Type -> Q Dec
mkAsRPCInstance [Type]
fieldTypes Type
derivedType Type
derivedTypeRPC
    , [Type] -> Type -> Q [Dec]
mkIsoValueInstance [Type]
fieldTypesRPC Type
derivedTypeRPC
    , Maybe Type -> Name -> Type -> [Con] -> GenericStrategy -> Q [Dec]
customGeneric' (Type -> Maybe Type
forall a. a -> Maybe a
Just Type
repTypeRPC) Name
typeNameRPC Type
derivedTypeRPC [Con]
constructorsRPC GenericStrategy
gs'
    ]

  where
    -- | Given the field type @FieldType a b@, returns @AsRPC (FieldType a b)@.
    convertFieldType :: Type -> Type
    convertFieldType :: Type -> Type
convertFieldType Type
tp = Name -> Type
ConT ''AsRPC Type -> Type -> Type
`AppT` Type
tp

    convertNameStr :: String -> String
    convertNameStr :: String -> String
convertNameStr String
s = String
s String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
"RPC"

    dropRPCSuffix :: Text -> Text
    dropRPCSuffix :: Text -> Text
dropRPCSuffix = Text -> Maybe Text -> Text
forall a. a -> Maybe a -> a
fromMaybe (Text -> Text
forall a. HasCallStack => Text -> a
error Text
"Unexpected field/constructor without RPC suffix") (Maybe Text -> Text) -> (Text -> Maybe Text) -> Text -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text -> Maybe Text
T.stripSuffix Text
"RPC"

    convertName :: Name -> Name
    convertName :: Name -> Name
convertName = String -> Name
mkName (String -> Name) -> (Name -> String) -> Name -> Name
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> String
convertNameStr (String -> String) -> (Name -> String) -> Name -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Name -> String
nameBase

    -- | Given the constructor
    -- @C { f :: Int }@,
    -- returns the constructor
    -- @CRPC { fRPC :: AsRPC Int }@.
    convertConstructor :: Con -> Q Con
    convertConstructor :: Con -> Q Con
convertConstructor = \case
      RecC Name
conName [VarBangType]
fields -> Con -> Q Con
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Con -> Q Con) -> Con -> Q Con
forall a b. (a -> b) -> a -> b
$
        Name -> [VarBangType] -> Con
RecC
          (Name -> Name
convertName Name
conName)
          ([VarBangType]
fields [VarBangType] -> (VarBangType -> VarBangType) -> [VarBangType]
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \(Name
fieldName, Bang
fieldBang, Type
fieldType) ->
            (Name -> Name
convertName Name
fieldName, Bang
fieldBang, Type -> Type
convertFieldType Type
fieldType)
          )
      NormalC Name
conName [BangType]
fields -> Con -> Q Con
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Con -> Q Con) -> Con -> Q Con
forall a b. (a -> b) -> a -> b
$
        Name -> [BangType] -> Con
NormalC (Name -> Name
convertName Name
conName) ((Type -> Type) -> BangType -> BangType
forall (p :: * -> * -> *) b c a.
Bifunctor p =>
(b -> c) -> p a b -> p a c
second Type -> Type
convertFieldType (BangType -> BangType) -> [BangType] -> [BangType]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [BangType]
fields)
      InfixC BangType
fieldType1 Name
conName BangType
fieldType2 -> Con -> Q Con
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Con -> Q Con) -> Con -> Q Con
forall a b. (a -> b) -> a -> b
$
        BangType -> Name -> BangType -> Con
InfixC ((Type -> Type) -> BangType -> BangType
forall (p :: * -> * -> *) b c a.
Bifunctor p =>
(b -> c) -> p a b -> p a c
second Type -> Type
convertFieldType BangType
fieldType1) (Name -> Name
convertName Name
conName) ((Type -> Type) -> BangType -> BangType
forall (p :: * -> * -> *) b c a.
Bifunctor p =>
(b -> c) -> p a b -> p a c
second Type -> Type
convertFieldType BangType
fieldType2)
      Con
constr -> String -> Q Con
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Q Con) -> String -> Q Con
forall a b. (a -> b) -> a -> b
$ String
"Unsupported constructor for '" String -> String -> String
forall a. Semigroup a => a -> a -> a
<> Name -> String
forall b a. (PrettyShow a, Show a, IsString b) => a -> b
show Name
typeName String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
"': " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> Doc -> String
forall b a. (PrettyShow a, Show a, IsString b) => a -> b
show (Con -> Doc
forall a. Ppr a => a -> Doc
ppr Con
constr)

    -- | Get a list of all the unique types of all the fields of all the given constructors.
    getFieldTypes :: [Con] -> Q [Type]
    getFieldTypes :: [Con] -> Q [Type]
getFieldTypes [Con]
constrs = [Type] -> [Type]
forall a. Ord a => [a] -> [a]
ordNub ([Type] -> [Type]) -> ([[Type]] -> [Type]) -> [[Type]] -> [Type]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [[Type]] -> [Type]
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join ([[Type]] -> [Type]) -> Q [[Type]] -> Q [Type]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Con] -> (Con -> Q [Type]) -> Q [[Type]]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM [Con]
constrs \case
      RecC Name
_ [VarBangType]
fields -> [Type] -> Q [Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([Type] -> Q [Type]) -> [Type] -> Q [Type]
forall a b. (a -> b) -> a -> b
$ [VarBangType]
fields [VarBangType] -> (VarBangType -> Type) -> [Type]
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \(Name
_, Bang
_, Type
fieldType) -> Type
fieldType
      NormalC Name
_ [BangType]
fields -> [Type] -> Q [Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([Type] -> Q [Type]) -> [Type] -> Q [Type]
forall a b. (a -> b) -> a -> b
$ BangType -> Type
forall a b. (a, b) -> b
snd (BangType -> Type) -> [BangType] -> [Type]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [BangType]
fields
      InfixC BangType
field1 Name
_ BangType
field2 -> [Type] -> Q [Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure [BangType -> Type
forall a b. (a, b) -> b
snd BangType
field1, BangType -> Type
forall a b. (a, b) -> b
snd BangType
field2]
      Con
constr -> String -> Q [Type]
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Q [Type]) -> String -> Q [Type]
forall a b. (a -> b) -> a -> b
$ String
"Unsupported constructor for '" String -> String -> String
forall a. Semigroup a => a -> a -> a
<> Name -> String
forall b a. (PrettyShow a, Show a, IsString b) => a -> b
show Name
typeName String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
"': " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> Doc -> String
forall b a. (PrettyShow a, Show a, IsString b) => a -> b
show (Con -> Doc
forall a. Ppr a => a -> Doc
ppr Con
constr)

    mkTypeDeclaration :: Name -> Cxt -> Name -> [TyVarBndr ()] -> Maybe Kind -> [Con] -> Q Dec
    mkTypeDeclaration :: Name
-> [Type] -> Name -> [TyVarBndr ()] -> Maybe Type -> [Con] -> Q Dec
mkTypeDeclaration Name
tyName [Type]
decCxt Name
typeNameRPC [TyVarBndr ()]
tyVars Maybe Type
mKind [Con]
constructorsRPC = do
      Info
typeInfo <- Name -> Q Info
reify Name
tyName
      case Info
typeInfo of
        TyConI DataD {} -> Dec -> Q Dec
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Dec -> Q Dec) -> Dec -> Q Dec
forall a b. (a -> b) -> a -> b
$ [Type]
-> Name
-> [TyVarBndr ()]
-> Maybe Type
-> [Con]
-> [DerivClause]
-> Dec
DataD [Type]
decCxt Name
typeNameRPC [TyVarBndr ()]
tyVars Maybe Type
mKind [Con]
constructorsRPC []
        TyConI NewtypeD {} -> (case [Con]
constructorsRPC of
          [Con
con] -> Dec -> Q Dec
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Dec -> Q Dec) -> Dec -> Q Dec
forall a b. (a -> b) -> a -> b
$ [Type]
-> Name
-> [TyVarBndr ()]
-> Maybe Type
-> Con
-> [DerivClause]
-> Dec
NewtypeD [Type]
decCxt Name
typeNameRPC [TyVarBndr ()]
tyVars Maybe Type
mKind Con
con []
          [Con]
_ -> String -> Q Dec
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Newtype has only one constructor")
        Info
_ -> String -> Q Dec
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Q Dec) -> String -> Q Dec
forall a b. (a -> b) -> a -> b
$ String
"Only newtypes and data types are supported, but '" String -> String -> String
forall a. Semigroup a => a -> a -> a
<>
          Name -> String
forall b a. (PrettyShow a, Show a, IsString b) => a -> b
show Name
tyName String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
"' is:\n" String -> String -> String
forall a. Semigroup a => a -> a -> a
<> Doc -> String
forall b a. (PrettyShow a, Show a, IsString b) => a -> b
show (Info -> Doc
forall a. Ppr a => a -> Doc
ppr Info
typeInfo)

    -- | Traverse a 'Rep' type and:
    --
    -- 1. Inspect its metadata and append @RPC@ to the type/constructor/field names.
    -- 2. Convert field types (e.g. @T@ becomes @AsRPC T@).
    -- 3. Replace the Rep's module name with the name of the module of where this Q is being spliced.
    convertRep :: String -> TySynEqn -> [TyVarBndr a] -> Type
    convertRep :: forall a. String -> TySynEqn -> [TyVarBndr a] -> Type
convertRep String
currentModuleName (TySynEqn Maybe [TyVarBndr ()]
_tyVars Type
lhs Type
rhs) [TyVarBndr a]
tvs = Type -> Type
go Type
rhs
      where
        varMap :: Map Name Name
varMap = [(Name, Name)] -> Map Name Name
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList ([(Name, Name)] -> Map Name Name)
-> [(Name, Name)] -> Map Name Name
forall a b. (a -> b) -> a -> b
$ [Name] -> [Name] -> [(Name, Name)]
forall a b. [a] -> [b] -> [(a, b)]
zip [Name]
lhsTvs ([Name] -> [(Name, Name)]) -> [Name] -> [(Name, Name)]
forall a b. (a -> b) -> a -> b
$ [TyVarBndr a]
tvs [TyVarBndr a] -> (TyVarBndr a -> Name) -> [Name]
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \case
          PlainTV Name
vName a
_ -> Name
vName
          KindedTV Name
vName a
_ Type
_ -> Name
vName
        lhsTvs :: [Name]
lhsTvs = ([Name] -> [Name] -> [Name]) -> GenericQ [Name] -> GenericQ [Name]
forall r. (r -> r -> r) -> GenericQ r -> GenericQ r
everything [Name] -> [Name] -> [Name]
forall a. Semigroup a => a -> a -> a
(<>) ([Name]
forall a. Monoid a => a
mempty [Name] -> (Type -> [Name]) -> a -> [Name]
forall a b r. (Typeable a, Typeable b) => r -> (b -> r) -> a -> r
`mkQ` ([Name] -> (Name -> [Name]) -> Maybe Name -> [Name]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [Name]
forall a. Monoid a => a
mempty Name -> [Name]
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe Name -> [Name]) -> (Type -> Maybe Name) -> Type -> [Name]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Type -> Maybe Name
varTName)) Type
lhs
        varTName :: Type -> Maybe Name
varTName = \case
          VarT Name
v -> Name -> Maybe Name
forall a. a -> Maybe a
Just Name
v
          Type
_ -> Maybe Name
forall a. Maybe a
Nothing
        go :: Type -> Type
        go :: Type -> Type
go = \case
          -- Rename type name and module name
          PromotedT Name
t `AppT` LitT (StrTyLit String
tyName) `AppT` LitT (StrTyLit String
_moduleName)
            | Name
t Name -> Name -> Bool
forall a. Eq a => a -> a -> Bool
== 'G.MetaData
            -> Name -> Type
PromotedT Name
t Type -> Type -> Type
`AppT` TyLit -> Type
LitT (String -> TyLit
StrTyLit (String -> String
convertNameStr String
tyName)) Type -> Type -> Type
`AppT` TyLit -> Type
LitT (String -> TyLit
StrTyLit String
currentModuleName)
          -- Rename constructor names
          PromotedT Name
t `AppT` LitT (StrTyLit String
conName)
            | Name
t Name -> Name -> Bool
forall a. Eq a => a -> a -> Bool
== 'G.MetaCons
            -> Name -> Type
PromotedT Name
t Type -> Type -> Type
`AppT` TyLit -> Type
LitT (String -> TyLit
StrTyLit (String -> String
convertNameStr String
conName))
          -- Rename field names
          PromotedT Name
t `AppT` (PromotedT Name
just `AppT` LitT (StrTyLit String
fieldName))
            | Name
t Name -> Name -> Bool
forall a. Eq a => a -> a -> Bool
== 'G.MetaSel
            -> Name -> Type
PromotedT Name
t Type -> Type -> Type
`AppT` (Name -> Type
PromotedT Name
just Type -> Type -> Type
`AppT` TyLit -> Type
LitT (String -> TyLit
StrTyLit (String -> String
convertNameStr String
fieldName)))
          -- Replace field type @T@ with @AsRPC T@
          ConT Name
x `AppT` Type
fieldType
            | Name
x Name -> Name -> Bool
forall a. Eq a => a -> a -> Bool
== ''G.Rec0
            -> Name -> Type
ConT Name
x Type -> Type -> Type
`AppT` (Type -> Type
convertFieldType (Type -> Type) -> Type -> Type
forall a b. (a -> b) -> a -> b
$ Type -> Type
replaceVars Type
fieldType)
          Type
x `AppT` Type
y -> Type -> Type
go Type
x Type -> Type -> Type
`AppT` Type -> Type
go Type
y
          Type
x -> Type -> Type
replaceVars Type
x
        replaceVars :: Type -> Type
replaceVars = \case
          VarT Name
v -> Name -> Type
VarT (Name -> Type) -> Name -> Type
forall a b. (a -> b) -> a -> b
$ Name -> Maybe Name -> Name
forall a. a -> Maybe a -> a
fromMaybe Name
v (Maybe Name -> Name) -> Maybe Name -> Name
forall a b. (a -> b) -> a -> b
$ Name -> Map Name Name -> Maybe Name
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup Name
v Map Name Name
varMap
          Type
x -> Type
x

    -- | Lookup the generic 'Rep' type instance for the given type.
    reifyRepInstance :: Name -> Type -> Q TySynEqn
    reifyRepInstance :: Name -> Type -> Q TySynEqn
reifyRepInstance Name
name Type
tp =
      Name -> [Type] -> Q [Dec]
reifyInstances ''G.Rep [Type
tp] Q [Dec] -> ([Dec] -> Q TySynEqn) -> Q TySynEqn
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
        [TySynInstD TySynEqn
repInstance] -> TySynEqn -> Q TySynEqn
forall (f :: * -> *) a. Applicative f => a -> f a
pure TySynEqn
repInstance
        (Dec
_:[Dec]
_) -> String -> Q TySynEqn
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Q TySynEqn) -> String -> Q TySynEqn
forall a b. (a -> b) -> a -> b
$ String
"Found multiple instances of 'Generic' for '" String -> String -> String
forall a. Semigroup a => a -> a -> a
<> Name -> String
forall b a. (PrettyShow a, Show a, IsString b) => a -> b
show Name
name String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
"'."
        [] -> String -> Q TySynEqn
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Q TySynEqn) -> String -> Q TySynEqn
forall a b. (a -> b) -> a -> b
$ String
"Type '" String -> String -> String
forall a. Semigroup a => a -> a -> a
<> Name -> String
forall b a. (PrettyShow a, Show a, IsString b) => a -> b
show Name
name String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
"' must implement 'Generic'."

    -- | Given the type @Foo a b = Foo (Bar a)@, generate an 'IsoValue' instance like:
    --
    -- > deriving anyclass instance IsoValue (AsRPC (Bar a)) => IsoValue (FooRPC a b)
    --
    -- Note that if a type variable @t@ is a phantom type variable, then no @IsoValue (AsRPC t)@
    -- constraint is generated for it.
    mkIsoValueInstance :: [Type] -> Type -> Q [Dec]
    mkIsoValueInstance :: [Type] -> Type -> Q [Dec]
mkIsoValueInstance [Type]
fieldTypes Type
tp =
      Dec -> [Dec]
forall x. One x => OneItem x -> x
one (Dec -> [Dec]) -> Q Dec -> Q [Dec]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe DerivStrategy -> Q [Type] -> Q Type -> Q Dec
forall (m :: * -> *).
Quote m =>
Maybe DerivStrategy -> m [Type] -> m Type -> m Dec
standaloneDerivWithStrategyD (DerivStrategy -> Maybe DerivStrategy
forall a. a -> Maybe a
Just DerivStrategy
AnyclassStrategy) Q [Type]
constraints [t|IsoValue $(pure tp)|]
      where
        constraints :: Q Cxt
        constraints :: Q [Type]
constraints =
          [Q Type] -> Q [Type]
forall (m :: * -> *). Quote m => [m Type] -> m [Type]
cxt ([Q Type] -> Q [Type]) -> [Q Type] -> Q [Type]
forall a b. (a -> b) -> a -> b
$ (Type -> Bool) -> [Type] -> [Type]
forall a. (a -> Bool) -> [a] -> [a]
filter Type -> Bool
hasTyVar [Type]
fieldTypes [Type] -> (Type -> Q Type) -> [Q Type]
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \Type
fieldType ->
            [t|IsoValue $(pure fieldType)|]

    -- | Given the type @Foo a b = Foo (Bar a)@, generate an 'HasRPCRepr' instance like:
    --
    -- > instance HasRPCRepr (Bar a) => HasRPCRepr (Foo a b) where
    -- >   type AsRPC (Foo a b) = FooRPC a b
    --
    -- Note that if a type variable @t@ is a phantom type variable, then no @HasRPCRepr@
    -- constraint is generated for it.
    mkAsRPCInstance :: [Type] -> Type -> Type -> Q Dec
    mkAsRPCInstance :: [Type] -> Type -> Type -> Q Dec
mkAsRPCInstance [Type]
fieldTypes Type
tp Type
tpRPC = do
      [Dec]
typeInstance <- [d|type instance AsRPC $(pure tp) = $(pure tpRPC)|]
      Q [Type] -> Q Type -> [Q Dec] -> Q Dec
forall (m :: * -> *).
Quote m =>
m [Type] -> m Type -> [m Dec] -> m Dec
instanceD Q [Type]
constraints [t|HasRPCRepr $(pure tp)|]
        (Dec -> Q Dec
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Dec -> Q Dec) -> [Dec] -> [Q Dec]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Dec]
typeInstance)
      where
        constraints :: Q Cxt
        constraints :: Q [Type]
constraints =
          [Q Type] -> Q [Type]
forall (m :: * -> *). Quote m => [m Type] -> m [Type]
cxt ([Q Type] -> Q [Type]) -> [Q Type] -> Q [Type]
forall a b. (a -> b) -> a -> b
$ (Type -> Bool) -> [Type] -> [Type]
forall a. (a -> Bool) -> [a] -> [a]
filter Type -> Bool
hasTyVar [Type]
fieldTypes [Type] -> (Type -> Q Type) -> [Q Type]
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \Type
fieldType ->
            [t|HasRPCRepr $(pure fieldType)|]

    -- | Checks if the given type has any type variables.
    hasTyVar :: Type -> Bool
    hasTyVar :: Type -> Bool
hasTyVar Type
ty =
      ((Type -> Bool) -> [Type] -> Bool)
-> [Type] -> (Type -> Bool) -> Bool
forall a b c. (a -> b -> c) -> b -> a -> c
flip (Type -> Bool) -> [Type] -> Bool
forall t. Container t => (Element t -> Bool) -> t -> Bool
any (Type -> [Type]
forall a. Plated a => a -> [a]
universe Type
ty) \case
        VarT Name
_ -> Bool
True
        Type
_ -> Bool
False

----------------------------------------------------------------------------
-- Conversions
----------------------------------------------------------------------------

-- | Replace all big_maps in a value with the respective big_map IDs.
--
-- Throws an error if it finds a big_map without an ID.
valueAsRPC :: HasCallStack => Value t -> Value (TAsRPC t)
valueAsRPC :: forall (t :: T). HasCallStack => Value t -> Value (TAsRPC t)
valueAsRPC Value t
v =
  case Value t
v of
    VKey {} -> Value t
Value (TAsRPC t)
v
    VUnit {} -> Value t
Value (TAsRPC t)
v
    VSignature {} -> Value t
Value (TAsRPC t)
v
    VChainId {} -> Value t
Value (TAsRPC t)
v
    VChest {} -> Value t
Value (TAsRPC t)
v
    VChestKey {} -> Value t
Value (TAsRPC t)
v
    VOption (Maybe (Value t1)
vMaybe :: Maybe (Value elem)) ->
      (SingI t1 :- SingI (TAsRPC t1))
-> (SingI (TAsRPC t1) => Value ('TOption (TAsRPC t1)))
-> Value ('TOption (TAsRPC t1))
forall (c :: Constraint) e r. HasDict c e => e -> (c => r) -> r
withDict (forall (t :: T). SingI t :- SingI (TAsRPC t)
rpcSingIEvi @elem) ((SingI (TAsRPC t1) => Value ('TOption (TAsRPC t1)))
 -> Value ('TOption (TAsRPC t1)))
-> (SingI (TAsRPC t1) => Value ('TOption (TAsRPC t1)))
-> Value ('TOption (TAsRPC t1))
forall a b. (a -> b) -> a -> b
$
        Maybe (Value' Instr (TAsRPC t1)) -> Value ('TOption (TAsRPC t1))
forall (t1 :: T) (instr :: [T] -> [T] -> *).
SingI t1 =>
Maybe (Value' instr t1) -> Value' instr ('TOption t1)
VOption (Maybe (Value' Instr (TAsRPC t1)) -> Value ('TOption (TAsRPC t1)))
-> Maybe (Value' Instr (TAsRPC t1)) -> Value ('TOption (TAsRPC t1))
forall a b. (a -> b) -> a -> b
$ Value t1 -> Value' Instr (TAsRPC t1)
forall (t :: T). HasCallStack => Value t -> Value (TAsRPC t)
valueAsRPC (Value t1 -> Value' Instr (TAsRPC t1))
-> Maybe (Value t1) -> Maybe (Value' Instr (TAsRPC t1))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (Value t1)
vMaybe
    VList ([Value t1]
vList :: [Value elem]) ->
      (SingI t1 :- SingI (TAsRPC t1))
-> (SingI (TAsRPC t1) => Value ('TList (TAsRPC t1)))
-> Value ('TList (TAsRPC t1))
forall (c :: Constraint) e r. HasDict c e => e -> (c => r) -> r
withDict (forall (t :: T). SingI t :- SingI (TAsRPC t)
rpcSingIEvi @elem) ((SingI (TAsRPC t1) => Value ('TList (TAsRPC t1)))
 -> Value ('TList (TAsRPC t1)))
-> (SingI (TAsRPC t1) => Value ('TList (TAsRPC t1)))
-> Value ('TList (TAsRPC t1))
forall a b. (a -> b) -> a -> b
$
        [Value' Instr (TAsRPC t1)] -> Value ('TList (TAsRPC t1))
forall (t1 :: T) (instr :: [T] -> [T] -> *).
SingI t1 =>
[Value' instr t1] -> Value' instr ('TList t1)
VList ([Value' Instr (TAsRPC t1)] -> Value ('TList (TAsRPC t1)))
-> [Value' Instr (TAsRPC t1)] -> Value ('TList (TAsRPC t1))
forall a b. (a -> b) -> a -> b
$ Value t1 -> Value' Instr (TAsRPC t1)
forall (t :: T). HasCallStack => Value t -> Value (TAsRPC t)
valueAsRPC (Value t1 -> Value' Instr (TAsRPC t1))
-> [Value t1] -> [Value' Instr (TAsRPC t1)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Value t1]
vList
    VSet {} -> Value t
Value (TAsRPC t)
v
    VOp {} -> Value t
Value (TAsRPC t)
v
    VContract {} -> Value t
Value (TAsRPC t)
v
    VTicket {} -> Value t
Value (TAsRPC t)
v
    VPair (Value' Instr l
x, Value' Instr r
y) -> (Value' Instr (TAsRPC l), Value' Instr (TAsRPC r))
-> Value' Instr ('TPair (TAsRPC l) (TAsRPC r))
forall (l :: T) (r :: T) (instr :: [T] -> [T] -> *).
(Value' instr l, Value' instr r) -> Value' instr ('TPair l r)
VPair (Value' Instr l -> Value' Instr (TAsRPC l)
forall (t :: T). HasCallStack => Value t -> Value (TAsRPC t)
valueAsRPC Value' Instr l
x, Value' Instr r -> Value' Instr (TAsRPC r)
forall (t :: T). HasCallStack => Value t -> Value (TAsRPC t)
valueAsRPC Value' Instr r
y)
    VOr (Either (Value l) (Value r)
vEither :: Either (Value l) (Value r)) ->
      ((SingI l, SingI r) :- (SingI (TAsRPC l), SingI (TAsRPC r)))
-> ((SingI (TAsRPC l), SingI (TAsRPC r)) =>
    Value ('TOr (TAsRPC l) (TAsRPC r)))
-> Value ('TOr (TAsRPC l) (TAsRPC r))
forall (c :: Constraint) e r. HasDict c e => e -> (c => r) -> r
withDict (forall (t :: T). SingI t :- SingI (TAsRPC t)
rpcSingIEvi @l (SingI l :- SingI (TAsRPC l))
-> (SingI r :- SingI (TAsRPC r))
-> (SingI l, SingI r) :- (SingI (TAsRPC l), SingI (TAsRPC r))
forall (a :: Constraint) (b :: Constraint) (c :: Constraint)
       (d :: Constraint).
(a :- b) -> (c :- d) -> (a, c) :- (b, d)
*** forall (t :: T). SingI t :- SingI (TAsRPC t)
rpcSingIEvi @r) (((SingI (TAsRPC l), SingI (TAsRPC r)) =>
  Value ('TOr (TAsRPC l) (TAsRPC r)))
 -> Value ('TOr (TAsRPC l) (TAsRPC r)))
-> ((SingI (TAsRPC l), SingI (TAsRPC r)) =>
    Value ('TOr (TAsRPC l) (TAsRPC r)))
-> Value ('TOr (TAsRPC l) (TAsRPC r))
forall a b. (a -> b) -> a -> b
$
        case Either (Value l) (Value r)
vEither of
          Right Value r
r -> Either (Value' Instr (TAsRPC l)) (Value' Instr (TAsRPC r))
-> Value ('TOr (TAsRPC l) (TAsRPC r))
forall (l :: T) (r :: T) (instr :: [T] -> [T] -> *).
(SingI l, SingI r) =>
Either (Value' instr l) (Value' instr r) -> Value' instr ('TOr l r)
VOr (Value' Instr (TAsRPC r)
-> Either (Value' Instr (TAsRPC l)) (Value' Instr (TAsRPC r))
forall a b. b -> Either a b
Right (Value r -> Value' Instr (TAsRPC r)
forall (t :: T). HasCallStack => Value t -> Value (TAsRPC t)
valueAsRPC Value r
r))
          Left Value l
l -> Either (Value' Instr (TAsRPC l)) (Value' Instr (TAsRPC r))
-> Value ('TOr (TAsRPC l) (TAsRPC r))
forall (l :: T) (r :: T) (instr :: [T] -> [T] -> *).
(SingI l, SingI r) =>
Either (Value' instr l) (Value' instr r) -> Value' instr ('TOr l r)
VOr (Value' Instr (TAsRPC l)
-> Either (Value' Instr (TAsRPC l)) (Value' Instr (TAsRPC r))
forall a b. a -> Either a b
Left (Value l -> Value' Instr (TAsRPC l)
forall (t :: T). HasCallStack => Value t -> Value (TAsRPC t)
valueAsRPC Value l
l))
    VLam {} -> Value t
Value (TAsRPC t)
v
    VMap (Map (Value k) (Value v)
vMap :: Map (Value k) (Value v)) ->
      (SingI v :- SingI (TAsRPC v))
-> (SingI (TAsRPC v) => Value ('TMap k (TAsRPC v)))
-> Value ('TMap k (TAsRPC v))
forall (c :: Constraint) e r. HasDict c e => e -> (c => r) -> r
withDict (forall (t :: T). SingI t :- SingI (TAsRPC t)
rpcSingIEvi @v) ((SingI (TAsRPC v) => Value ('TMap k (TAsRPC v)))
 -> Value ('TMap k (TAsRPC v)))
-> (SingI (TAsRPC v) => Value ('TMap k (TAsRPC v)))
-> Value ('TMap k (TAsRPC v))
forall a b. (a -> b) -> a -> b
$
        Map (Value k) (Value' Instr (TAsRPC v))
-> Value ('TMap k (TAsRPC v))
forall (k :: T) (v :: T) (instr :: [T] -> [T] -> *).
(SingI k, SingI v, Comparable k) =>
Map (Value' instr k) (Value' instr v) -> Value' instr ('TMap k v)
VMap (Map (Value k) (Value' Instr (TAsRPC v))
 -> Value ('TMap k (TAsRPC v)))
-> Map (Value k) (Value' Instr (TAsRPC v))
-> Value ('TMap k (TAsRPC v))
forall a b. (a -> b) -> a -> b
$ Value v -> Value' Instr (TAsRPC v)
forall (t :: T). HasCallStack => Value t -> Value (TAsRPC t)
valueAsRPC (Value v -> Value' Instr (TAsRPC v))
-> Map (Value k) (Value v)
-> Map (Value k) (Value' Instr (TAsRPC v))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Map (Value k) (Value v)
vMap
    VBigMap (Just Natural
bmId) Map (Value' Instr k) (Value' Instr v)
_ -> Natural -> Value' Instr 'TNat
forall (instr :: [T] -> [T] -> *). Natural -> Value' instr 'TNat
VNat Natural
bmId
    VBigMap Maybe Natural
Nothing Map (Value' Instr k) (Value' Instr v)
_ ->
      Text -> Value' Instr 'TNat
forall a. HasCallStack => Text -> a
error (Text -> Value' Instr 'TNat) -> Text -> Value' Instr 'TNat
forall a b. (a -> b) -> a -> b
$ [Text] -> Text
unlines
        [ Text
"Expected all big_maps to have an ID, but at least one big_map didn't."
        , Text
"This is most likely a bug."
        ]
    VInt {} -> Value t
Value (TAsRPC t)
v
    VNat {} -> Value t
Value (TAsRPC t)
v
    VString {} -> Value t
Value (TAsRPC t)
v
    VBytes {} -> Value t
Value (TAsRPC t)
v
    VMutez {} -> Value t
Value (TAsRPC t)
v
    VBool {} -> Value t
Value (TAsRPC t)
v
    VKeyHash {} -> Value t
Value (TAsRPC t)
v
    VTimestamp {} -> Value t
Value (TAsRPC t)
v
    VAddress {} -> Value t
Value (TAsRPC t)
v
    VBls12381Fr {} -> Value t
Value (TAsRPC t)
v
    VBls12381G1 {} -> Value t
Value (TAsRPC t)
v
    VBls12381G2 {} -> Value t
Value (TAsRPC t)
v
    VTxRollupL2Address {} -> Value t
Value (TAsRPC t)
v

-- | Replaces all bigmap IDs with their corresponding bigmap values.
-- This is the inverse of `valueAsRPC`.
replaceBigMapIds
  :: forall t m. Monad m
  => (forall k v. (SingI k, SingI v) => Natural -> m (Value ('TBigMap k v)))
  -- ^ A function for looking up a bigmap using its ID.
  -> Sing t -> Value (TAsRPC t) -> m (Value t)
replaceBigMapIds :: forall (t :: T) (m :: * -> *).
Monad m =>
(forall (k :: T) (v :: T).
 (SingI k, SingI v) =>
 Natural -> m (Value ('TBigMap k v)))
-> Sing t -> Value (TAsRPC t) -> m (Value t)
replaceBigMapIds forall (k :: T) (v :: T).
(SingI k, SingI v) =>
Natural -> m (Value ('TBigMap k v))
findBigMapById = Sing t -> Value (TAsRPC t) -> m (Value t)
forall (t1 :: T). Sing t1 -> Value (TAsRPC t1) -> m (Value t1)
go
  where
    go :: forall t1. Sing t1 -> Value (TAsRPC t1) -> m (Value t1)
    go :: forall (t1 :: T). Sing t1 -> Value (TAsRPC t1) -> m (Value t1)
go Sing t1
s Value (TAsRPC t1)
v = case (Sing t1
SingT t1
s, Value (TAsRPC t1)
v) of
      (STKey {}, Value (TAsRPC t1)
_) -> Value t1 -> m (Value t1)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Value t1
Value (TAsRPC t1)
v
      (STUnit {}, Value (TAsRPC t1)
_) -> Value t1 -> m (Value t1)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Value t1
Value (TAsRPC t1)
v
      (STSignature {}, Value (TAsRPC t1)
_) -> Value t1 -> m (Value t1)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Value t1
Value (TAsRPC t1)
v
      (STChainId {}, Value (TAsRPC t1)
_) -> Value t1 -> m (Value t1)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Value t1
Value (TAsRPC t1)
v
      (STChest {}, Value (TAsRPC t1)
_) -> Value t1 -> m (Value t1)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Value t1
Value (TAsRPC t1)
v
      (STChestKey {}, Value (TAsRPC t1)
_) -> Value t1 -> m (Value t1)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Value t1
Value (TAsRPC t1)
v
      (STTxRollupL2Address {}, Value (TAsRPC t1)
_) -> Value t1 -> m (Value t1)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Value t1
Value (TAsRPC t1)
v
      (STOption Sing n
sMaybe, VOption Maybe (Value' Instr t1)
vMaybe) ->
        Sing n -> (SingI n => m (Value t1)) -> m (Value t1)
forall {k} (n :: k) r. Sing n -> (SingI n => r) -> r
withSingI Sing n
sMaybe ((SingI n => m (Value t1)) -> m (Value t1))
-> (SingI n => m (Value t1)) -> m (Value t1)
forall a b. (a -> b) -> a -> b
$
          Maybe (Value' Instr n) -> Value' Instr ('TOption n)
forall (t1 :: T) (instr :: [T] -> [T] -> *).
SingI t1 =>
Maybe (Value' instr t1) -> Value' instr ('TOption t1)
VOption (Maybe (Value' Instr n) -> Value' Instr ('TOption n))
-> m (Maybe (Value' Instr n)) -> m (Value' Instr ('TOption n))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Value' Instr t1 -> m (Value' Instr n))
-> Maybe (Value' Instr t1) -> m (Maybe (Value' Instr n))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (Sing n -> Value (TAsRPC n) -> m (Value' Instr n)
forall (t1 :: T). Sing t1 -> Value (TAsRPC t1) -> m (Value t1)
go Sing n
sMaybe) Maybe (Value' Instr t1)
vMaybe
      (STList Sing n
sList, VList [Value' Instr t1]
vList) ->
        Sing n -> (SingI n => m (Value t1)) -> m (Value t1)
forall {k} (n :: k) r. Sing n -> (SingI n => r) -> r
withSingI Sing n
sList ((SingI n => m (Value t1)) -> m (Value t1))
-> (SingI n => m (Value t1)) -> m (Value t1)
forall a b. (a -> b) -> a -> b
$
          [Value' Instr n] -> Value' Instr ('TList n)
forall (t1 :: T) (instr :: [T] -> [T] -> *).
SingI t1 =>
[Value' instr t1] -> Value' instr ('TList t1)
VList ([Value' Instr n] -> Value' Instr ('TList n))
-> m [Value' Instr n] -> m (Value' Instr ('TList n))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Value' Instr t1 -> m (Value' Instr n))
-> [Value' Instr t1] -> m [Value' Instr n]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (Sing n -> Value (TAsRPC n) -> m (Value' Instr n)
forall (t1 :: T). Sing t1 -> Value (TAsRPC t1) -> m (Value t1)
go Sing n
sList) [Value' Instr t1]
vList
      (STSet {}, Value (TAsRPC t1)
_) -> Value t1 -> m (Value t1)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Value t1
Value (TAsRPC t1)
v
      (STOperation {}, Value (TAsRPC t1)
_) -> Value t1 -> m (Value t1)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Value t1
Value (TAsRPC t1)
v
      (STContract {}, Value (TAsRPC t1)
_) -> Value t1 -> m (Value t1)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Value t1
Value (TAsRPC t1)
v
      (STTicket {}, Value (TAsRPC t1)
_) -> Value t1 -> m (Value t1)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Value t1
Value (TAsRPC t1)
v
      (STPair Sing n1
sa Sing n2
sb, VPair (Value' Instr l
a, Value' Instr r
b)) -> do
        Value n1
a' <- Sing n1 -> Value (TAsRPC n1) -> m (Value n1)
forall (t1 :: T). Sing t1 -> Value (TAsRPC t1) -> m (Value t1)
go Sing n1
sa Value' Instr l
Value (TAsRPC n1)
a
        Value n2
b' <- Sing n2 -> Value (TAsRPC n2) -> m (Value n2)
forall (t1 :: T). Sing t1 -> Value (TAsRPC t1) -> m (Value t1)
go Sing n2
sb Value' Instr r
Value (TAsRPC n2)
b
        pure $ (Value n1, Value n2) -> Value' Instr ('TPair n1 n2)
forall (l :: T) (r :: T) (instr :: [T] -> [T] -> *).
(Value' instr l, Value' instr r) -> Value' instr ('TPair l r)
VPair (Value n1
a', Value n2
b')
      (STOr Sing n1
sl Sing n2
sr, VOr Either (Value' Instr l) (Value' Instr r)
vEither) -> Sing n1 -> (SingI n1 => m (Value t1)) -> m (Value t1)
forall {k} (n :: k) r. Sing n -> (SingI n => r) -> r
withSingI Sing n1
sl ((SingI n1 => m (Value t1)) -> m (Value t1))
-> (SingI n1 => m (Value t1)) -> m (Value t1)
forall a b. (a -> b) -> a -> b
$ Sing n2 -> (SingI n2 => m (Value t1)) -> m (Value t1)
forall {k} (n :: k) r. Sing n -> (SingI n => r) -> r
withSingI Sing n2
sr ((SingI n2 => m (Value t1)) -> m (Value t1))
-> (SingI n2 => m (Value t1)) -> m (Value t1)
forall a b. (a -> b) -> a -> b
$
        case Either (Value' Instr l) (Value' Instr r)
vEither of
          Right Value' Instr r
r -> Either (Value' Instr n1) (Value' Instr n2)
-> Value' Instr ('TOr n1 n2)
forall (l :: T) (r :: T) (instr :: [T] -> [T] -> *).
(SingI l, SingI r) =>
Either (Value' instr l) (Value' instr r) -> Value' instr ('TOr l r)
VOr (Either (Value' Instr n1) (Value' Instr n2)
 -> Value' Instr ('TOr n1 n2))
-> (Value' Instr n2 -> Either (Value' Instr n1) (Value' Instr n2))
-> Value' Instr n2
-> Value' Instr ('TOr n1 n2)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Value' Instr n2 -> Either (Value' Instr n1) (Value' Instr n2)
forall a b. b -> Either a b
Right (Value' Instr n2 -> Value' Instr ('TOr n1 n2))
-> m (Value' Instr n2) -> m (Value' Instr ('TOr n1 n2))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Sing n2 -> Value (TAsRPC n2) -> m (Value' Instr n2)
forall (t1 :: T). Sing t1 -> Value (TAsRPC t1) -> m (Value t1)
go Sing n2
sr Value' Instr r
Value (TAsRPC n2)
r
          Left Value' Instr l
l -> Either (Value' Instr n1) (Value' Instr n2)
-> Value' Instr ('TOr n1 n2)
forall (l :: T) (r :: T) (instr :: [T] -> [T] -> *).
(SingI l, SingI r) =>
Either (Value' instr l) (Value' instr r) -> Value' instr ('TOr l r)
VOr (Either (Value' Instr n1) (Value' Instr n2)
 -> Value' Instr ('TOr n1 n2))
-> (Value' Instr n1 -> Either (Value' Instr n1) (Value' Instr n2))
-> Value' Instr n1
-> Value' Instr ('TOr n1 n2)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Value' Instr n1 -> Either (Value' Instr n1) (Value' Instr n2)
forall a b. a -> Either a b
Left (Value' Instr n1 -> Value' Instr ('TOr n1 n2))
-> m (Value' Instr n1) -> m (Value' Instr ('TOr n1 n2))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Sing n1 -> Value (TAsRPC n1) -> m (Value' Instr n1)
forall (t1 :: T). Sing t1 -> Value (TAsRPC t1) -> m (Value t1)
go Sing n1
sl Value' Instr l
Value (TAsRPC n1)
l
      (STLambda {}, Value (TAsRPC t1)
_) -> Value t1 -> m (Value t1)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Value t1
Value (TAsRPC t1)
v
      (STMap Sing n1
_ Sing n2
sv, VMap Map (Value' Instr k) (Value' Instr v)
vList) ->
        Sing n2 -> (SingI n2 => m (Value t1)) -> m (Value t1)
forall {k} (n :: k) r. Sing n -> (SingI n => r) -> r
withSingI Sing n2
sv ((SingI n2 => m (Value t1)) -> m (Value t1))
-> (SingI n2 => m (Value t1)) -> m (Value t1)
forall a b. (a -> b) -> a -> b
$
          Map (Value' Instr k) (Value' Instr n2) -> Value' Instr ('TMap k n2)
forall (k :: T) (v :: T) (instr :: [T] -> [T] -> *).
(SingI k, SingI v, Comparable k) =>
Map (Value' instr k) (Value' instr v) -> Value' instr ('TMap k v)
VMap (Map (Value' Instr k) (Value' Instr n2)
 -> Value' Instr ('TMap k n2))
-> m (Map (Value' Instr k) (Value' Instr n2))
-> m (Value' Instr ('TMap k n2))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Value' Instr v -> m (Value' Instr n2))
-> Map (Value' Instr k) (Value' Instr v)
-> m (Map (Value' Instr k) (Value' Instr n2))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (Sing n2 -> Value (TAsRPC n2) -> m (Value' Instr n2)
forall (t1 :: T). Sing t1 -> Value (TAsRPC t1) -> m (Value t1)
go Sing n2
sv) Map (Value' Instr k) (Value' Instr v)
vList
      (STBigMap Sing n1
sk Sing n2
sv, VNat Natural
bigMapId) -> Sing n1 -> (SingI n1 => m (Value t1)) -> m (Value t1)
forall {k} (n :: k) r. Sing n -> (SingI n => r) -> r
withSingI Sing n1
sk ((SingI n1 => m (Value t1)) -> m (Value t1))
-> (SingI n1 => m (Value t1)) -> m (Value t1)
forall a b. (a -> b) -> a -> b
$ Sing n2 -> (SingI n2 => m (Value t1)) -> m (Value t1)
forall {k} (n :: k) r. Sing n -> (SingI n => r) -> r
withSingI Sing n2
sv ((SingI n2 => m (Value t1)) -> m (Value t1))
-> (SingI n2 => m (Value t1)) -> m (Value t1)
forall a b. (a -> b) -> a -> b
$ Natural -> m (Value ('TBigMap n1 n2))
forall (k :: T) (v :: T).
(SingI k, SingI v) =>
Natural -> m (Value ('TBigMap k v))
findBigMapById Natural
bigMapId
      (STInt {}, Value (TAsRPC t1)
_) -> Value t1 -> m (Value t1)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Value t1
Value (TAsRPC t1)
v
      (STNat {}, Value (TAsRPC t1)
_) -> Value t1 -> m (Value t1)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Value t1
Value (TAsRPC t1)
v
      (STString {}, Value (TAsRPC t1)
_) -> Value t1 -> m (Value t1)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Value t1
Value (TAsRPC t1)
v
      (STBytes {}, Value (TAsRPC t1)
_) -> Value t1 -> m (Value t1)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Value t1
Value (TAsRPC t1)
v
      (STMutez {}, Value (TAsRPC t1)
_) -> Value t1 -> m (Value t1)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Value t1
Value (TAsRPC t1)
v
      (STBool {}, Value (TAsRPC t1)
_) -> Value t1 -> m (Value t1)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Value t1
Value (TAsRPC t1)
v
      (STKeyHash {}, Value (TAsRPC t1)
_) -> Value t1 -> m (Value t1)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Value t1
Value (TAsRPC t1)
v
      (STTimestamp {}, Value (TAsRPC t1)
_) -> Value t1 -> m (Value t1)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Value t1
Value (TAsRPC t1)
v
      (STAddress {}, Value (TAsRPC t1)
_) -> Value t1 -> m (Value t1)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Value t1
Value (TAsRPC t1)
v
      (STBls12381Fr {}, Value (TAsRPC t1)
_) -> Value t1 -> m (Value t1)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Value t1
Value (TAsRPC t1)
v
      (STBls12381G1 {}, Value (TAsRPC t1)
_) -> Value t1 -> m (Value t1)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Value t1
Value (TAsRPC t1)
v
      (STBls12381G2 {}, Value (TAsRPC t1)
_) -> Value t1 -> m (Value t1)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Value t1
Value (TAsRPC t1)
v

-- | Replace all @big_map@ annotations in a value with @nat@ annotations.
notesAsRPC :: Notes t -> Notes (TAsRPC t)
notesAsRPC :: forall (t :: T). Notes t -> Notes (TAsRPC t)
notesAsRPC Notes t
notes =
  case Notes t
notes of
    NTKey {} -> Notes t
Notes (TAsRPC t)
notes
    NTUnit {} -> Notes t
Notes (TAsRPC t)
notes
    NTSignature {} -> Notes t
Notes (TAsRPC t)
notes
    NTChainId {} -> Notes t
Notes (TAsRPC t)
notes
    NTChest {} -> Notes t
Notes (TAsRPC t)
notes
    NTChestKey {} -> Notes t
Notes (TAsRPC t)
notes
    NTOption TypeAnn
typeAnn Notes t1
elemNotes -> TypeAnn -> Notes (TAsRPC t1) -> Notes ('TOption (TAsRPC t1))
forall (t1 :: T). TypeAnn -> Notes t1 -> Notes ('TOption t1)
NTOption TypeAnn
typeAnn (Notes (TAsRPC t1) -> Notes ('TOption (TAsRPC t1)))
-> Notes (TAsRPC t1) -> Notes ('TOption (TAsRPC t1))
forall a b. (a -> b) -> a -> b
$ Notes t1 -> Notes (TAsRPC t1)
forall (t :: T). Notes t -> Notes (TAsRPC t)
notesAsRPC Notes t1
elemNotes
    NTList TypeAnn
typeAnn Notes t1
elemNotes -> TypeAnn -> Notes (TAsRPC t1) -> Notes ('TList (TAsRPC t1))
forall (t1 :: T). TypeAnn -> Notes t1 -> Notes ('TList t1)
NTList TypeAnn
typeAnn (Notes (TAsRPC t1) -> Notes ('TList (TAsRPC t1)))
-> Notes (TAsRPC t1) -> Notes ('TList (TAsRPC t1))
forall a b. (a -> b) -> a -> b
$ Notes t1 -> Notes (TAsRPC t1)
forall (t :: T). Notes t -> Notes (TAsRPC t)
notesAsRPC Notes t1
elemNotes
    NTSet {} -> Notes t
Notes (TAsRPC t)
notes
    NTOperation {} -> Notes t
Notes (TAsRPC t)
notes
    NTContract {} -> Notes t
Notes (TAsRPC t)
notes
    NTTicket {} -> Notes t
Notes (TAsRPC t)
notes
    NTPair TypeAnn
typeAnn FieldAnn
fieldAnn1 FieldAnn
fieldAnn2 VarAnn
varAnn1 VarAnn
varAnn2 Notes p
notes1 Notes q
notes2 ->
      TypeAnn
-> FieldAnn
-> FieldAnn
-> VarAnn
-> VarAnn
-> Notes (TAsRPC p)
-> Notes (TAsRPC q)
-> Notes ('TPair (TAsRPC p) (TAsRPC q))
forall (p :: T) (q :: T).
TypeAnn
-> FieldAnn
-> FieldAnn
-> VarAnn
-> VarAnn
-> Notes p
-> Notes q
-> Notes ('TPair p q)
NTPair TypeAnn
typeAnn FieldAnn
fieldAnn1 FieldAnn
fieldAnn2 VarAnn
varAnn1 VarAnn
varAnn2 (Notes p -> Notes (TAsRPC p)
forall (t :: T). Notes t -> Notes (TAsRPC t)
notesAsRPC Notes p
notes1) (Notes q -> Notes (TAsRPC q)
forall (t :: T). Notes t -> Notes (TAsRPC t)
notesAsRPC Notes q
notes2)
    NTOr TypeAnn
typeAnn FieldAnn
fieldAnn1 FieldAnn
fieldAnn2 Notes p
notes1 Notes q
notes2 ->
      TypeAnn
-> FieldAnn
-> FieldAnn
-> Notes (TAsRPC p)
-> Notes (TAsRPC q)
-> Notes ('TOr (TAsRPC p) (TAsRPC q))
forall (p :: T) (q :: T).
TypeAnn
-> FieldAnn -> FieldAnn -> Notes p -> Notes q -> Notes ('TOr p q)
NTOr TypeAnn
typeAnn FieldAnn
fieldAnn1 FieldAnn
fieldAnn2 (Notes p -> Notes (TAsRPC p)
forall (t :: T). Notes t -> Notes (TAsRPC t)
notesAsRPC Notes p
notes1) (Notes q -> Notes (TAsRPC q)
forall (t :: T). Notes t -> Notes (TAsRPC t)
notesAsRPC Notes q
notes2)
    NTLambda {} -> Notes t
Notes (TAsRPC t)
notes
    NTMap TypeAnn
typeAnn Notes k
keyAnns Notes v
valueNotes -> TypeAnn
-> Notes k -> Notes (TAsRPC v) -> Notes ('TMap k (TAsRPC v))
forall (k :: T) (v :: T).
TypeAnn -> Notes k -> Notes v -> Notes ('TMap k v)
NTMap TypeAnn
typeAnn Notes k
keyAnns (Notes v -> Notes (TAsRPC v)
forall (t :: T). Notes t -> Notes (TAsRPC t)
notesAsRPC Notes v
valueNotes)
    NTBigMap TypeAnn
typeAnn Notes k
_ Notes v
_ -> TypeAnn -> Notes 'TNat
NTNat TypeAnn
typeAnn
    NTInt {} -> Notes t
Notes (TAsRPC t)
notes
    NTNat {} -> Notes t
Notes (TAsRPC t)
notes
    NTString {} -> Notes t
Notes (TAsRPC t)
notes
    NTBytes {} -> Notes t
Notes (TAsRPC t)
notes
    NTMutez {} -> Notes t
Notes (TAsRPC t)
notes
    NTBool {} -> Notes t
Notes (TAsRPC t)
notes
    NTKeyHash {} -> Notes t
Notes (TAsRPC t)
notes
    NTTimestamp {} -> Notes t
Notes (TAsRPC t)
notes
    NTAddress {} -> Notes t
Notes (TAsRPC t)
notes
    NTBls12381Fr {} -> Notes t
Notes (TAsRPC t)
notes
    NTBls12381G1 {} -> Notes t
Notes (TAsRPC t)
notes
    NTBls12381G2 {} -> Notes t
Notes (TAsRPC t)
notes
    NTNever {} -> Notes t
Notes (TAsRPC t)
notes
    NTTxRollupL2Address {} -> Notes t
Notes (TAsRPC t)
notes
    NTSaplingState {} -> Notes t
Notes (TAsRPC t)
notes
    NTSaplingTransaction {} -> Notes t
Notes (TAsRPC t)
notes

----------------------------------------------------------------------------
-- Entailments
----------------------------------------------------------------------------

-- | A proof that if a singleton exists for @t@,
-- then so it does for @TAsRPC t@.
rpcSingIEvi :: forall (t :: T). SingI t :- SingI (TAsRPC t)
rpcSingIEvi :: forall (t :: T). SingI t :- SingI (TAsRPC t)
rpcSingIEvi =
  (SingI t => Dict (SingI (TAsRPC t))) -> SingI t :- SingI (TAsRPC t)
forall (a :: Constraint) (b :: Constraint). (a => Dict b) -> a :- b
Sub ((SingI t => Dict (SingI (TAsRPC t)))
 -> SingI t :- SingI (TAsRPC t))
-> (SingI t => Dict (SingI (TAsRPC t)))
-> SingI t :- SingI (TAsRPC t)
forall a b. (a -> b) -> a -> b
$
    case forall {k} (a :: k). SingI a => Sing a
forall (a :: T). SingI a => Sing a
sing @t of
      Sing t
SingT t
STKey -> Dict (SingI (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
      STUnit {} -> Dict (SingI (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
      STSignature {} -> Dict (SingI (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
      STChainId {} -> Dict (SingI (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
      STChest {} -> Dict (SingI (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
      STChestKey {} -> Dict (SingI (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
      STOption (Sing n
s :: Sing elem) -> Sing n
-> (SingI n => Dict (SingI (TAsRPC t))) -> Dict (SingI (TAsRPC t))
forall {k} (n :: k) r. Sing n -> (SingI n => r) -> r
withSingI Sing n
s ((SingI n => Dict (SingI (TAsRPC t))) -> Dict (SingI (TAsRPC t)))
-> (SingI n => Dict (SingI (TAsRPC t))) -> Dict (SingI (TAsRPC t))
forall a b. (a -> b) -> a -> b
$ SingI (TAsRPC n) => Dict (SingI (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict (SingI (TAsRPC n) => Dict (SingI (TAsRPC t)))
-> (SingI n :- SingI (TAsRPC n)) -> Dict (SingI (TAsRPC t))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ forall (t :: T). SingI t :- SingI (TAsRPC t)
rpcSingIEvi @elem
      STList (Sing n
s :: Sing elem) -> Sing n
-> (SingI n => Dict (SingI (TAsRPC t))) -> Dict (SingI (TAsRPC t))
forall {k} (n :: k) r. Sing n -> (SingI n => r) -> r
withSingI Sing n
s ((SingI n => Dict (SingI (TAsRPC t))) -> Dict (SingI (TAsRPC t)))
-> (SingI n => Dict (SingI (TAsRPC t))) -> Dict (SingI (TAsRPC t))
forall a b. (a -> b) -> a -> b
$  SingI (TAsRPC n) => Dict (SingI (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict (SingI (TAsRPC n) => Dict (SingI (TAsRPC t)))
-> (SingI n :- SingI (TAsRPC n)) -> Dict (SingI (TAsRPC t))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ forall (t :: T). SingI t :- SingI (TAsRPC t)
rpcSingIEvi @elem
      STSet (Sing n
s :: Sing elem) -> Sing n
-> (SingI n => Dict (SingI (TAsRPC t))) -> Dict (SingI (TAsRPC t))
forall {k} (n :: k) r. Sing n -> (SingI n => r) -> r
withSingI Sing n
s ((SingI n => Dict (SingI (TAsRPC t))) -> Dict (SingI (TAsRPC t)))
-> (SingI n => Dict (SingI (TAsRPC t))) -> Dict (SingI (TAsRPC t))
forall a b. (a -> b) -> a -> b
$ SingI (TAsRPC n) => Dict (SingI (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict (SingI (TAsRPC n) => Dict (SingI (TAsRPC t)))
-> (SingI n :- SingI (TAsRPC n)) -> Dict (SingI (TAsRPC t))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ forall (t :: T). SingI t :- SingI (TAsRPC t)
rpcSingIEvi @elem
      STOperation {} -> Dict (SingI (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
      STContract {} -> Dict (SingI (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
      STTicket {} -> Dict (SingI (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
      STPair (Sing n1
sa :: Sing a) (Sing n2
sb :: Sing b) ->
        Sing n1
-> (SingI n1 => Dict (SingI (TAsRPC t))) -> Dict (SingI (TAsRPC t))
forall {k} (n :: k) r. Sing n -> (SingI n => r) -> r
withSingI Sing n1
sa ((SingI n1 => Dict (SingI (TAsRPC t))) -> Dict (SingI (TAsRPC t)))
-> (SingI n1 => Dict (SingI (TAsRPC t))) -> Dict (SingI (TAsRPC t))
forall a b. (a -> b) -> a -> b
$ Sing n2
-> (SingI n2 => Dict (SingI (TAsRPC t))) -> Dict (SingI (TAsRPC t))
forall {k} (n :: k) r. Sing n -> (SingI n => r) -> r
withSingI Sing n2
sb ((SingI n2 => Dict (SingI (TAsRPC t))) -> Dict (SingI (TAsRPC t)))
-> (SingI n2 => Dict (SingI (TAsRPC t))) -> Dict (SingI (TAsRPC t))
forall a b. (a -> b) -> a -> b
$
          SingI (TAsRPC n1) => Dict (SingI (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict (SingI (TAsRPC n1) => Dict (SingI (TAsRPC t)))
-> (SingI n1 :- SingI (TAsRPC n1)) -> Dict (SingI (TAsRPC t))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ forall (t :: T). SingI t :- SingI (TAsRPC t)
rpcSingIEvi @a (SingI (TAsRPC n2) => Dict (SingI (TAsRPC t)))
-> (SingI n2 :- SingI (TAsRPC n2)) -> Dict (SingI (TAsRPC t))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ forall (t :: T). SingI t :- SingI (TAsRPC t)
rpcSingIEvi @b
      STOr (Sing n1
sl :: Sing l) (Sing n2
sr :: Sing r) ->
        Sing n1
-> (SingI n1 => Dict (SingI (TAsRPC t))) -> Dict (SingI (TAsRPC t))
forall {k} (n :: k) r. Sing n -> (SingI n => r) -> r
withSingI Sing n1
sl ((SingI n1 => Dict (SingI (TAsRPC t))) -> Dict (SingI (TAsRPC t)))
-> (SingI n1 => Dict (SingI (TAsRPC t))) -> Dict (SingI (TAsRPC t))
forall a b. (a -> b) -> a -> b
$ Sing n2
-> (SingI n2 => Dict (SingI (TAsRPC t))) -> Dict (SingI (TAsRPC t))
forall {k} (n :: k) r. Sing n -> (SingI n => r) -> r
withSingI Sing n2
sr ((SingI n2 => Dict (SingI (TAsRPC t))) -> Dict (SingI (TAsRPC t)))
-> (SingI n2 => Dict (SingI (TAsRPC t))) -> Dict (SingI (TAsRPC t))
forall a b. (a -> b) -> a -> b
$
          SingI (TAsRPC n1) => Dict (SingI (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict (SingI (TAsRPC n1) => Dict (SingI (TAsRPC t)))
-> (SingI n1 :- SingI (TAsRPC n1)) -> Dict (SingI (TAsRPC t))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ forall (t :: T). SingI t :- SingI (TAsRPC t)
rpcSingIEvi @l (SingI (TAsRPC n2) => Dict (SingI (TAsRPC t)))
-> (SingI n2 :- SingI (TAsRPC n2)) -> Dict (SingI (TAsRPC t))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ forall (t :: T). SingI t :- SingI (TAsRPC t)
rpcSingIEvi @r
      STLambda {} -> Dict (SingI (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
      STMap (Sing n1
sk :: Sing k) (Sing n2
sv :: Sing v) ->
        Sing n1
-> (SingI n1 => Dict (SingI (TAsRPC t))) -> Dict (SingI (TAsRPC t))
forall {k} (n :: k) r. Sing n -> (SingI n => r) -> r
withSingI Sing n1
sk ((SingI n1 => Dict (SingI (TAsRPC t))) -> Dict (SingI (TAsRPC t)))
-> (SingI n1 => Dict (SingI (TAsRPC t))) -> Dict (SingI (TAsRPC t))
forall a b. (a -> b) -> a -> b
$ Sing n2
-> (SingI n2 => Dict (SingI (TAsRPC t))) -> Dict (SingI (TAsRPC t))
forall {k} (n :: k) r. Sing n -> (SingI n => r) -> r
withSingI Sing n2
sv ((SingI n2 => Dict (SingI (TAsRPC t))) -> Dict (SingI (TAsRPC t)))
-> (SingI n2 => Dict (SingI (TAsRPC t))) -> Dict (SingI (TAsRPC t))
forall a b. (a -> b) -> a -> b
$
          SingI (TAsRPC n1) => Dict (SingI (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict (SingI (TAsRPC n1) => Dict (SingI (TAsRPC t)))
-> (SingI n1 :- SingI (TAsRPC n1)) -> Dict (SingI (TAsRPC t))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ forall (t :: T). SingI t :- SingI (TAsRPC t)
rpcSingIEvi @k (SingI (TAsRPC n2) => Dict (SingI (TAsRPC t)))
-> (SingI n2 :- SingI (TAsRPC n2)) -> Dict (SingI (TAsRPC t))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ forall (t :: T). SingI t :- SingI (TAsRPC t)
rpcSingIEvi @v
      STBigMap {} -> Dict (SingI (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
      STInt {} -> Dict (SingI (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
      STNat {} -> Dict (SingI (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
      STString {} -> Dict (SingI (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
      STBytes {} -> Dict (SingI (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
      STMutez {} -> Dict (SingI (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
      STBool {} -> Dict (SingI (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
      STKeyHash {} -> Dict (SingI (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
      STBls12381Fr {} -> Dict (SingI (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
      STBls12381G1 {} -> Dict (SingI (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
      STBls12381G2 {} -> Dict (SingI (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
      STTimestamp {} -> Dict (SingI (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
      STAddress {} -> Dict (SingI (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
      STNever {} -> Dict (SingI (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
      STTxRollupL2Address {} -> Dict (SingI (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
      STSaplingState Sing n
_ -> Dict (SingI (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
      STSaplingTransaction Sing n
_ -> Dict (SingI (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict

-- | A proof that if @t@ is well-typed, then @TAsRPC t@ is also well-typed.
rpcWellTypedEvi :: forall (t :: T). WellTyped t => WellTyped t :- WellTyped (TAsRPC t)
rpcWellTypedEvi :: forall (t :: T). WellTyped t => WellTyped t :- WellTyped (TAsRPC t)
rpcWellTypedEvi = Sing t -> WellTyped t :- WellTyped (TAsRPC t)
forall (t :: T).
WellTyped t =>
Sing t -> WellTyped t :- WellTyped (TAsRPC t)
rpcWellTypedEvi' Sing t
forall {k} (a :: k). SingI a => Sing a
sing

rpcWellTypedEvi'
  :: WellTyped t
  => Sing t
  -> WellTyped t :- WellTyped (TAsRPC t)
rpcWellTypedEvi' :: forall (t :: T).
WellTyped t =>
Sing t -> WellTyped t :- WellTyped (TAsRPC t)
rpcWellTypedEvi' Sing t
sng = (WellTyped t => Dict (WellTyped (TAsRPC t)))
-> WellTyped t :- WellTyped (TAsRPC t)
forall (a :: Constraint) (b :: Constraint). (a => Dict b) -> a :- b
Sub ((WellTyped t => Dict (WellTyped (TAsRPC t)))
 -> WellTyped t :- WellTyped (TAsRPC t))
-> (WellTyped t => Dict (WellTyped (TAsRPC t)))
-> WellTyped t :- WellTyped (TAsRPC t)
forall a b. (a -> b) -> a -> b
$ case Sing t
sng of
  Sing t
SingT t
STKey -> Dict (WellTyped (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STUnit {} -> Dict (WellTyped (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STSignature {} -> Dict (WellTyped (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STChainId {} -> Dict (WellTyped (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STOption Sing n
s -> WellTyped (TAsRPC n) => Dict (WellTyped (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict (WellTyped (TAsRPC n) => Dict (WellTyped (TAsRPC t)))
-> (WellTyped n :- WellTyped (TAsRPC n))
-> Dict (WellTyped (TAsRPC t))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ Sing n -> WellTyped n :- WellTyped (TAsRPC n)
forall (t :: T).
WellTyped t =>
Sing t -> WellTyped t :- WellTyped (TAsRPC t)
rpcWellTypedEvi' Sing n
s
  STList Sing n
s -> WellTyped (TAsRPC n) => Dict (WellTyped (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict (WellTyped (TAsRPC n) => Dict (WellTyped (TAsRPC t)))
-> (WellTyped n :- WellTyped (TAsRPC n))
-> Dict (WellTyped (TAsRPC t))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ Sing n -> WellTyped n :- WellTyped (TAsRPC n)
forall (t :: T).
WellTyped t =>
Sing t -> WellTyped t :- WellTyped (TAsRPC t)
rpcWellTypedEvi' Sing n
s
  STSet Sing n
s -> WellTyped (TAsRPC n) => Dict (WellTyped (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict (WellTyped (TAsRPC n) => Dict (WellTyped (TAsRPC t)))
-> (WellTyped n :- WellTyped (TAsRPC n))
-> Dict (WellTyped (TAsRPC t))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ Sing n -> WellTyped n :- WellTyped (TAsRPC n)
forall (t :: T).
WellTyped t =>
Sing t -> WellTyped t :- WellTyped (TAsRPC t)
rpcWellTypedEvi' Sing n
s
  STOperation {} -> Dict (WellTyped (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STContract Sing n
s -> WellTyped (TAsRPC n) => Dict (WellTyped (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict (WellTyped (TAsRPC n) => Dict (WellTyped (TAsRPC t)))
-> (WellTyped n :- WellTyped (TAsRPC n))
-> Dict (WellTyped (TAsRPC t))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ Sing n -> WellTyped n :- WellTyped (TAsRPC n)
forall (t :: T).
WellTyped t =>
Sing t -> WellTyped t :- WellTyped (TAsRPC t)
rpcWellTypedEvi' Sing n
s
  STTicket Sing n
s -> WellTyped (TAsRPC n) => Dict (WellTyped (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict (WellTyped (TAsRPC n) => Dict (WellTyped (TAsRPC t)))
-> (WellTyped n :- WellTyped (TAsRPC n))
-> Dict (WellTyped (TAsRPC t))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ Sing n -> WellTyped n :- WellTyped (TAsRPC n)
forall (t :: T).
WellTyped t =>
Sing t -> WellTyped t :- WellTyped (TAsRPC t)
rpcWellTypedEvi' Sing n
s
  STPair Sing n1
sa Sing n2
sb -> WellTyped (TAsRPC n1) => Dict (WellTyped (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict (WellTyped (TAsRPC n1) => Dict (WellTyped (TAsRPC t)))
-> (WellTyped n1 :- WellTyped (TAsRPC n1))
-> Dict (WellTyped (TAsRPC t))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ Sing n1 -> WellTyped n1 :- WellTyped (TAsRPC n1)
forall (t :: T).
WellTyped t =>
Sing t -> WellTyped t :- WellTyped (TAsRPC t)
rpcWellTypedEvi' Sing n1
sa (WellTyped (TAsRPC n2) => Dict (WellTyped (TAsRPC t)))
-> (WellTyped n2 :- WellTyped (TAsRPC n2))
-> Dict (WellTyped (TAsRPC t))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ Sing n2 -> WellTyped n2 :- WellTyped (TAsRPC n2)
forall (t :: T).
WellTyped t =>
Sing t -> WellTyped t :- WellTyped (TAsRPC t)
rpcWellTypedEvi' Sing n2
sb
  STOr Sing n1
sl Sing n2
sr -> WellTyped (TAsRPC n1) => Dict (WellTyped (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict (WellTyped (TAsRPC n1) => Dict (WellTyped (TAsRPC t)))
-> (WellTyped n1 :- WellTyped (TAsRPC n1))
-> Dict (WellTyped (TAsRPC t))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ Sing n1 -> WellTyped n1 :- WellTyped (TAsRPC n1)
forall (t :: T).
WellTyped t =>
Sing t -> WellTyped t :- WellTyped (TAsRPC t)
rpcWellTypedEvi' Sing n1
sl (WellTyped (TAsRPC n2) => Dict (WellTyped (TAsRPC t)))
-> (WellTyped n2 :- WellTyped (TAsRPC n2))
-> Dict (WellTyped (TAsRPC t))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ Sing n2 -> WellTyped n2 :- WellTyped (TAsRPC n2)
forall (t :: T).
WellTyped t =>
Sing t -> WellTyped t :- WellTyped (TAsRPC t)
rpcWellTypedEvi' Sing n2
sr
  STLambda Sing n1
sa Sing n2
sb -> WellTyped (TAsRPC n1) => Dict (WellTyped (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict (WellTyped (TAsRPC n1) => Dict (WellTyped (TAsRPC t)))
-> (WellTyped n1 :- WellTyped (TAsRPC n1))
-> Dict (WellTyped (TAsRPC t))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ Sing n1 -> WellTyped n1 :- WellTyped (TAsRPC n1)
forall (t :: T).
WellTyped t =>
Sing t -> WellTyped t :- WellTyped (TAsRPC t)
rpcWellTypedEvi' Sing n1
sa (WellTyped (TAsRPC n2) => Dict (WellTyped (TAsRPC t)))
-> (WellTyped n2 :- WellTyped (TAsRPC n2))
-> Dict (WellTyped (TAsRPC t))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ Sing n2 -> WellTyped n2 :- WellTyped (TAsRPC n2)
forall (t :: T).
WellTyped t =>
Sing t -> WellTyped t :- WellTyped (TAsRPC t)
rpcWellTypedEvi' Sing n2
sb
  STMap Sing n1
sk Sing n2
sv -> WellTyped (TAsRPC n1) => Dict (WellTyped (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict (WellTyped (TAsRPC n1) => Dict (WellTyped (TAsRPC t)))
-> (WellTyped n1 :- WellTyped (TAsRPC n1))
-> Dict (WellTyped (TAsRPC t))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ Sing n1 -> WellTyped n1 :- WellTyped (TAsRPC n1)
forall (t :: T).
WellTyped t =>
Sing t -> WellTyped t :- WellTyped (TAsRPC t)
rpcWellTypedEvi' Sing n1
sk (WellTyped (TAsRPC n2) => Dict (WellTyped (TAsRPC t)))
-> (WellTyped n2 :- WellTyped (TAsRPC n2))
-> Dict (WellTyped (TAsRPC t))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ Sing n2 -> WellTyped n2 :- WellTyped (TAsRPC n2)
forall (t :: T).
WellTyped t =>
Sing t -> WellTyped t :- WellTyped (TAsRPC t)
rpcWellTypedEvi' Sing n2
sv
  STBigMap Sing n1
sk Sing n2
sv -> WellTyped (TAsRPC n1) => Dict (WellTyped (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict (WellTyped (TAsRPC n1) => Dict (WellTyped (TAsRPC t)))
-> (WellTyped n1 :- WellTyped (TAsRPC n1))
-> Dict (WellTyped (TAsRPC t))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ Sing n1 -> WellTyped n1 :- WellTyped (TAsRPC n1)
forall (t :: T).
WellTyped t =>
Sing t -> WellTyped t :- WellTyped (TAsRPC t)
rpcWellTypedEvi' Sing n1
sk (WellTyped (TAsRPC n2) => Dict (WellTyped (TAsRPC t)))
-> (WellTyped n2 :- WellTyped (TAsRPC n2))
-> Dict (WellTyped (TAsRPC t))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ Sing n2 -> WellTyped n2 :- WellTyped (TAsRPC n2)
forall (t :: T).
WellTyped t =>
Sing t -> WellTyped t :- WellTyped (TAsRPC t)
rpcWellTypedEvi' Sing n2
sv
  STInt {} -> Dict (WellTyped (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STNat {} -> Dict (WellTyped (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STString {} -> Dict (WellTyped (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STBytes {} -> Dict (WellTyped (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STMutez {} -> Dict (WellTyped (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STBool {} -> Dict (WellTyped (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STKeyHash {} -> Dict (WellTyped (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STBls12381Fr {} -> Dict (WellTyped (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STBls12381G1 {} -> Dict (WellTyped (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STBls12381G2 {} -> Dict (WellTyped (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STTimestamp {} -> Dict (WellTyped (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STAddress {} -> Dict (WellTyped (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STChest {} -> Dict (WellTyped (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STChestKey {} -> Dict (WellTyped (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STNever {} -> Dict (WellTyped (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STTxRollupL2Address {} -> Dict (WellTyped (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STSaplingState Sing n
_ -> Dict (WellTyped (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STSaplingTransaction Sing n
_ -> Dict (WellTyped (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict

-- | A proof that if @t@ does not contain any operations, then neither does @TAsRPC t@.
rpcHasNoOpEvi :: forall (t :: T). (SingI t, HasNoOp t) => HasNoOp t :- HasNoOp (TAsRPC t)
rpcHasNoOpEvi :: forall (t :: T).
(SingI t, HasNoOp t) =>
HasNoOp t :- HasNoOp (TAsRPC t)
rpcHasNoOpEvi = Sing t -> HasNoOp t :- HasNoOp (TAsRPC t)
forall (t :: T).
HasNoOp t =>
Sing t -> HasNoOp t :- HasNoOp (TAsRPC t)
rpcHasNoOpEvi' Sing t
forall {k} (a :: k). SingI a => Sing a
sing

rpcHasNoOpEvi'
  :: HasNoOp t
  => Sing t
  -> HasNoOp t :- HasNoOp (TAsRPC t)
rpcHasNoOpEvi' :: forall (t :: T).
HasNoOp t =>
Sing t -> HasNoOp t :- HasNoOp (TAsRPC t)
rpcHasNoOpEvi' Sing t
sng = (HasNoOp t => Dict (HasNoOp (TAsRPC t)))
-> HasNoOp t :- HasNoOp (TAsRPC t)
forall (a :: Constraint) (b :: Constraint). (a => Dict b) -> a :- b
Sub ((HasNoOp t => Dict (HasNoOp (TAsRPC t)))
 -> HasNoOp t :- HasNoOp (TAsRPC t))
-> (HasNoOp t => Dict (HasNoOp (TAsRPC t)))
-> HasNoOp t :- HasNoOp (TAsRPC t)
forall a b. (a -> b) -> a -> b
$ case Sing t
sng of
  Sing t
SingT t
STKey -> Dict (HasNoOp (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STUnit {} -> Dict (HasNoOp (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STSignature {} -> Dict (HasNoOp (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STChainId {} -> Dict (HasNoOp (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STChest {} -> Dict (HasNoOp (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STChestKey {} -> Dict (HasNoOp (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STOption Sing n
s -> HasNoOp (TAsRPC n) => Dict (HasNoOp (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict (HasNoOp (TAsRPC n) => Dict (HasNoOp (TAsRPC t)))
-> (HasNoOp n :- HasNoOp (TAsRPC n)) -> Dict (HasNoOp (TAsRPC t))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ Sing n -> HasNoOp n :- HasNoOp (TAsRPC n)
forall (t :: T).
HasNoOp t =>
Sing t -> HasNoOp t :- HasNoOp (TAsRPC t)
rpcHasNoOpEvi' Sing n
s
  STList Sing n
s -> HasNoOp (TAsRPC n) => Dict (HasNoOp (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict (HasNoOp (TAsRPC n) => Dict (HasNoOp (TAsRPC t)))
-> (HasNoOp n :- HasNoOp (TAsRPC n)) -> Dict (HasNoOp (TAsRPC t))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ Sing n -> HasNoOp n :- HasNoOp (TAsRPC n)
forall (t :: T).
HasNoOp t =>
Sing t -> HasNoOp t :- HasNoOp (TAsRPC t)
rpcHasNoOpEvi' Sing n
s
  STSet Sing n
s -> HasNoOp (TAsRPC n) => Dict (HasNoOp (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict (HasNoOp (TAsRPC n) => Dict (HasNoOp (TAsRPC t)))
-> (HasNoOp n :- HasNoOp (TAsRPC n)) -> Dict (HasNoOp (TAsRPC t))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ Sing n -> HasNoOp n :- HasNoOp (TAsRPC n)
forall (t :: T).
HasNoOp t =>
Sing t -> HasNoOp t :- HasNoOp (TAsRPC t)
rpcHasNoOpEvi' Sing n
s
  STContract {} -> Dict (HasNoOp (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STTicket {} -> Dict (HasNoOp (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STPair Sing n1
sa Sing n2
sb -> case Sing n1 -> OpPresence n1
forall (ty :: T). Sing ty -> OpPresence ty
checkOpPresence Sing n1
sa of
    OpPresence n1
OpAbsent -> HasNoOp (TAsRPC n1) => Dict (HasNoOp (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict (HasNoOp (TAsRPC n1) => Dict (HasNoOp (TAsRPC t)))
-> (HasNoOp n1 :- HasNoOp (TAsRPC n1)) -> Dict (HasNoOp (TAsRPC t))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ Sing n1 -> HasNoOp n1 :- HasNoOp (TAsRPC n1)
forall (t :: T).
HasNoOp t =>
Sing t -> HasNoOp t :- HasNoOp (TAsRPC t)
rpcHasNoOpEvi' Sing n1
sa (HasNoOp (TAsRPC n2) => Dict (HasNoOp (TAsRPC t)))
-> (HasNoOp n2 :- HasNoOp (TAsRPC n2)) -> Dict (HasNoOp (TAsRPC t))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ Sing n2 -> HasNoOp n2 :- HasNoOp (TAsRPC n2)
forall (t :: T).
HasNoOp t =>
Sing t -> HasNoOp t :- HasNoOp (TAsRPC t)
rpcHasNoOpEvi' Sing n2
sb
  STOr Sing n1
sl Sing n2
sr -> case Sing n1 -> OpPresence n1
forall (ty :: T). Sing ty -> OpPresence ty
checkOpPresence Sing n1
sl of
    OpPresence n1
OpAbsent -> HasNoOp (TAsRPC n1) => Dict (HasNoOp (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict (HasNoOp (TAsRPC n1) => Dict (HasNoOp (TAsRPC t)))
-> (HasNoOp n1 :- HasNoOp (TAsRPC n1)) -> Dict (HasNoOp (TAsRPC t))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ Sing n1 -> HasNoOp n1 :- HasNoOp (TAsRPC n1)
forall (t :: T).
HasNoOp t =>
Sing t -> HasNoOp t :- HasNoOp (TAsRPC t)
rpcHasNoOpEvi' Sing n1
sl (HasNoOp (TAsRPC n2) => Dict (HasNoOp (TAsRPC t)))
-> (HasNoOp n2 :- HasNoOp (TAsRPC n2)) -> Dict (HasNoOp (TAsRPC t))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ Sing n2 -> HasNoOp n2 :- HasNoOp (TAsRPC n2)
forall (t :: T).
HasNoOp t =>
Sing t -> HasNoOp t :- HasNoOp (TAsRPC t)
rpcHasNoOpEvi' Sing n2
sr
  STLambda {} -> Dict (HasNoOp (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STMap Sing n1
_ Sing n2
sv -> case Sing n2 -> OpPresence n2
forall (ty :: T). Sing ty -> OpPresence ty
checkOpPresence Sing n2
sv of
    OpPresence n2
OpAbsent -> HasNoOp (TAsRPC n2) => Dict (HasNoOp (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict (HasNoOp (TAsRPC n2) => Dict (HasNoOp (TAsRPC t)))
-> (HasNoOp n2 :- HasNoOp (TAsRPC n2)) -> Dict (HasNoOp (TAsRPC t))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ Sing n2 -> HasNoOp n2 :- HasNoOp (TAsRPC n2)
forall (t :: T).
HasNoOp t =>
Sing t -> HasNoOp t :- HasNoOp (TAsRPC t)
rpcHasNoOpEvi' Sing n2
sv
  STBigMap {} -> Dict (HasNoOp (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STInt {} -> Dict (HasNoOp (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STNat {} -> Dict (HasNoOp (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STString {} -> Dict (HasNoOp (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STBytes {} -> Dict (HasNoOp (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STMutez {} -> Dict (HasNoOp (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STBool {} -> Dict (HasNoOp (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STKeyHash {} -> Dict (HasNoOp (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STBls12381Fr {} -> Dict (HasNoOp (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STBls12381G1 {} -> Dict (HasNoOp (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STBls12381G2 {} -> Dict (HasNoOp (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STTimestamp {} -> Dict (HasNoOp (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STAddress {} -> Dict (HasNoOp (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STTxRollupL2Address {} -> Dict (HasNoOp (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STNever {} -> Dict (HasNoOp (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STSaplingState {} -> Dict (HasNoOp (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STSaplingTransaction {} -> Dict (HasNoOp (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict

-- | A proof that @AsRPC (Value t)@ does not contain big_maps.
rpcHasNoBigMapEvi :: forall (t :: T). SingI t => Dict (HasNoBigMap (TAsRPC t))
rpcHasNoBigMapEvi :: forall (t :: T). SingI t => Dict (HasNoBigMap (TAsRPC t))
rpcHasNoBigMapEvi = Sing t -> Dict (HasNoBigMap (TAsRPC t))
forall (t :: T). Sing t -> Dict (HasNoBigMap (TAsRPC t))
rpcHasNoBigMapEvi' (forall {k} (a :: k). SingI a => Sing a
forall (a :: T). SingI a => Sing a
sing @t)

rpcHasNoBigMapEvi' :: Sing t -> Dict (HasNoBigMap (TAsRPC t))
rpcHasNoBigMapEvi' :: forall (t :: T). Sing t -> Dict (HasNoBigMap (TAsRPC t))
rpcHasNoBigMapEvi' = \case
  Sing t
SingT t
STKey -> Dict (HasNoBigMap (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STUnit {} -> Dict (HasNoBigMap (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STSignature {} -> Dict (HasNoBigMap (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STChainId {} -> Dict (HasNoBigMap (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STChest {} -> Dict (HasNoBigMap (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STChestKey {} -> Dict (HasNoBigMap (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STOption Sing n
s -> HasNoBigMap (TAsRPC n) => Dict (HasNoBigMap ('TOption (TAsRPC n)))
forall (a :: Constraint). a => Dict a
Dict (HasNoBigMap (TAsRPC n) =>
 Dict (HasNoBigMap ('TOption (TAsRPC n))))
-> Dict (HasNoBigMap (TAsRPC n))
-> Dict (HasNoBigMap ('TOption (TAsRPC n)))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ Sing n -> Dict (HasNoBigMap (TAsRPC n))
forall (t :: T). Sing t -> Dict (HasNoBigMap (TAsRPC t))
rpcHasNoBigMapEvi' Sing n
s
  STList Sing n
s -> HasNoBigMap (TAsRPC n) => Dict (HasNoBigMap ('TList (TAsRPC n)))
forall (a :: Constraint). a => Dict a
Dict (HasNoBigMap (TAsRPC n) => Dict (HasNoBigMap ('TList (TAsRPC n))))
-> Dict (HasNoBigMap (TAsRPC n))
-> Dict (HasNoBigMap ('TList (TAsRPC n)))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ Sing n -> Dict (HasNoBigMap (TAsRPC n))
forall (t :: T). Sing t -> Dict (HasNoBigMap (TAsRPC t))
rpcHasNoBigMapEvi' Sing n
s
  STSet Sing n
s -> HasNoBigMap (TAsRPC n) => Dict (HasNoBigMap ('TSet n))
forall (a :: Constraint). a => Dict a
Dict (HasNoBigMap (TAsRPC n) => Dict (HasNoBigMap ('TSet n)))
-> Dict (HasNoBigMap (TAsRPC n)) -> Dict (HasNoBigMap ('TSet n))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ Sing n -> Dict (HasNoBigMap (TAsRPC n))
forall (t :: T). Sing t -> Dict (HasNoBigMap (TAsRPC t))
rpcHasNoBigMapEvi' Sing n
s
  STOperation {} -> Dict (HasNoBigMap (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STContract {} -> Dict (HasNoBigMap (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STTicket {} -> Dict (HasNoBigMap (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STPair Sing n1
sa Sing n2
sb -> HasNoBigMap (TAsRPC n1) =>
Dict (HasNoBigMap ('TPair (TAsRPC n1) (TAsRPC n2)))
forall (a :: Constraint). a => Dict a
Dict (HasNoBigMap (TAsRPC n1) =>
 Dict (HasNoBigMap ('TPair (TAsRPC n1) (TAsRPC n2))))
-> Dict (HasNoBigMap (TAsRPC n1))
-> Dict (HasNoBigMap ('TPair (TAsRPC n1) (TAsRPC n2)))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ Sing n1 -> Dict (HasNoBigMap (TAsRPC n1))
forall (t :: T). Sing t -> Dict (HasNoBigMap (TAsRPC t))
rpcHasNoBigMapEvi' Sing n1
sa (HasNoBigMap (TAsRPC n2) =>
 Dict (HasNoBigMap ('TPair (TAsRPC n1) (TAsRPC n2))))
-> Dict (HasNoBigMap (TAsRPC n2))
-> Dict (HasNoBigMap ('TPair (TAsRPC n1) (TAsRPC n2)))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ Sing n2 -> Dict (HasNoBigMap (TAsRPC n2))
forall (t :: T). Sing t -> Dict (HasNoBigMap (TAsRPC t))
rpcHasNoBigMapEvi' Sing n2
sb
  STOr Sing n1
sl Sing n2
sr -> HasNoBigMap (TAsRPC n1) =>
Dict (HasNoBigMap ('TOr (TAsRPC n1) (TAsRPC n2)))
forall (a :: Constraint). a => Dict a
Dict (HasNoBigMap (TAsRPC n1) =>
 Dict (HasNoBigMap ('TOr (TAsRPC n1) (TAsRPC n2))))
-> Dict (HasNoBigMap (TAsRPC n1))
-> Dict (HasNoBigMap ('TOr (TAsRPC n1) (TAsRPC n2)))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ Sing n1 -> Dict (HasNoBigMap (TAsRPC n1))
forall (t :: T). Sing t -> Dict (HasNoBigMap (TAsRPC t))
rpcHasNoBigMapEvi' Sing n1
sl (HasNoBigMap (TAsRPC n2) =>
 Dict (HasNoBigMap ('TOr (TAsRPC n1) (TAsRPC n2))))
-> Dict (HasNoBigMap (TAsRPC n2))
-> Dict (HasNoBigMap ('TOr (TAsRPC n1) (TAsRPC n2)))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ Sing n2 -> Dict (HasNoBigMap (TAsRPC n2))
forall (t :: T). Sing t -> Dict (HasNoBigMap (TAsRPC t))
rpcHasNoBigMapEvi' Sing n2
sr
  STLambda {} -> Dict (HasNoBigMap (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STMap Sing n1
sk Sing n2
sv -> HasNoBigMap (TAsRPC n1) =>
Dict (HasNoBigMap ('TMap n1 (TAsRPC n2)))
forall (a :: Constraint). a => Dict a
Dict (HasNoBigMap (TAsRPC n1) =>
 Dict (HasNoBigMap ('TMap n1 (TAsRPC n2))))
-> Dict (HasNoBigMap (TAsRPC n1))
-> Dict (HasNoBigMap ('TMap n1 (TAsRPC n2)))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ Sing n1 -> Dict (HasNoBigMap (TAsRPC n1))
forall (t :: T). Sing t -> Dict (HasNoBigMap (TAsRPC t))
rpcHasNoBigMapEvi' Sing n1
sk (HasNoBigMap (TAsRPC n2) =>
 Dict (HasNoBigMap ('TMap n1 (TAsRPC n2))))
-> Dict (HasNoBigMap (TAsRPC n2))
-> Dict (HasNoBigMap ('TMap n1 (TAsRPC n2)))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ Sing n2 -> Dict (HasNoBigMap (TAsRPC n2))
forall (t :: T). Sing t -> Dict (HasNoBigMap (TAsRPC t))
rpcHasNoBigMapEvi' Sing n2
sv
  STBigMap {} -> Dict (HasNoBigMap (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STInt {} -> Dict (HasNoBigMap (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STNat {} -> Dict (HasNoBigMap (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STString {} -> Dict (HasNoBigMap (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STBytes {} -> Dict (HasNoBigMap (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STMutez {} -> Dict (HasNoBigMap (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STBool {} -> Dict (HasNoBigMap (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STKeyHash {} -> Dict (HasNoBigMap (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STBls12381Fr {} -> Dict (HasNoBigMap (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STBls12381G1 {} -> Dict (HasNoBigMap (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STBls12381G2 {} -> Dict (HasNoBigMap (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STTimestamp {} -> Dict (HasNoBigMap (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STAddress {} -> Dict (HasNoBigMap (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STNever {} -> Dict (HasNoBigMap (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STSaplingState {} -> Dict (HasNoBigMap (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STSaplingTransaction {} -> Dict (HasNoBigMap (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STTxRollupL2Address {} -> Dict (HasNoBigMap (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict

-- | A proof that @AsRPC (Value t)@ does not contain big_maps.
rpcHasNoNestedBigMapsEvi
  :: forall (t :: T).
     SingI t
  => Dict (HasNoNestedBigMaps (TAsRPC t))
rpcHasNoNestedBigMapsEvi :: forall (t :: T). SingI t => Dict (HasNoNestedBigMaps (TAsRPC t))
rpcHasNoNestedBigMapsEvi = Sing t -> Dict (HasNoNestedBigMaps (TAsRPC t))
forall (t :: T). Sing t -> Dict (HasNoNestedBigMaps (TAsRPC t))
rpcHasNoNestedBigMapsEvi' (forall {k} (a :: k). SingI a => Sing a
forall (a :: T). SingI a => Sing a
sing @t)

rpcHasNoNestedBigMapsEvi' :: Sing t -> Dict (HasNoNestedBigMaps (TAsRPC t))
rpcHasNoNestedBigMapsEvi' :: forall (t :: T). Sing t -> Dict (HasNoNestedBigMaps (TAsRPC t))
rpcHasNoNestedBigMapsEvi' = \case
  Sing t
SingT t
STKey -> Dict (HasNoNestedBigMaps (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STUnit {} -> Dict (HasNoNestedBigMaps (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STSignature {} -> Dict (HasNoNestedBigMaps (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STChainId {} -> Dict (HasNoNestedBigMaps (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STChest {} -> Dict (HasNoNestedBigMaps (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STChestKey {} -> Dict (HasNoNestedBigMaps (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STOption Sing n
s -> HasNoNestedBigMaps (TAsRPC n) =>
Dict (HasNoNestedBigMaps ('TOption (TAsRPC n)))
forall (a :: Constraint). a => Dict a
Dict (HasNoNestedBigMaps (TAsRPC n) =>
 Dict (HasNoNestedBigMaps ('TOption (TAsRPC n))))
-> Dict (HasNoNestedBigMaps (TAsRPC n))
-> Dict (HasNoNestedBigMaps ('TOption (TAsRPC n)))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ Sing n -> Dict (HasNoNestedBigMaps (TAsRPC n))
forall (t :: T). Sing t -> Dict (HasNoNestedBigMaps (TAsRPC t))
rpcHasNoNestedBigMapsEvi' Sing n
s
  STList Sing n
s -> HasNoNestedBigMaps (TAsRPC n) =>
Dict (HasNoNestedBigMaps ('TList (TAsRPC n)))
forall (a :: Constraint). a => Dict a
Dict (HasNoNestedBigMaps (TAsRPC n) =>
 Dict (HasNoNestedBigMaps ('TList (TAsRPC n))))
-> Dict (HasNoNestedBigMaps (TAsRPC n))
-> Dict (HasNoNestedBigMaps ('TList (TAsRPC n)))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ Sing n -> Dict (HasNoNestedBigMaps (TAsRPC n))
forall (t :: T). Sing t -> Dict (HasNoNestedBigMaps (TAsRPC t))
rpcHasNoNestedBigMapsEvi' Sing n
s
  STSet Sing n
s -> HasNoNestedBigMaps (TAsRPC n) =>
Dict (HasNoNestedBigMaps ('TSet n))
forall (a :: Constraint). a => Dict a
Dict (HasNoNestedBigMaps (TAsRPC n) =>
 Dict (HasNoNestedBigMaps ('TSet n)))
-> Dict (HasNoNestedBigMaps (TAsRPC n))
-> Dict (HasNoNestedBigMaps ('TSet n))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ Sing n -> Dict (HasNoNestedBigMaps (TAsRPC n))
forall (t :: T). Sing t -> Dict (HasNoNestedBigMaps (TAsRPC t))
rpcHasNoNestedBigMapsEvi' Sing n
s
  STOperation {} -> Dict (HasNoNestedBigMaps (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STContract {} -> Dict (HasNoNestedBigMaps (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STTicket {} -> Dict (HasNoNestedBigMaps (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STPair Sing n1
sa Sing n2
sb ->
    HasNoNestedBigMaps (TAsRPC n1) =>
Dict (HasNoNestedBigMaps ('TPair (TAsRPC n1) (TAsRPC n2)))
forall (a :: Constraint). a => Dict a
Dict (HasNoNestedBigMaps (TAsRPC n1) =>
 Dict (HasNoNestedBigMaps ('TPair (TAsRPC n1) (TAsRPC n2))))
-> Dict (HasNoNestedBigMaps (TAsRPC n1))
-> Dict (HasNoNestedBigMaps ('TPair (TAsRPC n1) (TAsRPC n2)))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ Sing n1 -> Dict (HasNoNestedBigMaps (TAsRPC n1))
forall (t :: T). Sing t -> Dict (HasNoNestedBigMaps (TAsRPC t))
rpcHasNoNestedBigMapsEvi' Sing n1
sa (HasNoNestedBigMaps (TAsRPC n2) =>
 Dict (HasNoNestedBigMaps ('TPair (TAsRPC n1) (TAsRPC n2))))
-> Dict (HasNoNestedBigMaps (TAsRPC n2))
-> Dict (HasNoNestedBigMaps ('TPair (TAsRPC n1) (TAsRPC n2)))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ Sing n2 -> Dict (HasNoNestedBigMaps (TAsRPC n2))
forall (t :: T). Sing t -> Dict (HasNoNestedBigMaps (TAsRPC t))
rpcHasNoNestedBigMapsEvi' Sing n2
sb
  STOr Sing n1
sl Sing n2
sr ->
    HasNoNestedBigMaps (TAsRPC n1) =>
Dict (HasNoNestedBigMaps ('TOr (TAsRPC n1) (TAsRPC n2)))
forall (a :: Constraint). a => Dict a
Dict (HasNoNestedBigMaps (TAsRPC n1) =>
 Dict (HasNoNestedBigMaps ('TOr (TAsRPC n1) (TAsRPC n2))))
-> Dict (HasNoNestedBigMaps (TAsRPC n1))
-> Dict (HasNoNestedBigMaps ('TOr (TAsRPC n1) (TAsRPC n2)))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ Sing n1 -> Dict (HasNoNestedBigMaps (TAsRPC n1))
forall (t :: T). Sing t -> Dict (HasNoNestedBigMaps (TAsRPC t))
rpcHasNoNestedBigMapsEvi' Sing n1
sl (HasNoNestedBigMaps (TAsRPC n2) =>
 Dict (HasNoNestedBigMaps ('TOr (TAsRPC n1) (TAsRPC n2))))
-> Dict (HasNoNestedBigMaps (TAsRPC n2))
-> Dict (HasNoNestedBigMaps ('TOr (TAsRPC n1) (TAsRPC n2)))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ Sing n2 -> Dict (HasNoNestedBigMaps (TAsRPC n2))
forall (t :: T). Sing t -> Dict (HasNoNestedBigMaps (TAsRPC t))
rpcHasNoNestedBigMapsEvi' Sing n2
sr
  STLambda {} -> Dict (HasNoNestedBigMaps (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STMap Sing n1
sk Sing n2
sv ->
    HasNoNestedBigMaps (TAsRPC n1) =>
Dict (HasNoNestedBigMaps ('TMap n1 (TAsRPC n2)))
forall (a :: Constraint). a => Dict a
Dict (HasNoNestedBigMaps (TAsRPC n1) =>
 Dict (HasNoNestedBigMaps ('TMap n1 (TAsRPC n2))))
-> Dict (HasNoNestedBigMaps (TAsRPC n1))
-> Dict (HasNoNestedBigMaps ('TMap n1 (TAsRPC n2)))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ Sing n1 -> Dict (HasNoNestedBigMaps (TAsRPC n1))
forall (t :: T). Sing t -> Dict (HasNoNestedBigMaps (TAsRPC t))
rpcHasNoNestedBigMapsEvi' Sing n1
sk (HasNoNestedBigMaps (TAsRPC n2) =>
 Dict (HasNoNestedBigMaps ('TMap n1 (TAsRPC n2))))
-> Dict (HasNoNestedBigMaps (TAsRPC n2))
-> Dict (HasNoNestedBigMaps ('TMap n1 (TAsRPC n2)))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ Sing n2 -> Dict (HasNoNestedBigMaps (TAsRPC n2))
forall (t :: T). Sing t -> Dict (HasNoNestedBigMaps (TAsRPC t))
rpcHasNoNestedBigMapsEvi' Sing n2
sv
  STBigMap {} -> Dict (HasNoNestedBigMaps (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STInt {} -> Dict (HasNoNestedBigMaps (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STNat {} -> Dict (HasNoNestedBigMaps (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STString {} -> Dict (HasNoNestedBigMaps (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STBytes {} -> Dict (HasNoNestedBigMaps (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STMutez {} -> Dict (HasNoNestedBigMaps (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STBool {} -> Dict (HasNoNestedBigMaps (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STKeyHash {} -> Dict (HasNoNestedBigMaps (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STBls12381Fr {} -> Dict (HasNoNestedBigMaps (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STBls12381G1 {} -> Dict (HasNoNestedBigMaps (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STBls12381G2 {} -> Dict (HasNoNestedBigMaps (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STTimestamp {} -> Dict (HasNoNestedBigMaps (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STAddress {} -> Dict (HasNoNestedBigMaps (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STNever {} -> Dict (HasNoNestedBigMaps (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STSaplingState {} -> Dict (HasNoNestedBigMaps (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STSaplingTransaction {} -> Dict (HasNoNestedBigMaps (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STTxRollupL2Address {} -> Dict (HasNoNestedBigMaps (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict

-- | A proof that if @t@ does not contain any contract values, then neither does @TAsRPC t@.
rpcHasNoContractEvi
  :: forall (t :: T).
     (SingI t, HasNoContract t)
  => HasNoContract t :- HasNoContract (TAsRPC t)
rpcHasNoContractEvi :: forall (t :: T).
(SingI t, HasNoContract t) =>
HasNoContract t :- HasNoContract (TAsRPC t)
rpcHasNoContractEvi = Sing t -> HasNoContract t :- HasNoContract (TAsRPC t)
forall (t :: T).
HasNoContract t =>
Sing t -> HasNoContract t :- HasNoContract (TAsRPC t)
rpcHasNoContractEvi' Sing t
forall {k} (a :: k). SingI a => Sing a
sing

rpcHasNoContractEvi'
  :: HasNoContract t
  => Sing t
  -> HasNoContract t :- HasNoContract (TAsRPC t)
rpcHasNoContractEvi' :: forall (t :: T).
HasNoContract t =>
Sing t -> HasNoContract t :- HasNoContract (TAsRPC t)
rpcHasNoContractEvi' Sing t
sng = (HasNoContract t => Dict (HasNoContract (TAsRPC t)))
-> HasNoContract t :- HasNoContract (TAsRPC t)
forall (a :: Constraint) (b :: Constraint). (a => Dict b) -> a :- b
Sub ((HasNoContract t => Dict (HasNoContract (TAsRPC t)))
 -> HasNoContract t :- HasNoContract (TAsRPC t))
-> (HasNoContract t => Dict (HasNoContract (TAsRPC t)))
-> HasNoContract t :- HasNoContract (TAsRPC t)
forall a b. (a -> b) -> a -> b
$ case Sing t
sng of
  Sing t
SingT t
STKey -> Dict (HasNoContract (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STUnit {} -> Dict (HasNoContract (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STSignature {} -> Dict (HasNoContract (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STChainId {} -> Dict (HasNoContract (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STChest {} -> Dict (HasNoContract (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STChestKey {} -> Dict (HasNoContract (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STOption Sing n
s -> HasNoContract (TAsRPC n) => Dict (HasNoContract (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict (HasNoContract (TAsRPC n) => Dict (HasNoContract (TAsRPC t)))
-> (HasNoContract n :- HasNoContract (TAsRPC n))
-> Dict (HasNoContract (TAsRPC t))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ Sing n -> HasNoContract n :- HasNoContract (TAsRPC n)
forall (t :: T).
HasNoContract t =>
Sing t -> HasNoContract t :- HasNoContract (TAsRPC t)
rpcHasNoContractEvi' Sing n
s
  STList Sing n
s -> HasNoContract (TAsRPC n) => Dict (HasNoContract (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict (HasNoContract (TAsRPC n) => Dict (HasNoContract (TAsRPC t)))
-> (HasNoContract n :- HasNoContract (TAsRPC n))
-> Dict (HasNoContract (TAsRPC t))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ Sing n -> HasNoContract n :- HasNoContract (TAsRPC n)
forall (t :: T).
HasNoContract t =>
Sing t -> HasNoContract t :- HasNoContract (TAsRPC t)
rpcHasNoContractEvi' Sing n
s
  STSet Sing n
_ -> Dict (HasNoContract (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STOperation {} -> Dict (HasNoContract (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STTicket {} -> Dict (HasNoContract (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STPair Sing n1
sa Sing n2
sb -> case Sing n1 -> ContractPresence n1
forall (ty :: T). Sing ty -> ContractPresence ty
checkContractTypePresence Sing n1
sa of
    ContractPresence n1
ContractAbsent ->
      HasNoContract (TAsRPC n1) => Dict (HasNoContract (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict (HasNoContract (TAsRPC n1) => Dict (HasNoContract (TAsRPC t)))
-> (HasNoContract n1 :- HasNoContract (TAsRPC n1))
-> Dict (HasNoContract (TAsRPC t))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ Sing n1 -> HasNoContract n1 :- HasNoContract (TAsRPC n1)
forall (t :: T).
HasNoContract t =>
Sing t -> HasNoContract t :- HasNoContract (TAsRPC t)
rpcHasNoContractEvi' Sing n1
sa (HasNoContract (TAsRPC n2) => Dict (HasNoContract (TAsRPC t)))
-> (HasNoContract n2 :- HasNoContract (TAsRPC n2))
-> Dict (HasNoContract (TAsRPC t))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ Sing n2 -> HasNoContract n2 :- HasNoContract (TAsRPC n2)
forall (t :: T).
HasNoContract t =>
Sing t -> HasNoContract t :- HasNoContract (TAsRPC t)
rpcHasNoContractEvi' Sing n2
sb
  STOr Sing n1
sl Sing n2
sr -> case Sing n1 -> ContractPresence n1
forall (ty :: T). Sing ty -> ContractPresence ty
checkContractTypePresence Sing n1
sl of
    ContractPresence n1
ContractAbsent ->
      HasNoContract (TAsRPC n1) => Dict (HasNoContract (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict (HasNoContract (TAsRPC n1) => Dict (HasNoContract (TAsRPC t)))
-> (HasNoContract n1 :- HasNoContract (TAsRPC n1))
-> Dict (HasNoContract (TAsRPC t))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ Sing n1 -> HasNoContract n1 :- HasNoContract (TAsRPC n1)
forall (t :: T).
HasNoContract t =>
Sing t -> HasNoContract t :- HasNoContract (TAsRPC t)
rpcHasNoContractEvi' Sing n1
sl (HasNoContract (TAsRPC n2) => Dict (HasNoContract (TAsRPC t)))
-> (HasNoContract n2 :- HasNoContract (TAsRPC n2))
-> Dict (HasNoContract (TAsRPC t))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ Sing n2 -> HasNoContract n2 :- HasNoContract (TAsRPC n2)
forall (t :: T).
HasNoContract t =>
Sing t -> HasNoContract t :- HasNoContract (TAsRPC t)
rpcHasNoContractEvi' Sing n2
sr
  STLambda {} -> Dict (HasNoContract (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STMap Sing n1
_ Sing n2
sv -> HasNoContract (TAsRPC n2) => Dict (HasNoContract (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict (HasNoContract (TAsRPC n2) => Dict (HasNoContract (TAsRPC t)))
-> (HasNoContract n2 :- HasNoContract (TAsRPC n2))
-> Dict (HasNoContract (TAsRPC t))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ Sing n2 -> HasNoContract n2 :- HasNoContract (TAsRPC n2)
forall (t :: T).
HasNoContract t =>
Sing t -> HasNoContract t :- HasNoContract (TAsRPC t)
rpcHasNoContractEvi' Sing n2
sv
  STBigMap {} -> Dict (HasNoContract (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STInt {} -> Dict (HasNoContract (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STNat {} -> Dict (HasNoContract (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STString {} -> Dict (HasNoContract (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STBytes {} -> Dict (HasNoContract (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STMutez {} -> Dict (HasNoContract (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STBool {} -> Dict (HasNoContract (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STKeyHash {} -> Dict (HasNoContract (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STBls12381Fr {} -> Dict (HasNoContract (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STBls12381G1 {} -> Dict (HasNoContract (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STBls12381G2 {} -> Dict (HasNoContract (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STTimestamp {} -> Dict (HasNoContract (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STAddress {} -> Dict (HasNoContract (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STNever {} -> Dict (HasNoContract (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STSaplingState {} -> Dict (HasNoContract (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STSaplingTransaction {} -> Dict (HasNoContract (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
  STTxRollupL2Address {} -> Dict (HasNoContract (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict

-- | A proof that if @t@ is a valid storage type, then so is @TAsRPC t@.
rpcStorageScopeEvi :: forall (t :: T). StorageScope t :- StorageScope (TAsRPC t)
rpcStorageScopeEvi :: forall (t :: T). StorageScope t :- StorageScope (TAsRPC t)
rpcStorageScopeEvi =
  (StorageScope t => Dict (StorageScope (TAsRPC t)))
-> StorageScope t :- StorageScope (TAsRPC t)
forall (a :: Constraint) (b :: Constraint). (a => Dict b) -> a :- b
Sub ((StorageScope t => Dict (StorageScope (TAsRPC t)))
 -> StorageScope t :- StorageScope (TAsRPC t))
-> (StorageScope t => Dict (StorageScope (TAsRPC t)))
-> StorageScope t :- StorageScope (TAsRPC t)
forall a b. (a -> b) -> a -> b
$ SingI (TAsRPC t) => Dict (StorageScope (TAsRPC t))
forall (a :: Constraint). a => Dict a
Dict
    (SingI (TAsRPC t) => Dict (StorageScope (TAsRPC t)))
-> (SingI t :- SingI (TAsRPC t)) -> Dict (StorageScope (TAsRPC t))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ forall (t :: T). SingI t :- SingI (TAsRPC t)
rpcSingIEvi @t
    (HasNoOp (TAsRPC t) => Dict (StorageScope (TAsRPC t)))
-> (HasNoOp t :- HasNoOp (TAsRPC t))
-> Dict (StorageScope (TAsRPC t))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ forall (t :: T).
(SingI t, HasNoOp t) =>
HasNoOp t :- HasNoOp (TAsRPC t)
rpcHasNoOpEvi @t
    (HasNoNestedBigMaps (TAsRPC t) => Dict (StorageScope (TAsRPC t)))
-> Dict (HasNoNestedBigMaps (TAsRPC t))
-> Dict (StorageScope (TAsRPC t))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ forall (t :: T). SingI t => Dict (HasNoNestedBigMaps (TAsRPC t))
rpcHasNoNestedBigMapsEvi @t
    (HasNoContract (TAsRPC t) => Dict (StorageScope (TAsRPC t)))
-> (HasNoContract t :- HasNoContract (TAsRPC t))
-> Dict (StorageScope (TAsRPC t))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ forall (t :: T).
(SingI t, HasNoContract t) =>
HasNoContract t :- HasNoContract (TAsRPC t)
rpcHasNoContractEvi @t
    (WellTyped (TAsRPC t) => Dict (StorageScope (TAsRPC t)))
-> (WellTyped t :- WellTyped (TAsRPC t))
-> Dict (StorageScope (TAsRPC t))
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ forall (t :: T). WellTyped t => WellTyped t :- WellTyped (TAsRPC t)
rpcWellTypedEvi @t