@@ -16,7 +16,7 @@ import Cardano.AsCbor (encodeCbor)
1616import Cardano.Types (TransactionHash )
1717import Control.Error.Util (bool )
1818import Data.Array (concat , singleton ) as Array
19- import Data.Codec.Argonaut (JsonCodec , array , int , object , string ) as CA
19+ import Data.Codec.Argonaut (JsonCodec , JPropCodec , array , int , object , string ) as CA
2020import Data.Codec.Argonaut.Compat (maybe ) as CA
2121import Data.Codec.Argonaut.Record (record ) as CAR
2222import Data.Foldable (foldMap )
@@ -28,7 +28,7 @@ import Data.Traversable (for_, traverse_)
2828import Effect (Effect )
2929import Effect.AVar (empty , tryPut ) as AVar
3030import Effect.Class (class MonadEffect , liftEffect )
31- import HydraSdk.Internal.Lib.Codec (txHashCodec )
31+ import HydraSdk.Internal.Lib.Codec (txHashCodec , unionRecordCodecs )
3232import HydraSdk.Internal.Lib.Misc (cborBytesToHex )
3333import HydraSdk.Internal.Types.HostPort
3434 ( HostPort
@@ -46,9 +46,13 @@ import Node.ChildProcess (ChildProcess, defaultSpawnOptions, spawn, stderr, stdo
4646import Node.Encoding (Encoding (UTF8)) as Encoding
4747import Node.Path (FilePath )
4848import Node.Stream (onDataString )
49+ import Prim.Row (class Union ) as Row
50+ import Prim.RowList (RowList )
51+ import Prim.RowList (class RowToList ) as RowList
52+ import Record.Extra (class Keys ) as Record.Extra
4953
5054-- | Parameters to be passed to the hydra-node child process on startup.
51- type HydraNodeStartupParams =
55+ type HydraNodeStartupParams ( peerExtra :: Row Type ) =
5256 { nodeId :: String
5357 , hydraNodeAddress :: HostPort
5458 , hydraNodeAdvertisedAddress :: Maybe HostPort
@@ -60,12 +64,18 @@ type HydraNodeStartupParams =
6064 , pparams :: FilePath
6165 , hydraScripts :: Array TransactionHash
6266 , contestPeriodSec :: Int
63- , peers :: Array HydraHeadPeer
67+ , peers :: Array ( Record ( HydraHeadPeer peerExtra ))
6468 }
6569
6670-- | Bidirectional JSON codec for `HydraNodeStartupParams`.
67- hydraNodeStartupParamsCodec :: CA.JsonCodec HydraNodeStartupParams
68- hydraNodeStartupParamsCodec =
71+ hydraNodeStartupParamsCodec
72+ :: forall (peerExtra :: Row Type ) (rl :: RowList Type )
73+ . Row.Union peerExtra (HydraHeadPeer ()) (HydraHeadPeer peerExtra )
74+ => RowList.RowToList peerExtra rl
75+ => Record.Extra.Keys rl
76+ => CA.JPropCodec (Record peerExtra )
77+ -> CA.JsonCodec (HydraNodeStartupParams peerExtra )
78+ hydraNodeStartupParamsCodec peerExtraCodec =
6979 CA .object " HydraNodeStartupParams" $ CAR .record
7080 { nodeId: CA .string
7181 , hydraNodeAddress: hostPortStringCodec
@@ -78,22 +88,29 @@ hydraNodeStartupParamsCodec =
7888 , pparams: CA .string
7989 , hydraScripts: CA .array txHashCodec
8090 , contestPeriodSec: CA .int
81- , peers: CA .array hydraHeadPeerCodec
91+ , peers: CA .array $ hydraHeadPeerCodec peerExtraCodec
8292 }
8393
8494-- | Configuration parameters for a single Hydra Head peer. When setting up a
8595-- | Hydra Head, each node must specify the network addresses and public key
8696-- | information of its respective peers.
87- type HydraHeadPeer =
88- { hydraNodeAddress :: HostPort
97+ type HydraHeadPeer ( extra :: Row Type ) =
98+ ( hydraNodeAddress :: HostPort
8999 , hydraVerificationKey :: FilePath
90100 , cardanoVerificationKey :: FilePath
91- }
101+ | extra
102+ )
92103
93104-- | Bi-directional JSON codec for `HydraHeadPeer`.
94- hydraHeadPeerCodec :: CA.JsonCodec HydraHeadPeer
95- hydraHeadPeerCodec =
96- CA .object " HydraHeadPeer" $ CAR .record
105+ hydraHeadPeerCodec
106+ :: forall (extra :: Row Type ) (rl :: RowList Type )
107+ . Row.Union extra (HydraHeadPeer ()) (HydraHeadPeer extra )
108+ => RowList.RowToList extra rl
109+ => Record.Extra.Keys rl
110+ => CA.JPropCodec (Record extra )
111+ -> CA.JsonCodec (Record (HydraHeadPeer extra ))
112+ hydraHeadPeerCodec extraCodec =
113+ CA .object " HydraHeadPeer" $ unionRecordCodecs extraCodec $ CAR .record
97114 { hydraNodeAddress: hostPortStringCodec
98115 , hydraVerificationKey: CA .string
99116 , cardanoVerificationKey: CA .string
@@ -126,9 +143,9 @@ noopHydraNodeHandlers =
126143-- |
127144-- | NOTE: The hydra-node executable must be available in the PATH.
128145spawnHydraNode
129- :: forall m
146+ :: forall ( m :: Type -> Type ) ( peerExtra :: Row Type )
130147 . MonadEffect m
131- => HydraNodeStartupParams
148+ => HydraNodeStartupParams peerExtra
132149 -> HydraNodeHandlers
133150 -> m ChildProcess
134151spawnHydraNode params handlers = liftEffect do
0 commit comments