Skip to content

Commit

Permalink
Do not include "alias" in Party JSON if Nothing
Browse files Browse the repository at this point in the history
  • Loading branch information
ch1bo authored and abailly-iohk committed Sep 14, 2021
1 parent 891ea53 commit 064685a
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions hydra-node/src/Hydra/Party.hs
Expand Up @@ -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)
Expand All @@ -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} =
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 064685a

Please sign in to comment.