Skip to content

Commit 97714e9

Browse files
committed
Address review
1 parent a9312df commit 97714e9

File tree

15 files changed

+66
-78
lines changed

15 files changed

+66
-78
lines changed

cardano-api/cardano-api.cabal

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ library
8484
Cardano.Api.Internal.IO
8585
Cardano.Api.Internal.LedgerState
8686
Cardano.Api.Internal.Modes
87-
Cardano.Api.Internal.Orphans.All
88-
Cardano.Api.Internal.Orphans.Serialization
87+
Cardano.Api.Internal.Orphans
8988
Cardano.Api.Internal.Orphans.Misc
89+
Cardano.Api.Internal.Orphans.Serialisation
9090
Cardano.Api.Internal.Plutus
9191
Cardano.Api.Internal.Pretty
9292
Cardano.Api.Internal.ProtocolParameters

cardano-api/src/Cardano/Api.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1156,7 +1156,7 @@ import Cardano.Api.Internal.Modes
11561156
import Cardano.Api.Internal.Monad.Error
11571157
import Cardano.Api.Internal.NetworkId
11581158
import Cardano.Api.Internal.OperationalCertificate
1159-
import Cardano.Api.Internal.Orphans.All ()
1159+
import Cardano.Api.Internal.Orphans ()
11601160
import Cardano.Api.Internal.Plutus
11611161
import Cardano.Api.Internal.Pretty
11621162
import Cardano.Api.Internal.Protocol

cardano-api/src/Cardano/Api/Internal/CIP/Cip129.hs

