Skip to content
This repository has been archived by the owner on Aug 18, 2020. It is now read-only.

Commit

Permalink
[CO-410] Modify RequiresNetworkMagic's FromJSON instance to suppo…
Browse files Browse the repository at this point in the history
…rt legacy encoding
  • Loading branch information
Jimbo4350 committed Oct 12, 2018
1 parent 3fadbb8 commit a60c50f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions crypto/Pos/Crypto/Configuration.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# LANGUAGE OverloadedStrings #-}

module Pos.Crypto.Configuration
( ProtocolMagic (..)
, ProtocolMagicId (..)
Expand Down Expand Up @@ -45,7 +47,9 @@ instance A.ToJSON RequiresNetworkMagic where
instance A.FromJSON RequiresNetworkMagic where
parseJSON = A.withText "requiresNetworkMagic" $ toAesonError . \case
"RequiresNoMagic" -> Right RequiresNoMagic
"RequiresMagic" -> Right RequiresMagic
"RequiresMagic" -> Right RequiresMagic
"NMMustBeNothing" -> Right RequiresNoMagic
"NMMustBeJust" -> Right RequiresMagic
other -> Left ("invalid value " <> show other <>
", acceptable values are RequiresNoMagic | RequiresMagic")

Expand Down Expand Up @@ -105,7 +109,7 @@ instance A.FromJSON ProtocolMagic where
parseJSON (A.Object o) = ProtocolMagic
<$> (ProtocolMagicId <$> o .: "pm")
<*> o .: "requiresNetworkMagic"
parseJSON invalid = typeMismatch "Coord" invalid
parseJSON invalid = typeMismatch "ProtocolMagic" invalid

-- Canonical JSON instances
instance Monad m => ToJSON m ProtocolMagic where
Expand Down

0 comments on commit a60c50f

Please sign in to comment.