Skip to content

Commit

Permalink
remove extra type param
Browse files Browse the repository at this point in the history
  • Loading branch information
martyall committed Sep 30, 2023
1 parent b514aca commit c2662f3
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 37 deletions.
4 changes: 2 additions & 2 deletions src/Network/Ethereum/Web3/Contract.purs
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,10 @@ deployContract txOptions deployByteCode args =
eth_sendTransaction txdata

mkDataField
:: forall selector a rep fields l
:: forall selector a rep fields
. IsSymbol selector
=> Generic a rep
=> GRecordFieldsIso rep fields l
=> GRecordFieldsIso rep fields
=> GenericABIEncode rep
=> Proxy (Tagged selector a)
-> Record fields
Expand Down
16 changes: 8 additions & 8 deletions src/Network/Ethereum/Web3/Solidity/Event.purs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ parseChange (Change change) anonymous = do
pure $ Event a b

combineChange
:: forall afields al a arep bfields bl b brep c cfields
:: forall afields a arep bfields b brep c cfields
. Generic a arep
=> Generic b brep
=> GRecordFieldsIso arep afields al
=> GRecordFieldsIso brep bfields bl
=> GRecordFieldsIso arep afields
=> GRecordFieldsIso brep bfields
=> Row.Union afields bfields cfields
=> Row.Nub cfields cfields
=> Newtype c (Record cfields)
Expand All @@ -93,12 +93,12 @@ class IndexedEvent a b c | c -> a b where
isAnonymous :: Proxy c -> Boolean

decodeEventDef
:: forall afields al a arep bfields bl b brep c cfields
:: forall afields a arep bfields b brep c cfields
. Generic a arep
=> GRecordFieldsIso arep afields al
=> GRecordFieldsIso arep afields
=> GenericABIDecode arep
=> ArrayParser arep
=> GRecordFieldsIso brep bfields bl
=> GRecordFieldsIso brep bfields
=> Generic b brep
=> GenericABIDecode brep
=> Row.Union afields bfields cfields
Expand All @@ -122,10 +122,10 @@ class

instance
( ArrayParser arep
, GRecordFieldsIso arep afields al
, GRecordFieldsIso arep afields
, Generic a arep
, GenericABIDecode arep
, GRecordFieldsIso brep bfields bl
, GRecordFieldsIso brep bfields
, Generic b brep
, GenericABIDecode brep
, Row.Union afields bfields cfields
Expand Down
51 changes: 24 additions & 27 deletions src/Network/Ethereum/Web3/Solidity/Internal.purs
Original file line number Diff line number Diff line change
Expand Up @@ -14,51 +14,48 @@ import Data.Symbol (class IsSymbol)
import Prim.Row as Row
import Record as Record
import Type.Proxy (Proxy(..))
import Type.RowList (class RowListAppend, Cons, Nil)
import Unsafe.Coerce (unsafeCoerce)

class GRecordFieldsIso :: forall k1. Type -> Row Type -> k1 -> Constraint
class GRecordFieldsIso rep fields k | rep -> k, k -> rep fields where
gToRecordFields :: Proxy k -> rep -> Record fields
gFromRecordFields :: Proxy k -> Record fields -> rep
class GRecordFieldsIso rep fields | rep -> fields where
gToRecordFields :: rep -> Record fields
gFromRecordFields :: Record fields -> rep

instance GRecordFieldsIso NoArguments () Nil where
gToRecordFields _ _ = {}
gFromRecordFields _ _ = NoArguments
instance GRecordFieldsIso NoArguments () where
gToRecordFields _ = {}
gFromRecordFields _ = NoArguments

else instance GRecordFieldsIso a r rl => GRecordFieldsIso (Constructor name a) r (Cons name rl Nil) where
gToRecordFields _ (Constructor a) = gToRecordFields (Proxy @rl) a
gFromRecordFields _ r = Constructor (gFromRecordFields (Proxy @rl) r)
else instance GRecordFieldsIso a r => GRecordFieldsIso (Constructor name a) r where
gToRecordFields (Constructor a) = gToRecordFields a
gFromRecordFields r = Constructor (gFromRecordFields r)

else instance
( IsSymbol s
, Row.Cons s a () r
, Row.Lacks s ()
) =>
GRecordFieldsIso (Argument (Tagged s a)) r (Cons s a Nil) where
gToRecordFields _ (Argument a) = Record.insert (Proxy @s) (untagged a) {}
gFromRecordFields _ r = Argument (tagged $ Record.get (Proxy @s) r)
GRecordFieldsIso (Argument (Tagged s a)) r where
gToRecordFields (Argument a) = Record.insert (Proxy @s) (untagged a) {}
gFromRecordFields r = Argument (tagged $ Record.get (Proxy @s) r)

else instance
( GRecordFieldsIso as ra rla
, GRecordFieldsIso bs rb rlb
, RowListAppend rla rlb rl
( GRecordFieldsIso as ra
, GRecordFieldsIso bs rb
, Row.Union ra rb r
, Row.Nub r r
) =>
GRecordFieldsIso (Product as bs) r rl where
gToRecordFields _ (Product as bs) =
Record.merge (gToRecordFields (Proxy @rla) as) (gToRecordFields (Proxy @rlb) bs)
GRecordFieldsIso (Product as bs) r where
gToRecordFields (Product as bs) =
Record.merge (gToRecordFields as) (gToRecordFields bs)

gFromRecordFields _ r =
gFromRecordFields r =
let
as = gFromRecordFields (Proxy @rla) (unsafeCoerce r)
bs = gFromRecordFields (Proxy @rlb) (unsafeCoerce r)
as = gFromRecordFields (unsafeCoerce r)
bs = gFromRecordFields (unsafeCoerce r)
in
Product as bs

toRecord :: forall a rep fields l. Generic a rep => GRecordFieldsIso rep fields l => a -> Record fields
toRecord a = gToRecordFields (Proxy :: Proxy l) (from a)
toRecord :: forall a rep fields. Generic a rep => GRecordFieldsIso rep fields => a -> Record fields
toRecord a = gToRecordFields $ from a

fromRecord :: forall a rep fields l. Generic a rep => GRecordFieldsIso rep fields l => Record fields -> a
fromRecord a = to $ gFromRecordFields (Proxy :: Proxy l) a
fromRecord :: forall a rep fields. Generic a rep => GRecordFieldsIso rep fields => Record fields -> a
fromRecord a = to $ gFromRecordFields a

0 comments on commit c2662f3

Please sign in to comment.