From 064685a948c3cd881fdcb18c5cd21f61d4536451 Mon Sep 17 00:00:00 2001 From: Sebastian Nagel Date: Mon, 13 Sep 2021 16:28:25 +0200 Subject: [PATCH] Do not include "alias" in Party JSON if Nothing --- hydra-node/src/Hydra/Party.hs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/hydra-node/src/Hydra/Party.hs b/hydra-node/src/Hydra/Party.hs index 8ee6e832167..9017cc4e283 100644 --- a/hydra-node/src/Hydra/Party.hs +++ b/hydra-node/src/Hydra/Party.hs @@ -20,7 +20,7 @@ import Cardano.Crypto.DSIGN ( ) import Cardano.Crypto.Seed (mkSeedFromBytes) import Cardano.Crypto.Util (SignableRepresentation) -import Data.Aeson (ToJSONKey, Value (String), withText) +import Data.Aeson (ToJSONKey, Value (String), object, withText, (.=)) import Data.Aeson.Types (FromJSONKey) import qualified Data.ByteString.Base16 as Base16 import Test.QuickCheck (vectorOf) @@ -31,7 +31,7 @@ data Party = Party { alias :: Maybe Text , vkey :: VerificationKey } - deriving (Eq, Generic, FromJSON, ToJSON) + deriving (Eq, Generic, FromJSON) instance Show Party where show Party{alias, vkey} = @@ -70,6 +70,14 @@ instance ToCBOR Party where instance FromJSONKey Party instance ToJSONKey Party +instance ToJSON Party where + toJSON Party{alias, vkey} = + object $ ["vkey" .= vkey] <> maybeAlias + where + maybeAlias = case alias of + Nothing -> [] + Just a -> ["alias" .= a] + -- NOTE(SN): Convenience type class to be able to quickly create parties from -- integer literals using 'fromInteger', e.g. `let alice = 10`. This will be -- removed at latest when we don't have MockDSIGN VerificationKeys anymore