Skip to content

Commit 851e397

Browse files
committed
Rename class to Cip129
1 parent 105a6c0 commit 851e397

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

cardano-api/cardano-api.cabal

+1-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ library
189189

190190
other-modules:
191191
Cardano.Api.Internal.Anchor
192-
Cardano.Api.Internal.CIP.CIP129
192+
Cardano.Api.Internal.CIP.Cip129
193193
Cardano.Api.Internal.Certificate
194194
Cardano.Api.Internal.Compatible.Tx
195195
Cardano.Api.Internal.Convenience.Construction

cardano-api/src/Cardano/Api.hs

+3-3
Original file line numberDiff line numberDiff line change
@@ -710,9 +710,9 @@ module Cardano.Api
710710
, UsingBech32 (..)
711711

712712
-- ** Bech32 CIP-129
713-
, CIP129 (..)
713+
, Cip129 (..)
714714
, deserialiseFromBech32CIP129
715-
, serialiseToBech32CIP129
715+
, serialiseToBech32Cip129
716716

717717
-- ** Addresses
718718

@@ -1110,7 +1110,7 @@ where
11101110
import Cardano.Api.Internal.Address
11111111
import Cardano.Api.Internal.Anchor
11121112
import Cardano.Api.Internal.Block
1113-
import Cardano.Api.Internal.CIP.CIP129
1113+
import Cardano.Api.Internal.CIP.Cip129
11141114
import Cardano.Api.Internal.Certificate
11151115
import Cardano.Api.Internal.Convenience.Construction
11161116
import Cardano.Api.Internal.Convenience.Query

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

+16-13
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
{-# LANGUAGE TypeFamilies #-}
77
{-# OPTIONS_GHC -Wno-orphans #-}
88

9-
module Cardano.Api.Internal.CIP.CIP129
10-
( CIP129 (..)
9+
module Cardano.Api.Internal.CIP.Cip129
10+
( Cip129 (..)
1111
, deserialiseFromBech32CIP129
12-
, serialiseToBech32CIP129
12+
, serialiseToBech32Cip129
1313
, serialiseGovActionIdToBech32CIP129
1414
, deserialiseGovActionIdFromBech32CIP129
1515
)
@@ -38,9 +38,9 @@ import Data.Text (Text)
3838
import Data.Text.Encoding qualified as Text
3939
import GHC.Exts (IsList (..))
4040

41-
-- | CIP129 is a typeclass that captures the serialisation requirements of https://cips.cardano.org/cip/CIP-0129
41+
-- | Cip129 is a typeclass that captures the serialisation requirements of https://cips.cardano.org/cip/CIP-0129
4242
-- which pertain to governance credentials and governance action ids.
43-
class (SerialiseAsRawBytes a, HasTypeProxy a) => CIP129 a where
43+
class (SerialiseAsRawBytes a, HasTypeProxy a) => Cip129 a where
4444
cip129Bech32PrefixFor :: AsType a -> Text
4545

4646
cip129HeaderHexByte :: a -> ByteString
@@ -49,32 +49,35 @@ class (SerialiseAsRawBytes a, HasTypeProxy a) => CIP129 a where
4949
default cip129Bech32PrefixesPermitted :: AsType a -> [Text]
5050
cip129Bech32PrefixesPermitted = return . cip129Bech32PrefixFor
5151

52-
instance CIP129 (Credential L.ColdCommitteeRole) where
52+
instance Cip129 (Credential L.ColdCommitteeRole) where
5353
cip129Bech32PrefixFor _ = "cc_cold"
5454
cip129Bech32PrefixesPermitted AsColdCommitteeCredential = ["cc_cold"]
5555
cip129HeaderHexByte c =
5656
case c of
5757
L.KeyHashObj{} -> BS.singleton 0x12 -- 0001 0010
5858
L.ScriptHashObj{} -> BS.singleton 0x13 -- 0001 0011
5959

60-
instance CIP129 (Credential L.HotCommitteeRole) where
60+
instance Cip129 (Credential L.HotCommitteeRole) where
6161
cip129Bech32PrefixFor _ = "cc_hot"
6262
cip129Bech32PrefixesPermitted AsHotCommitteeCredential = ["cc_hot"]
6363
cip129HeaderHexByte c =
6464
case c of
6565
L.KeyHashObj{} -> BS.singleton 0x02 -- 0000 0010
6666
L.ScriptHashObj{} -> BS.singleton 0x03 -- 0000 0011
6767

68-
instance CIP129 (Credential L.DRepRole) where
68+
instance Cip129 (Credential L.DRepRole) where
6969
cip129Bech32PrefixFor _ = "drep"
7070
cip129Bech32PrefixesPermitted AsDrepCredential = ["drep"]
7171
cip129HeaderHexByte c =
7272
case c of
7373
L.KeyHashObj{} -> BS.singleton 0x22 -- 0010 0010
7474
L.ScriptHashObj{} -> BS.singleton 0x23 -- 0010 0011
7575

76-
serialiseToBech32CIP129 :: forall a. CIP129 a => a -> Text
77-
serialiseToBech32CIP129 a =
76+
-- | Serialize a accoding to the serialisation requirements of https://cips.cardano.org/cip/CIP-0129
77+
-- which currently pertain to governance credentials. Governance action ids are dealt separately with
78+
-- via 'serialiseGovActionIdToBech32CIP129'.
79+
serialiseToBech32Cip129 :: forall a. Cip129 a => a -> Text
80+
serialiseToBech32Cip129 a =
7881
Bech32.encodeLenient
7982
humanReadablePart
8083
(Bech32.dataPartFromBytes (cip129HeaderHexByte a <> serialiseToRawBytes a))
@@ -85,13 +88,13 @@ serialiseToBech32CIP129 a =
8588
Right p -> p
8689
Left err ->
8790
error $
88-
"serialiseToBech32CIP129: invalid prefix "
91+
"serialiseToBech32Cip129: invalid prefix "
8992
++ show prefix
9093
++ ", "
9194
++ show err
9295

9396
deserialiseFromBech32CIP129
94-
:: CIP129 a
97+
:: Cip129 a
9598
=> AsType a -> Text -> Either Bech32DecodeError a
9699
deserialiseFromBech32CIP129 asType bech32Str = do
97100
(prefix, dataPart) <-
@@ -130,7 +133,7 @@ deserialiseFromBech32CIP129 asType bech32Str = do
130133
toBase16Text = Text.decodeUtf8 . Base16.encode
131134

132135
-- | Governance Action ID
133-
-- According to CIP129 there is no header byte for GovActionId.
136+
-- According to Cip129 there is no header byte for GovActionId.
134137
-- Instead they append the txid and index to form the payload.
135138
serialiseGovActionIdToBech32CIP129 :: Gov.GovActionId -> Text
136139
serialiseGovActionIdToBech32CIP129 (Gov.GovActionId txid index) =

0 commit comments

Comments
 (0)