File tree 1 file changed +19
-0
lines changed
cardano-api/src/Cardano/Api
1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change 2
2
{-# LANGUAGE FlexibleContexts #-}
3
3
{-# LANGUAGE FlexibleInstances #-}
4
4
{-# LANGUAGE GADTs #-}
5
+ {-# LANGUAGE LambdaCase #-}
5
6
{-# LANGUAGE NamedFieldPuns #-}
6
7
{-# LANGUAGE PatternSynonyms #-}
7
8
{-# LANGUAGE RankNTypes #-}
@@ -358,6 +359,24 @@ instance Ord ChainPoint where
358
359
compare _ ChainPointAtGenesis = GT
359
360
compare (ChainPoint sn _) (ChainPoint sn' _) = compare sn sn'
360
361
362
+ instance ToJSON ChainPoint where
363
+ toJSON = \ case
364
+ ChainPointAtGenesis -> object [" tag" .= String " ChainPointAtGenesis" ]
365
+ ChainPoint slot blockHash ->
366
+ object
367
+ [ " tag" .= String " ChainPoint"
368
+ , " slot" .= toJSON slot
369
+ , " blockHash" .= toJSON blockHash
370
+ ]
371
+
372
+ instance FromJSON ChainPoint where
373
+ parseJSON = withObject " ChainPoint" $ \ o -> do
374
+ tag <- o .: " tag"
375
+ case tag :: Text of
376
+ " ChainPointAtGenesis" -> pure ChainPointAtGenesis
377
+ " ChainPoint" -> ChainPoint <$> o .: " slot" <*> o .: " blockHash"
378
+ _ -> fail " Expected tag to be ChainPointAtGenesis | ChainPoint"
379
+
361
380
toConsensusPointInMode :: ConsensusMode mode
362
381
-> ChainPoint
363
382
-> Consensus. Point (ConsensusBlockForMode mode )
You can’t perform that action at this time.
0 commit comments