deriveRPCWithStrategy appear to make slight wrong call to `customGeneric` internally generating broken `to`/`from` functions for `Generic` typeclass
Below is some code that demonstrates the issue.
type RegistryKey = MText
type RegistryValue = MText
type ProposalKey = Hash Blake2b $ Packed ProposeParams
data RegistryExtra = RegistryExtra
{ reRegistry :: BigMap RegistryKey RegistryValue
, reRegistryAffected :: BigMap RegistryKey ProposalKey
, reProposalReceivers :: Set Address
, reFrozenScaleValue :: Natural
, reFrozenExtraValue :: Natural
, reMaxProposalSize :: Natural
, reSlashScaleValue :: Natural
, reSlashDivisionValue :: Natural
, reMinXtzAmount :: Mutez
, reMaxXtzAmount :: Mutez
} deriving stock (Eq)
customGeneric "RegistryExtra" ligoLayout
deriveRPCWithStrategy "RegistryExtra" ligoLayout
Which throws the following errors
|| • Couldn't match type ‘Hash Blake2b (Packed ProposeParams)’
|| with ‘MText’
|| Expected type: BigMapId MText MText
|| Actual type: AsRPC (BigMap RegistryKey ProposalKey)
|| • In the first argument of ‘K1’, namely ‘v1_a1O2e’
|| In the first argument of ‘M1’, namely ‘(K1 v1_a1O2e)’
|| In the first argument of ‘(:*:)’, namely ‘(M1 (K1 v1_a1O2e))’
|| |
|| 90 | deriveRPCWithStrategy "RegistryExtra" ligoLayout
||
and
|| • Couldn't match type ‘Hash Blake2b (Packed ProposeParams)’
|| with ‘MText’
|| Expected type: AsRPC (BigMap RegistryKey RegistryValue)
|| Actual type: BigMapId MText (Hash Blake2b (Packed ProposeParams))
|| • In the first argument of ‘RegistryExtraRPC’, namely ‘v0_a1O2d’
|| In the expression:
|| (((((((((RegistryExtraRPC v0_a1O2d) v1_a1O2e) v2_a1O2f) v3_a1O2g)
|| v4_a1O2h)
|| v5_a1O2i)
|| v6_a1O2j)
|| v7_a1O2k)
|| v8_a1O2l)
|| v9_a1O2m
|| In an equation for ‘to’:
|| to
|| (M1 (M1 ((:*:) ((:*:) ((:*:) ((:*:) (M1 (K1 v4_a1O2h))
|| (M1 (K1 v3_a1O2g)))
|| ((:*:) (M1 (K1 v5_a1O2i)) (M1 (K1 v9_a1O2m))))
|| ((:*:) ((:*:) (M1 (K1 v8_a1O2l)) (M1 (K1 v2_a1O2f)))
|| ((:*:) (M1 (K1 v1_a1O2e)) (M1 (K1 v0_a1O2d)))))
|| ((:*:) (M1 (K1 v7_a1O2k)) (M1 (K1 v6_a1O2j))))))
|| = (((((((((RegistryExtraRPC v0_a1O2d) v1_a1O2e) v2_a1O2f) v3_a1O2g)
|| v4_a1O2h)
|| v5_a1O2i)
|| v6_a1O2j)
|| v7_a1O2k)
|| v8_a1O2l)
|| v9_a1O2m
|| |
|| 90 | deriveRPCWithStrategy "RegistryExtra" ligoLayout
Upon inspection it appeared that the generated from
/to
functions have couple of fields mixed up in the pattern match. The following is a fixed version of the generated from
method. See how the v1_a1r33
and v0_a1r32
had to be swapped to make it work. Similar error is present in to
method as well.
from
(RegistryExtraRPC v1_a1r33 v0_a1r32 v2_a1r34 v3_a1r35 v4_a1r36
v5_a1r37 v6_a1r38 v7_a1r39 v8_a1r3a v9_a1r3b)
= GHC.Generics.M1
....
After placing the generated code from deriveRPC
call in the source file, except for the generic instance, and calling customGeneric
after it, seem to fix the issue. So it appears that the customGenric
call made from deriveRPC
is somehow flawed.
Edited by Sandeep.C.R