Skip to content

Commit 48b1878

Browse files
committed
Address review
1 parent 56b0842 commit 48b1878

File tree

4 files changed

+31
-37
lines changed

4 files changed

+31
-37
lines changed

cardano-api/cardano-api.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ library
8585
Cardano.Api.Internal.LedgerState
8686
Cardano.Api.Internal.Modes
8787
Cardano.Api.Internal.Orphans.All
88-
Cardano.Api.Internal.Orphans.Serialization
88+
Cardano.Api.Internal.Orphans.Serialisation
8989
Cardano.Api.Internal.Orphans.Misc
9090
Cardano.Api.Internal.Plutus
9191
Cardano.Api.Internal.Pretty

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

Lines changed: 21 additions & 13 deletions
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,6 +13,7 @@ module Cardano.Api.Internal.CIP.Cip129
1213
, serialiseToBech32Cip129
1314
, serialiseGovActionIdToBech32CIP129
1415
, deserialiseGovActionIdFromBech32CIP129
16+
, AsType (AsColdCommitteeCredential, AsDrepCredential, AsHotCommitteeCredential)
1517
)
1618
where
1719

@@ -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
Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,3 @@
1-
{-# LANGUAGE DataKinds #-}
2-
{-# LANGUAGE DeriveAnyClass #-}
3-
{-# LANGUAGE DeriveDataTypeable #-}
4-
{-# LANGUAGE DeriveGeneric #-}
5-
{-# LANGUAGE DerivingVia #-}
6-
{-# LANGUAGE FlexibleContexts #-}
7-
{-# LANGUAGE FlexibleInstances #-}
8-
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
9-
{-# LANGUAGE NamedFieldPuns #-}
10-
{-# LANGUAGE OverloadedStrings #-}
11-
{-# LANGUAGE StandaloneDeriving #-}
12-
{-# LANGUAGE TypeFamilies #-}
13-
{-# LANGUAGE UndecidableInstances #-}
14-
{-# OPTIONS_GHC -Wno-orphans -Wno-unused-imports #-}
15-
161
module Cardano.Api.Internal.Orphans.All
172
( AsType
183
( AsColdCommitteeCredential
@@ -24,10 +9,11 @@ module Cardano.Api.Internal.Orphans.All
249
where
2510

2611
import Cardano.Api.Internal.Orphans.Misc ()
27-
import Cardano.Api.Internal.Orphans.Serialization (AsType
28-
( AsColdCommitteeCredential
29-
, AsHotCommitteeCredential
30-
, AsDrepCredential
31-
, AsGovActionId
32-
))
33-
import Cardano.Api.Internal.Orphans.Serialization ()
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/Serialization.hs renamed to cardano-api/src/Cardano/Api/Internal/Orphans/Serialisation.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
{-# LANGUAGE UndecidableInstances #-}
1414
{-# OPTIONS_GHC -Wno-orphans -Wno-unused-imports #-}
1515

16-
module Cardano.Api.Internal.Orphans.Serialization
16+
module Cardano.Api.Internal.Orphans.Serialisation
1717

1818
( AsType
1919
( AsColdCommitteeCredential

0 commit comments

Comments
 (0)