Skip to content

Commit b7c38b3

Browse files
committed
ouroboros-network:orphan-instances - refactoring
* added export list * use foldMap to fold Maybe
1 parent 25b59a8 commit b7c38b3

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

ouroboros-network/orphan-instances/Ouroboros/Network/OrphanInstances.hs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,15 @@
99

1010
{-# OPTIONS_GHC -Wno-orphans #-}
1111

12-
module Ouroboros.Network.OrphanInstances where
12+
-- | Orphan JSON instances for Ouroboros.Network types.
13+
--
14+
module Ouroboros.Network.OrphanInstances
15+
( networkTopologyFromJSON
16+
, localRootPeersGroupsFromJSON
17+
, networkTopologyToJSON
18+
, localRootPeersGroupsToJSON
19+
, peerSelectionTargetsToObject
20+
) where
1321

1422
import Cardano.Network.NodeToClient (LocalAddress (..), ProtocolLimitFailure)
1523
import Control.Applicative (Alternative ((<|>)))
@@ -149,16 +157,12 @@ localRootPeersGroupToJSON :: (extraFlags -> Maybe (Key, Value))
149157
-> Value
150158
localRootPeersGroupToJSON extraFlagsToJSON lrpg =
151159
Object $
152-
("accessPoints" .?= rootAccessPoints (localRoots lrpg))
153-
<> ("advertise" .?= rootAdvertise (localRoots lrpg))
154-
<> ("hotValency" .?= hotValency lrpg)
155-
<> ("warmValency" .?= warmValency lrpg)
156-
<> (case mv of
157-
Nothing -> mempty
158-
Just (k, v) -> k .?= v)
159-
<> ("diffusionMode" .?= rootDiffusionMode lrpg)
160-
where
161-
mv = extraFlagsToJSON (extraFlags lrpg)
160+
("accessPoints" .?= rootAccessPoints (localRoots lrpg))
161+
<> ("advertise" .?= rootAdvertise (localRoots lrpg))
162+
<> ("hotValency" .?= hotValency lrpg)
163+
<> ("warmValency" .?= warmValency lrpg)
164+
<> foldMap (uncurry (.?=)) (extraFlagsToJSON (extraFlags lrpg))
165+
<> ("diffusionMode" .?= rootDiffusionMode lrpg)
162166

163167
localRootPeersGroupsFromJSON
164168
:: (Object -> Parser extraFlags)
@@ -219,11 +223,7 @@ networkTopologyToJSON
219223
<> ("publicRoots" .?= publicRootPeers)
220224
<> ("useLedgerAfterSlot" .?= useLedgerPeers)
221225
<> ("peerSnapshotFile" .?= peerSnapshotPath)
222-
<> (case mv of
223-
Nothing -> mempty
224-
Just (k,v) -> k .?= v)
225-
where
226-
mv = extraConfigToJSON extraConfig
226+
<> foldMap (uncurry (.?=)) (extraConfigToJSON extraConfig)
227227

228228
instance FromJSON PeerSharing where
229229
parseJSON = withBool "PeerSharing" $ \b ->

0 commit comments

Comments
 (0)