4
4
{-# LANGUAGE FlexibleContexts #-}
5
5
{-# LANGUAGE FlexibleInstances #-}
6
6
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
7
+ {-# LANGUAGE LambdaCase #-}
7
8
{-# LANGUAGE OverloadedStrings #-}
8
9
{-# LANGUAGE StandaloneDeriving #-}
9
10
{-# LANGUAGE TypeFamilies #-}
13
14
14
15
module Cardano.CLI.Shelley.Orphans () where
15
16
16
- import Cardano.Prelude
17
-
18
- import Control.SetAlgebra as SetAlgebra
19
- import Data.Aeson
20
- import qualified Data.ByteString.Base16 as Base16
21
- import qualified Data.ByteString.Short as SBS
22
- import qualified Data.Text.Encoding as Text
23
-
24
17
import Cardano.Api.Orphans ()
25
-
26
- import Ouroboros.Consensus.Byron.Ledger.Block (ByronHash (.. ))
27
- import Ouroboros.Consensus.HardFork.Combinator (OneEraHash (.. ))
28
- import Ouroboros.Consensus.Shelley.Eras (StandardCrypto )
29
- import Ouroboros.Consensus.Shelley.Ledger.Block (ShelleyHash (.. ))
30
- import Ouroboros.Network.Block (BlockNo (.. ), HeaderHash , Tip (.. ))
31
-
32
18
import Cardano.Ledger.AuxiliaryData (AuxiliaryDataHash (.. ))
19
+ import qualified Cardano.Ledger.Credential as Ledger
33
20
import qualified Cardano.Ledger.Crypto as CC (Crypto )
21
+ import qualified Cardano.Ledger.Mary.Value as Ledger.Mary
34
22
import Cardano.Ledger.PoolDistr (PoolDistr (.. ))
35
- import Cardano.Protocol.TPraos.BHeader (HashHeader (.. ))
36
-
37
- import qualified Cardano.Ledger.Credential as Ledger
38
- import qualified Cardano.Protocol.TPraos.API as Ledger
39
23
import qualified Cardano.Ledger.Shelley.EpochBoundary as Ledger
24
+ import qualified Cardano.Ledger.Shelley.PoolRank as Ledger
40
25
import Cardano.Ledger.TxIn (TxId (.. ))
26
+ import Cardano.Prelude (Bool (True ), Category ((.) ))
27
+ import qualified Cardano.Protocol.TPraos.API as Ledger
28
+ import Cardano.Protocol.TPraos.BHeader (HashHeader (.. ))
41
29
import qualified Cardano.Protocol.TPraos.Rules.Prtcl as Ledger
42
30
import qualified Cardano.Protocol.TPraos.Rules.Tickn as Ledger
43
-
44
- import qualified Cardano.Ledger.Mary.Value as Ledger.Mary
45
-
31
+ import qualified Cardano.Slotting.Slot as Cardano
32
+ import qualified Control.SetAlgebra as SetAlgebra (BiMap , forwards )
33
+ import Data.Aeson (FromJSON (.. ), KeyValue ((.=) ), ToJSON (.. ), ToJSONKey )
34
+ import qualified Data.Aeson as Aeson
35
+ import qualified Data.ByteString.Base16 as Base16
36
+ import qualified Data.ByteString.Short as SBS
37
+ import qualified Data.Text.Encoding as Text
46
38
import qualified Data.VMap as VMap
47
- import qualified Cardano.Ledger.Shelley.PoolRank as Ledger
39
+ import Ouroboros.Consensus.Byron.Ledger.Block (ByronHash (.. ))
40
+ import Ouroboros.Consensus.HardFork.Combinator (OneEraHash (.. ))
41
+ import Ouroboros.Consensus.Protocol.Praos (PraosState )
42
+ import qualified Ouroboros.Consensus.Protocol.Praos as Consensus
43
+ import Ouroboros.Consensus.Protocol.TPraos (TPraosState )
44
+ import qualified Ouroboros.Consensus.Protocol.TPraos as Consensus
45
+ import Ouroboros.Consensus.Shelley.Eras (StandardCrypto )
46
+ import Ouroboros.Consensus.Shelley.Ledger.Block (ShelleyHash (.. ))
47
+ import Ouroboros.Network.Block (BlockNo (.. ), HeaderHash , Tip (.. ))
48
48
49
49
instance ToJSON (OneEraHash xs ) where
50
50
toJSON = toJSON
@@ -58,9 +58,9 @@ deriving newtype instance ToJSON ByronHash
58
58
-- This instance is temporarily duplicated in cardano-config
59
59
60
60
instance ToJSON (HeaderHash blk ) => ToJSON (Tip blk ) where
61
- toJSON TipGenesis = object [ " genesis" .= True ]
61
+ toJSON TipGenesis = Aeson. object [ " genesis" .= True ]
62
62
toJSON (Tip slotNo headerHash blockNo) =
63
- object
63
+ Aeson. object
64
64
[ " slotNo" .= slotNo
65
65
, " headerHash" .= headerHash
66
66
, " blockNo" .= blockNo
@@ -94,3 +94,26 @@ deriving newtype instance ToJSON (Ledger.Mary.PolicyID StandardCrypto)
94
94
95
95
instance (ToJSONKey k , ToJSON v ) => ToJSON (SetAlgebra. BiMap v k v ) where
96
96
toJSON = toJSON . SetAlgebra. forwards -- to normal Map
97
+
98
+ instance ToJSON (TPraosState StandardCrypto ) where
99
+ toJSON s = Aeson. object
100
+ [ " lastSlot" .= Consensus. tpraosStateLastSlot s
101
+ , " chainDepState" .= Consensus. tpraosStateChainDepState s
102
+ ]
103
+
104
+ instance ToJSON (PraosState StandardCrypto ) where
105
+ toJSON s = Aeson. object
106
+ [ " lastSlot" .= Consensus. praosStateLastSlot s
107
+ , " oCertCounters" .= Consensus. praosStateOCertCounters s
108
+ , " evolvingNonce" .= Consensus. praosStateEvolvingNonce s
109
+ , " candidateNonce" .= Consensus. praosStateCandidateNonce s
110
+ , " epochNonce" .= Consensus. praosStateEpochNonce s
111
+ , " labNonce" .= Consensus. praosStateLabNonce s
112
+ , " lastEpochBlockNonce" .= Consensus. praosStateLastEpochBlockNonce s
113
+ ]
114
+
115
+
116
+ instance ToJSON (Cardano. WithOrigin Cardano. SlotNo ) where
117
+ toJSON = \ case
118
+ Cardano. Origin -> Aeson. String " origin"
119
+ Cardano. At (Cardano. SlotNo n) -> toJSON n
0 commit comments