[#346] Added `AsRPC` type family
Description
This is a follow-up of !707 (closed).
This MR expose a new type family:
type family AsRPC (a :: k) = (b :: k)
This type family maps a storage type S
to the type that will be returned from the Tezos RPC when we query that storage, AsRPC S
.
type instance AsRPC (BigMap k v) = BigMapId k (AsRPC v)
type instance AsRPC [a] = [AsRPC a]
type instance AsRPC Integer = Integer
type instance AsRPC Natural = Natural
type instance AsRPC MText = MText
It also exports 4 template-haskell functions for deriving AsRPC
instances for user-defined types:
deriveRPC :: String -> Q [Dec]
deriveRPCWithStrategy :: String -> GenericStrategy -> Q [Dec]
deriveManyRPC :: String -> [String] -> Q [Dec]
deriveManyRPCWithStrategy :: String -> [String] -> GenericStrategy -> Q [Dec]
There are plenty of examples in the Test.AsRPC
module, but here's one:
data ExampleStorage a b = ExampleStorage
{ _esField1 :: Integer
, _esField2 :: [BigMap Integer MText]
, _esField3 :: a
}
deriving stock Generic
deriving anyclass IsoValue
deriveRPC "ExampleStorage"
======>
data ExampleStorageRPC a (b :: k) = ExampleStorageRPC
{ _esField1RPC :: AsRPC Integer
, _esField2RPC :: AsRPC [BigMap Integer MText]
, _esField3RPC :: AsRPC a
}
type instance AsRPC (ExampleStorage a (b :: k)) = ExampleStorageRPC a (b :: k)
deriving anyclass instance IsoValue (AsRPC a) => IsoValue (ExampleStorageRPC a (b :: k))
instance Generic (ExampleStorageRPC a (b :: k)) where ...
Related issue(s)
Resolves part of #346 (closed)
✅ Checklist for your Merge Request
Related changes (conditional)
-
Tests (see short guidelines)
-
If I added new functionality, I added tests covering it. -
If I fixed a bug, I added a regression test to prevent the bug from silently reappearing again.
-
-
Documentation
Stylistic guide (mandatory)
-
My commits comply with the following policy. -
My code complies with the style guide.
Edited by Diogo Castro