+22-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{-# LANGUAGE DataKinds #-}
22
{-# LANGUAGE DefaultSignatures #-}
33
{-# LANGUAGE FlexibleInstances #-}
4+
{-# LANGUAGE LambdaCase #-}
45
{-# LANGUAGE RankNTypes #-}
56
{-# LANGUAGE ScopedTypeVariables #-}
67
{-# LANGUAGE TypeFamilies #-}
@@ -12,12 +13,13 @@ module Cardano.Api.Internal.CIP.Cip129
1213
, serialiseToBech32Cip129
1314
, serialiseGovActionIdToBech32CIP129
1415
, deserialiseGovActionIdFromBech32CIP129
16+
, AsType (AsColdCommitteeCredential, AsDrepCredential, AsHotCommitteeCredential)
1517
)
1618
where
1719

1820
import Cardano.Api.Internal.Governance.Actions.ProposalProcedure
1921
import Cardano.Api.Internal.HasTypeProxy
20-
import Cardano.Api.Internal.Orphans.All (AsType (..))
22+
import Cardano.Api.Internal.Orphans (AsType (..))
2123
import Cardano.Api.Internal.SerialiseBech32
2224
import Cardano.Api.Internal.SerialiseRaw
2325
import Cardano.Api.Internal.TxIn
@@ -38,17 +40,22 @@ import Data.Text (Text)
3840
import Data.Text.Encoding qualified as Text
3941
import GHC.Exts (IsList (..))
4042

41-
-- | Cip129 is a typeclass that captures the serialisation requirements of https://cips.cardano.org/cip/CIP-0129
43+
-- | Cip-129 is a typeclass that captures the serialisation requirements of https://cips.cardano.org/cip/CIP-0129
4244
-- which pertain to governance credentials and governance action ids.
4345
class (SerialiseAsRawBytes a, HasTypeProxy a) => Cip129 a where
46+
-- | The human readable part of the Bech32 encoding for the credential.
4447
cip129Bech32PrefixFor :: AsType a -> Bech32.HumanReadablePart
4548

49+
-- | The header byte that identifies the credential type according to Cip-129.
4650
cip129HeaderHexByte :: a -> ByteString
4751

52+
-- | Permitted bech32 prefixes according to Cip-129.
4853
cip129Bech32PrefixesPermitted :: AsType a -> [Text]
4954
default cip129Bech32PrefixesPermitted :: AsType a -> [Text]
5055
cip129Bech32PrefixesPermitted = return . Bech32.humanReadablePartToText . cip129Bech32PrefixFor
5156

57+
-- | The human readable part of the Bech32 encoding for the credential. This will
58+
-- error if the prefix is not valid.
5259
unsafeHumanReadablePartFromText :: Text -> Bech32.HumanReadablePart
5360
unsafeHumanReadablePartFromText =
5461
either (error . ("Error while parsing Bech32: " <>) . show) id
@@ -57,26 +64,27 @@ unsafeHumanReadablePartFromText =
5764
instance Cip129 (Credential L.ColdCommitteeRole) where
5865
cip129Bech32PrefixFor _ = unsafeHumanReadablePartFromText "cc_cold"
5966
cip129Bech32PrefixesPermitted AsColdCommitteeCredential = ["cc_cold"]
60-
cip129HeaderHexByte c =
61-
case c of
62-
L.KeyHashObj{} -> BS.singleton 0x12 -- 0001 0010
63-
L.ScriptHashObj{} -> BS.singleton 0x13 -- 0001 0011
67+
68+
cip129HeaderHexByte =
69+
BS.singleton . \case
70+
L.KeyHashObj{} -> 0x12 -- 0001 0010
71+
L.ScriptHashObj{} -> 0x13 -- 0001 0011
6472

6573
instance Cip129 (Credential L.HotCommitteeRole) where
6674
cip129Bech32PrefixFor _ = unsafeHumanReadablePartFromText "cc_hot"
6775
cip129Bech32PrefixesPermitted AsHotCommitteeCredential = ["cc_hot"]
68-
cip129HeaderHexByte c =
69-
case c of
70-
L.KeyHashObj{} -> BS.singleton 0x02 -- 0000 0010
71-
L.ScriptHashObj{} -> BS.singleton 0x03 -- 0000 0011
76+
cip129HeaderHexByte =
77+
BS.singleton . \case
78+
L.KeyHashObj{} -> 0x02 -- 0000 0010
79+
L.ScriptHashObj{} -> 0x03 -- 0000 0011
7280

7381
instance Cip129 (Credential L.DRepRole) where
7482
cip129Bech32PrefixFor _ = unsafeHumanReadablePartFromText "drep"
7583
cip129Bech32PrefixesPermitted AsDrepCredential = ["drep"]
76-
cip129HeaderHexByte c =
77-
case c of
78-
L.KeyHashObj{} -> BS.singleton 0x22 -- 0010 0010
79-
L.ScriptHashObj{} -> BS.singleton 0x23 -- 0010 0011
84+
cip129HeaderHexByte =
85+
BS.singleton . \case
86+
L.KeyHashObj{} -> 0x22 -- 0010 0010
87+
L.ScriptHashObj{} -> 0x23 -- 0010 0011
8088

8189
-- | Serialize a accoding to the serialisation requirements of https://cips.cardano.org/cip/CIP-0129
8290
-- which currently pertain to governance credentials. Governance action ids are dealt separately with

cardano-api/src/Cardano/Api/Internal/Eon/ShelleyBasedEra.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ where
3939
import Cardano.Api.Internal.Eon.Convert
4040
import Cardano.Api.Internal.Eras.Core
4141
import Cardano.Api.Internal.Modes
42-
import Cardano.Api.Internal.Orphans.All ()
42+
import Cardano.Api.Internal.Orphans ()
4343
import Cardano.Api.Internal.Pretty (Pretty)
4444

4545
import Cardano.Crypto.Hash.Blake2b qualified as Blake2b

cardano-api/src/Cardano/Api/Internal/InMode.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ where
3030
import Cardano.Api.Internal.Eon.ShelleyBasedEra
3131
import Cardano.Api.Internal.Eras
3232
import Cardano.Api.Internal.Modes
33-
import Cardano.Api.Internal.Orphans.All ()
33+
import Cardano.Api.Internal.Orphans ()
3434
import Cardano.Api.Internal.Tx.Body
3535
import Cardano.Api.Internal.Tx.Sign
3636
import Cardano.Api.Internal.Utils (textShow)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module Cardano.Api.Internal.Orphans
2+
( AsType
3+
( AsColdCommitteeCredential
4+
, AsDrepCredential
5+
, AsGovActionId
6+
, AsHotCommitteeCredential
7+
)
8+
)
9+
where
10+
11+
import Cardano.Api.Internal.Orphans.Misc ()
12+
import Cardano.Api.Internal.Orphans.Serialisation
13+
( AsType
14+
( AsColdCommitteeCredential
15+
, AsDrepCredential
16+
, AsGovActionId
17+
, AsHotCommitteeCredential
18+
)
19+
)

cardano-api/src/Cardano/Api/Internal/Orphans/All.hs

-33
This file was deleted.

cardano-api/src/Cardano/Api/Internal/Orphans/Misc.hs

+11-13
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,35 @@
1111
{-# LANGUAGE StandaloneDeriving #-}
1212
{-# LANGUAGE TypeFamilies #-}
1313
{-# LANGUAGE UndecidableInstances #-}
14-
15-
16-
{-# OPTIONS_GHC -Wno-orphans #-}
14+
{-# OPTIONS_GHC -Wno-orphans #-}
1715

1816
module Cardano.Api.Internal.Orphans.Misc
19-
(
20-
) where
17+
(
18+
)
19+
where
2120

22-
import Cardano.Ledger.Binary
23-
import Codec.Binary.Bech32 qualified as Bech32
24-
import Codec.CBOR.Read qualified as CBOR
25-
import Data.Data (Data)
2621
import Cardano.Api.Internal.Pretty (Pretty (..), prettyException, (<+>))
22+
2723
import Cardano.Ledger.Alonzo.PParams qualified as Ledger
2824
import Cardano.Ledger.Babbage.PParams qualified as Ledger
2925
import Cardano.Ledger.BaseTypes (strictMaybeToMaybe)
3026
import Cardano.Ledger.BaseTypes qualified as Ledger
27+
import Cardano.Ledger.Binary
3128
import Cardano.Ledger.Coin qualified as L
3229
import Cardano.Ledger.Conway.PParams qualified as Ledger
3330
import Cardano.Ledger.HKD (NoUpdate (..))
3431
import Cardano.Ledger.Shelley.PParams qualified as Ledger
32+
33+
import Codec.Binary.Bech32 qualified as Bech32
34+
import Codec.CBOR.Read qualified as CBOR
35+
import Data.Data (Data)
3536
import Data.ListMap (ListMap)
3637
import Data.ListMap qualified as ListMap
3738
import Data.Maybe.Strict (StrictMaybe (..))
3839
import Data.Monoid
3940
import GHC.Exts (IsList (..))
4041
import Network.Mux qualified as Mux
4142

42-
4343
deriving instance Data DecoderError
4444

4545
deriving instance Data CBOR.DeserialiseFailure
@@ -60,8 +60,6 @@ deriving newtype instance Integral L.Coin
6060

6161
deriving newtype instance Num L.Coin
6262

63-
64-
6563
-- We wrap the individual records with Last and use Last's Semigroup instance.
6664
-- In this instance we take the last 'Just' value or the only 'Just' value
6765
instance Semigroup (Ledger.ShelleyPParams StrictMaybe era) where
@@ -266,4 +264,4 @@ instance Pretty Mux.Error where
266264
instance IsList (ListMap k a) where
267265
type Item (ListMap k a) = (k, a)
268266
fromList = ListMap.fromList
269-
toList = ListMap.toList
267+
toList = ListMap.toList

cardano-api/src/Cardano/Api/Internal/Orphans/Serialization.hs renamed to cardano-api/src/Cardano/Api/Internal/Orphans/Serialisation.hs

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{-# LANGUAGE DataKinds #-}
22
{-# LANGUAGE DeriveAnyClass #-}
3-
{-# LANGUAGE DeriveDataTypeable #-}
43
{-# LANGUAGE DeriveGeneric #-}
54
{-# LANGUAGE DerivingVia #-}
65
{-# LANGUAGE FlexibleContexts #-}
@@ -13,8 +12,7 @@
1312
{-# LANGUAGE UndecidableInstances #-}
1413
{-# OPTIONS_GHC -Wno-orphans -Wno-unused-imports #-}
1514

16-
module Cardano.Api.Internal.Orphans.Serialization
17-
15+
module Cardano.Api.Internal.Orphans.Serialisation
1816
( AsType
1917
( AsColdCommitteeCredential
2018
, AsHotCommitteeCredential
@@ -25,12 +23,13 @@ module Cardano.Api.Internal.Orphans.Serialization
2523
where
2624

2725
import Cardano.Api.Internal.HasTypeProxy
26+
import Cardano.Api.Internal.Orphans.Misc
2827
import Cardano.Api.Internal.Pretty (Pretty (..), prettyException, (<+>))
2928
import Cardano.Api.Internal.SerialiseRaw
3029
import Cardano.Api.Internal.TxIn
3130
import Cardano.Api.Internal.Via.ShowOf
3231
import Cardano.Api.Ledger qualified as Ledger
33-
import Cardano.Api.Internal.Orphans.Misc
32+
3433
import Cardano.Binary (DecoderError (..))
3534
import Cardano.Binary qualified as CBOR
3635
import Cardano.Chain.Byron.API qualified as L
@@ -255,7 +254,6 @@ deriving via ShowOf L.KeyHash instance ToJSON L.KeyHash
255254

256255
deriving via ShowOf L.ApplicationName instance ToJSONKey L.ApplicationName
257256

258-
259257
instance Pretty L.Coin where
260258
pretty (L.Coin n) = pretty n <+> "Lovelace"
261259

@@ -370,7 +368,6 @@ instance ToJSON PraosState where
370368
, "lastEpochBlockNonce" .= Consensus.praosStateLastEpochBlockNonce s
371369
]
372370

373-
374371
instance A.FromJSON V2.ParamName where
375372
parseJSON = A.withText "ParamName" parsePlutusParamName
376373

@@ -385,7 +382,6 @@ parsePlutusParamName t =
385382

386383
deriving instance Show V2.ParamName
387384

388-
389385
instance HasTypeProxy (Ledger.Credential L.ColdCommitteeRole) where
390386
data AsType (Ledger.Credential L.ColdCommitteeRole) = AsColdCommitteeCredential
391387
proxyToAsType _ = AsColdCommitteeCredential

cardano-api/src/Cardano/Api/Internal/ProtocolParameters.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ import Cardano.Api.Internal.Hash
101101
import Cardano.Api.Internal.Json (toRationalJSON)
102102
import Cardano.Api.Internal.Keys.Byron
103103
import Cardano.Api.Internal.Keys.Shelley
104-
import Cardano.Api.Internal.Orphans.All ()
104+
import Cardano.Api.Internal.Orphans ()
105105
import Cardano.Api.Internal.Pretty
106106
import Cardano.Api.Internal.Script
107107
import Cardano.Api.Internal.Serialise.Cbor

cardano-api/src/Cardano/Api/Internal/Query/Types.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module Cardano.Api.Internal.Query.Types
99
where
1010

1111
import Cardano.Api.Internal.Eon.ShelleyBasedEra
12-
import Cardano.Api.Internal.Orphans.All ()
12+
import Cardano.Api.Internal.Orphans ()
1313

1414
import Cardano.Binary
1515
import Cardano.Ledger.Binary.Plain qualified as Plain

cardano-api/src/Cardano/Api/Internal/SerialiseTextEnvelope.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import Cardano.Api.Internal.Eras
4242
import Cardano.Api.Internal.Error
4343
import Cardano.Api.Internal.HasTypeProxy
4444
import Cardano.Api.Internal.IO
45-
import Cardano.Api.Internal.Orphans.All ()
45+
import Cardano.Api.Internal.Orphans ()
4646
import Cardano.Api.Internal.Pretty
4747
import Cardano.Api.Internal.Serialise.Cbor
4848
import Cardano.Api.Internal.Utils (readFileBlocking)

cardano-api/src/Cardano/Api/Ledger/Lens.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ import Cardano.Api.Internal.Eon.ShelleyEraOnly
5151
import Cardano.Api.Internal.Eon.ShelleyToAllegraEra
5252
import Cardano.Api.Internal.Eon.ShelleyToBabbageEra
5353
import Cardano.Api.Internal.Eras.Case
54-
import Cardano.Api.Internal.Orphans.All ()
54+
import Cardano.Api.Internal.Orphans ()
5555

5656
import Cardano.Ledger.Allegra.Core qualified as L
5757
import Cardano.Ledger.Alonzo.Core qualified as L

cardano-api/test/cardano-api-test/Test/Cardano/Api/Eras.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module Test.Cardano.Api.Eras
66
where
77

88
import Cardano.Api
9-
import Cardano.Api.Internal.Orphans.All ()
9+
import Cardano.Api.Internal.Orphans ()
1010

1111
import Data.Aeson (ToJSON (..), decode, encode)
1212

cardano-api/test/cardano-api-test/Test/Cardano/Api/Json.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module Test.Cardano.Api.Json
77
where
88

99
import Cardano.Api
10-
import Cardano.Api.Internal.Orphans.All ()
10+
import Cardano.Api.Internal.Orphans ()
1111
import Cardano.Api.Shelley
1212

1313
import Data.Aeson (eitherDecode, encode)

0 commit comments

Comments
 (0)