From fa45d845c490edb580eb8c8362a57e4bb80ca102 Mon Sep 17 00:00:00 2001 From: Duncan Coutts Date: Tue, 1 Dec 2020 02:20:23 +0000 Subject: [PATCH] Add ToJSON instances needed for the Allegra & Mary ledger states --- .../src/Cardano/CLI/Shelley/Orphans.hs | 61 ++++++++++++++++++- 1 file changed, 58 insertions(+), 3 deletions(-) diff --git a/cardano-cli/src/Cardano/CLI/Shelley/Orphans.hs b/cardano-cli/src/Cardano/CLI/Shelley/Orphans.hs index ef2eaea289..47ff7764e5 100644 --- a/cardano-cli/src/Cardano/CLI/Shelley/Orphans.hs +++ b/cardano-cli/src/Cardano/CLI/Shelley/Orphans.hs @@ -28,7 +28,9 @@ import Cardano.Crypto.Hash.Class as Crypto import Ouroboros.Consensus.Byron.Ledger.Block (ByronHash (..)) import Ouroboros.Consensus.HardFork.Combinator (OneEraHash (..)) import Ouroboros.Consensus.Shelley.Ledger.Block (ShelleyHash (..)) -import Ouroboros.Consensus.Shelley.Eras (ShelleyBasedEra, StandardCrypto, StandardShelley) +import Ouroboros.Consensus.Shelley.Eras + (ShelleyBasedEra, StandardCrypto, + StandardShelley, StandardAllegra, StandardMary) import Ouroboros.Network.Block (BlockNo (..), HeaderHash, Tip (..)) import qualified Cardano.Ledger.Core as Core @@ -50,6 +52,8 @@ import qualified Shelley.Spec.Ledger.STS.Tickn as Ledger import Shelley.Spec.Ledger.TxBody (TxId (..), TxIn (..), TxOut (..)) import Shelley.Spec.Ledger.UTxO (UTxO (..)) +import qualified Cardano.Ledger.Mary.Value as Ledger.Mary + instance ShelleyBasedEra era => ToJSONKey (TxIn era) where toJSONKey = ToJSONKeyText txInToText (Aeson.text . txInToText) @@ -108,22 +112,33 @@ deriving newtype instance ToJSON (HashHeader era) deriving newtype instance ToJSON (MetaDataHash era) deriving newtype instance ToJSON Ledger.LogWeight deriving newtype instance ToJSON Ledger.Likelihood -deriving newtype instance ToJSON (Ledger.Stake StandardShelley) deriving newtype instance ToJSON (Ledger.PoolDistr StandardCrypto) deriving newtype instance ToJSON DeltaCoin +deriving newtype instance ToJSON (Ledger.Stake StandardShelley) +deriving newtype instance ToJSON (Ledger.Stake StandardAllegra) +deriving newtype instance ToJSON (Ledger.Stake StandardMary) + deriving anyclass instance ToJSON (Ledger.GenDelegs StandardCrypto) deriving anyclass instance ToJSON (Ledger.IndividualPoolStake StandardCrypto) + deriving anyclass instance ToJSON (Ledger.ProposedPPUpdates StandardShelley) deriving anyclass instance ToJSON (Ledger.PPUPState StandardShelley) deriving anyclass instance ToJSON (Ledger.BlocksMade StandardShelley) +deriving anyclass instance ToJSON (Ledger.ProposedPPUpdates StandardAllegra) +deriving anyclass instance ToJSON (Ledger.PPUPState StandardAllegra) +deriving anyclass instance ToJSON (Ledger.BlocksMade StandardAllegra) + +deriving anyclass instance ToJSON (Ledger.ProposedPPUpdates StandardMary) +deriving anyclass instance ToJSON (Ledger.PPUPState StandardMary) +deriving anyclass instance ToJSON (Ledger.BlocksMade StandardMary) + deriving instance ToJSON Ledger.Ptr deriving instance ToJSON Ledger.AccountState deriving instance ToJSON (Ledger.DPState StandardShelley) deriving instance ToJSON (Ledger.DState StandardShelley) -deriving instance ToJSON (Ledger.FutureGenDeleg StandardCrypto) deriving instance ToJSON (Ledger.InstantaneousRewards StandardShelley) deriving instance ToJSON (Ledger.SnapShot StandardShelley) deriving instance ToJSON (Ledger.SnapShots StandardShelley) @@ -136,6 +151,38 @@ deriving instance ToJSON (Ledger.PParams' StrictMaybe StandardShelley) deriving instance ToJSON (Ledger.PState StandardShelley) deriving instance ToJSON (Ledger.StakeReference StandardShelley) deriving instance ToJSON (Ledger.UTxOState StandardShelley) + +deriving instance ToJSON (Ledger.DPState StandardAllegra) +deriving instance ToJSON (Ledger.DState StandardAllegra) +deriving instance ToJSON (Ledger.InstantaneousRewards StandardAllegra) +deriving instance ToJSON (Ledger.SnapShot StandardAllegra) +deriving instance ToJSON (Ledger.SnapShots StandardAllegra) +deriving instance ToJSON (Ledger.NonMyopic StandardAllegra) +deriving instance ToJSON (Ledger.LedgerState StandardAllegra) +deriving instance ToJSON (Ledger.EpochState StandardAllegra) +deriving instance ToJSON (Ledger.RewardUpdate StandardAllegra) +deriving instance ToJSON (Ledger.NewEpochState StandardAllegra) +deriving instance ToJSON (Ledger.PParams' StrictMaybe StandardAllegra) +deriving instance ToJSON (Ledger.PState StandardAllegra) +deriving instance ToJSON (Ledger.StakeReference StandardAllegra) +deriving instance ToJSON (Ledger.UTxOState StandardAllegra) + +deriving instance ToJSON (Ledger.DPState StandardMary) +deriving instance ToJSON (Ledger.DState StandardMary) +deriving instance ToJSON (Ledger.InstantaneousRewards StandardMary) +deriving instance ToJSON (Ledger.SnapShot StandardMary) +deriving instance ToJSON (Ledger.SnapShots StandardMary) +deriving instance ToJSON (Ledger.NonMyopic StandardMary) +deriving instance ToJSON (Ledger.LedgerState StandardMary) +deriving instance ToJSON (Ledger.EpochState StandardMary) +deriving instance ToJSON (Ledger.RewardUpdate StandardMary) +deriving instance ToJSON (Ledger.NewEpochState StandardMary) +deriving instance ToJSON (Ledger.PParams' StrictMaybe StandardMary) +deriving instance ToJSON (Ledger.PState StandardMary) +deriving instance ToJSON (Ledger.StakeReference StandardMary) +deriving instance ToJSON (Ledger.UTxOState StandardMary) + +deriving instance ToJSON (Ledger.FutureGenDeleg StandardCrypto) deriving instance ToJSON (Ledger.PrtclState StandardCrypto) deriving instance ToJSON Ledger.TicknState deriving instance ToJSON (Ledger.ChainDepState StandardCrypto) @@ -143,5 +190,13 @@ deriving instance ToJSON (Ledger.ChainDepState StandardCrypto) deriving instance ToJSONKey Ledger.Ptr deriving instance ToJSONKey (Ledger.FutureGenDeleg StandardCrypto) +deriving anyclass instance ToJSON (Ledger.Mary.Value StandardMary) +deriving newtype instance ToJSON (Ledger.Mary.PolicyID StandardMary) +deriving anyclass instance ToJSONKey (Ledger.Mary.PolicyID StandardMary) +deriving anyclass instance ToJSONKey Ledger.Mary.AssetName + +instance ToJSON Ledger.Mary.AssetName where + toJSON (Ledger.Mary.AssetName bs) = toJSON (Text.decodeLatin1 bs) + instance (ToJSONKey k, ToJSON v) => ToJSON (SetAlgebra.BiMap v k v) where toJSON = toJSON . SetAlgebra.forwards -- to normal Map