Skip to content

Commit

Permalink
Encode pool metadata hash as hex in PoolMetaData ToJSON
Browse files Browse the repository at this point in the history
  • Loading branch information
intricate committed Jun 30, 2020
1 parent 04e9719 commit f777342
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ import qualified Data.Aeson as Aeson
import Data.Aeson.Types (explicitParseField)
import Data.ByteString (ByteString)
import qualified Data.ByteString as BS
import qualified Data.ByteString.Base16 as Base16
import qualified Data.ByteString.Char8 as Char8
import qualified Data.ByteString.Lazy as BSL
import Data.Foldable (fold)
Expand All @@ -109,6 +110,7 @@ import Data.Sequence.Strict (StrictSeq)
import qualified Data.Sequence.Strict as StrictSeq
import Data.Set (Set)
import qualified Data.Set as Set
import qualified Data.Text.Encoding as Text
import Data.Typeable (Typeable)
import Data.Word (Word8)
import GHC.Generics (Generic)
Expand Down Expand Up @@ -188,15 +190,15 @@ instance ToJSON PoolMetaData where
toJSON pmd =
Aeson.object
[ "url" .= _poolMDUrl pmd,
"hash" .= Char8.unpack (_poolMDHash pmd)
"hash" .= (Text.decodeLatin1 . Base16.encode) (_poolMDHash pmd)
]

instance FromJSON PoolMetaData where
parseJSON =
Aeson.withObject "PoolMetaData" $ \obj ->
PoolMetaData
<$> obj .: "url"
<*> explicitParseField (fmap Char8.pack . parseJSON) obj "hash"
<*> explicitParseField (fmap (fst . Base16.decode . Char8.pack) . parseJSON) obj "hash"

instance NoUnexpectedThunks PoolMetaData

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"pledge": 1,
"vrf": "b69330fe",
"metadata": {
"hash": "100ab{}",
"hash": "31303061627b7d",
"url": "best.pool.com"
},
"relays": [
Expand Down

0 comments on commit f777342

Please sign in to comment.