Skip to content

Commit

Permalink
Merge #4223
Browse files Browse the repository at this point in the history
4223: Script ToJSON instances serialises the full script r=ch1bo a=ch1bo

Mirrored changes of #4138 on origin `cardano-node` repository and targeting `master` per request of `@Jimbo4350` 

Co-authored-by: Arnaud Bailly <arnaud.bailly@iohk.io>
  • Loading branch information
iohk-bors[bot] and abailly authored Jul 26, 2022
2 parents 7da1f19 + 8794da7 commit 803881b
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions cardano-api/src/Cardano/Api/Orphans.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE UndecidableInstances #-}

{-# OPTIONS_GHC -Wno-orphans #-}
Expand Down Expand Up @@ -40,6 +39,7 @@ import Cardano.Ledger.UnifiedMap (UnifiedMap)
import Cardano.Slotting.Slot (SlotNo (..))
import Cardano.Slotting.Time (SystemStart (..))

import qualified Cardano.Binary as CBOR
import qualified Cardano.Crypto.Hash.Class as Crypto
import qualified Cardano.Ledger.Alonzo.Data as Alonzo
import qualified Cardano.Ledger.Alonzo.Scripts as Alonzo
Expand All @@ -61,7 +61,6 @@ import qualified Cardano.Ledger.Shelley.Rewards as Shelley
import qualified Ouroboros.Consensus.Shelley.Eras as Consensus

import Cardano.Api.Script
import Cardano.Api.SerialiseRaw (serialiseToRawBytesHexText)

-- Orphan instances involved in the JSON output of the API queries.
-- We will remove/replace these as we provide more API wrapper types
Expand Down Expand Up @@ -241,11 +240,10 @@ instance ( Ledger.Era era
SNothing -> Aeson.Null
SJust dH -> toJSON $ ScriptDataHash dH

instance ToJSON (Alonzo.Script (Babbage.BabbageEra Consensus.StandardCrypto)) where
toJSON s = Aeson.String . serialiseToRawBytesHexText
$ ScriptHash $ Ledger.hashScript @(Babbage.BabbageEra Consensus.StandardCrypto) s


instance ToJSON (Alonzo.Script (Babbage.BabbageEra Consensus.StandardCrypto)) where
toJSON = Aeson.String . Text.decodeUtf8 . B16.encode . CBOR.serialize'

instance Crypto.Crypto crypto => ToJSON (Shelley.DPState crypto) where
toJSON dpState = object [ "dstate" .= Shelley.dpsDState dpState
Expand Down

0 comments on commit 803881b

Please sign in to comment.