Skip to content

Commit 1a1e7ca

Browse files
committed
Add "cip" sub command
Add "cip-126" sub commands Add cip-129 encoding functions Add functions to read committee cold keys, governance action ids, hot keys and drep keys Update Bech32 errors Update "governance drep id" command to also output the cip-129 format Implement Cardano.CLI.EraIndependent.Cip.Common Misc changes Update golden files REMOVE ME Incorporate Vary Update golden files
1 parent 773ad5c commit 1a1e7ca

36 files changed

+902
-40
lines changed

cabal.project

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,8 @@ if impl (ghc >= 9.12)
7474
-- https://github.com/kapralVV/Unique/issues/11
7575
, Unique:hashable
7676

77+
source-repository-package
78+
type: git
79+
location: https://github.com/IntersectMBO/cardano-api.git
80+
tag: 180129463ef6fb1942883fa9058e3cb34eef160f
81+
subdir: cardano-api

cardano-cli/cardano-cli.cabal

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,14 @@ library
142142
Cardano.CLI.EraIndependent.Address.Info.Run
143143
Cardano.CLI.EraIndependent.Address.Option
144144
Cardano.CLI.EraIndependent.Address.Run
145+
Cardano.CLI.EraIndependent.Cip.Cip129.Command
146+
Cardano.CLI.EraIndependent.Cip.Cip129.Conversion
147+
Cardano.CLI.EraIndependent.Cip.Cip129.Options
148+
Cardano.CLI.EraIndependent.Cip.Cip129.Run
149+
Cardano.CLI.EraIndependent.Cip.Command
150+
Cardano.CLI.EraIndependent.Cip.Common
151+
Cardano.CLI.EraIndependent.Cip.Options
152+
Cardano.CLI.EraIndependent.Cip.Run
145153
Cardano.CLI.EraIndependent.Debug.CheckNodeConfiguration.Command
146154
Cardano.CLI.EraIndependent.Debug.CheckNodeConfiguration.Run
147155
Cardano.CLI.EraIndependent.Debug.Command
@@ -181,6 +189,10 @@ library
181189
Cardano.CLI.Orphan
182190
Cardano.CLI.Parser
183191
Cardano.CLI.Read
192+
Cardano.CLI.Read.Committee.ColdKey
193+
Cardano.CLI.Read.Committee.HotKey
194+
Cardano.CLI.Read.DRep
195+
Cardano.CLI.Read.GovernanceActionId
184196
Cardano.CLI.Render
185197
Cardano.CLI.Run
186198
Cardano.CLI.Run.Mnemonic
@@ -287,6 +299,7 @@ library
287299
transformers-except ^>=0.1.3,
288300
unliftio-core,
289301
utf8-string,
302+
validation,
290303
vary ^>=0.1.1.2,
291304
vector,
292305
yaml,

cardano-cli/src/Cardano/CLI/Command.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import Cardano.CLI.Compatible.Command
1010
import Cardano.CLI.EraBased.Command
1111
import Cardano.CLI.EraBased.Query.Command
1212
import Cardano.CLI.EraIndependent.Address.Command
13+
import Cardano.CLI.EraIndependent.Cip.Command (CipFormatCmds)
1314
import Cardano.CLI.EraIndependent.Debug.Command
1415
import Cardano.CLI.EraIndependent.Hash.Command (HashCmds)
1516
import Cardano.CLI.EraIndependent.Key.Command
@@ -37,6 +38,8 @@ data ClientCommand
3738
forall era. QueryCommands (QueryCmds era)
3839
| -- | Legacy shelley-based Commands
3940
LegacyCmds LegacyCmds
41+
| -- | Miscellaneous commands
42+
CipFormatCmds CipFormatCmds
4043
| CliPingCommand PingCmd
4144
| CliDebugCmds DebugCmds
4245
| forall a. Help ParserPrefs (ParserInfo a)

cardano-cli/src/Cardano/CLI/EraBased/Common/Option.hs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1830,12 +1830,30 @@ pFormatFlags content =
18301830
, "."
18311831
]
18321832

1833+
flagFormatBech32
1834+
:: FormatBech32 :| fs
1835+
=> Flag (Vary fs)
1836+
flagFormatBech32 =
1837+
mkFlag "output-bech32" "Bech32" FormatBech32
1838+
18331839
flagFormatCbor
18341840
:: FormatCbor :| fs
18351841
=> Flag (Vary fs)
18361842
flagFormatCbor =
18371843
mkFlag "output-cbor" "BASE16 CBOR" FormatCbor
18381844

1845+
flagFormatCip129
1846+
:: FormatCip129 :| fs
1847+
=> Flag (Vary fs)
1848+
flagFormatCip129 =
1849+
mkFlag "output-cip129" "CIP-129" FormatCip129
1850+
1851+
flagFormatHex
1852+
:: FormatHex :| fs
1853+
=> Flag (Vary fs)
1854+
flagFormatHex =
1855+
mkFlag "output-hex" "BASE16" FormatHex
1856+
18391857
flagFormatJson
18401858
:: FormatJson :| fs
18411859
=> Flag (Vary fs)
@@ -1996,6 +2014,7 @@ pKesVerificationKey =
19962014
Left err@(Bech32DataPartToBytesError _) -> Left (docToString $ prettyError err)
19972015
Left err@(Bech32DeserialiseFromBytesError _) -> Left (docToString $ prettyError err)
19982016
Left err@(Bech32WrongPrefix _ _) -> Left (docToString $ prettyError err)
2017+
Left err@(Bech32UnexpectedHeader _ _) -> Left (docToString $ prettyError err)
19992018
-- The input was not valid Bech32. Attempt to deserialise it as hex.
20002019
Left (Bech32DecodingError _) ->
20012020
first

cardano-cli/src/Cardano/CLI/EraBased/Governance/DRep/Command.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{-# LANGUAGE DataKinds #-}
22
{-# LANGUAGE DuplicateRecordFields #-}
3+
{-# LANGUAGE GADTs #-}
34
{-# LANGUAGE LambdaCase #-}
45

56
module Cardano.CLI.EraBased.Governance.DRep.Command
@@ -24,6 +25,8 @@ import Cardano.CLI.Type.Key
2425

2526
import Data.Text (Text)
2627

28+
import Vary (Vary)
29+
2730
data GovernanceDRepCmds era
2831
= GovernanceDRepKeyGenCmd !(GovernanceDRepKeyGenCmdArgs era)
2932
| GovernanceDRepIdCmd !(GovernanceDRepIdCmdArgs era)
@@ -43,7 +46,7 @@ data GovernanceDRepIdCmdArgs era
4346
= GovernanceDRepIdCmdArgs
4447
{ eon :: !(ConwayEraOnwards era)
4548
, vkeySource :: !(VerificationKeyOrHashOrFile DRepKey)
46-
, idOutputFormat :: !IdOutputFormat
49+
, idOutputFormat :: !(Vary [FormatHex, FormatBech32, FormatCip129])
4750
, mOutFile :: !(Maybe (File () Out))
4851
}
4952

cardano-cli/src/Cardano/CLI/EraBased/Governance/DRep/Option.hs

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ import Cardano.Api.Shelley (Hash (DRepMetadataHash))
1414
import Cardano.CLI.EraBased.Common.Option
1515
import Cardano.CLI.EraBased.Governance.DRep.Command
1616
import Cardano.CLI.EraIndependent.Hash.Command (HashGoal (..))
17+
import Cardano.CLI.Option.Flag
1718
import Cardano.CLI.Parser
1819
import Cardano.CLI.Read
19-
import Cardano.CLI.Type.Common hiding (CheckHash)
2020

2121
import Control.Applicative (Alternative ((<|>)), optional)
2222
import Data.Foldable (asum)
23+
import Data.Function
2324
import Options.Applicative (Parser)
2425
import Options.Applicative qualified as Opt
2526

@@ -73,27 +74,16 @@ pGovernanceDRepKeyIdCmd era = do
7374
( fmap GovernanceDRepIdCmd $
7475
GovernanceDRepIdCmdArgs w
7576
<$> pDRepVerificationKeyOrHashOrFile
76-
<*> pDRepIdOutputFormat
77+
<*> pFormatFlags
78+
"drep id output"
79+
[ flagFormatHex
80+
, flagFormatBech32 & setDefault
81+
, flagFormatCip129
82+
]
7783
<*> optional pOutputFile
7884
)
7985
$ Opt.progDesc "Generate a drep id."
8086

81-
pDRepIdOutputFormat :: Parser IdOutputFormat
82-
pDRepIdOutputFormat =
83-
asum [make IdOutputFormatHex "hex", make IdOutputFormatBech32 "bech32"]
84-
<|> pure default_
85-
where
86-
default_ = IdOutputFormatBech32
87-
make format flag_ =
88-
Opt.flag' format $
89-
mconcat
90-
[ Opt.help $
91-
"Format drep id output as "
92-
<> flag_
93-
<> (if format == default_ then " (the default)." else ".")
94-
, Opt.long ("output-" <> flag_)
95-
]
96-
9787
-- Registration Certificate related
9888

9989
pRegistrationCertificateCmd

cardano-cli/src/Cardano/CLI/EraBased/Governance/DRep/Run.hs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ where
1717

1818
import Cardano.Api
1919
import Cardano.Api.Ledger qualified as L
20+
import Cardano.Api.Shelley
2021

2122
import Cardano.CLI.EraBased.Governance.DRep.Command qualified as Cmd
2223
import Cardano.CLI.EraIndependent.Hash.Command qualified as Cmd
@@ -38,6 +39,8 @@ import Data.ByteString (ByteString)
3839
import Data.Function
3940
import Data.Text.Encoding qualified as Text
4041

42+
import Vary qualified
43+
4144
runGovernanceDRepCmds
4245
:: ()
4346
=> Cmd.GovernanceDRepCmds era
@@ -92,9 +95,18 @@ runGovernanceDRepIdCmd
9295
readVerificationKeyOrHashOrTextEnvFile AsDRepKey vkeySource
9396

9497
content <-
95-
pure $ case idOutputFormat of
96-
IdOutputFormatHex -> serialiseToRawBytesHex drepVerKeyHash
97-
IdOutputFormatBech32 -> Text.encodeUtf8 $ serialiseToBech32 drepVerKeyHash
98+
pure $
99+
idOutputFormat
100+
& ( Vary.on (\FormatHex -> serialiseToRawBytesHex drepVerKeyHash)
101+
$ Vary.on (\FormatBech32 -> Text.encodeUtf8 $ serialiseToBech32 drepVerKeyHash)
102+
$ Vary.on
103+
( \FormatCip129 ->
104+
let DRepKeyHash kh = drepVerKeyHash
105+
keyCredential = L.KeyHashObj kh
106+
in Text.encodeUtf8 $ serialiseToBech32Cip129 keyCredential
107+
)
108+
$ Vary.exhaustiveCase
109+
)
98110

99111
lift (writeByteStringOutput mOutFile content)
100112
& onLeft (left . WriteFileError)

cardano-cli/src/Cardano/CLI/EraBased/Query/Run.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ where
4242
import Cardano.Api hiding (QueryInShelleyBasedEra (..))
4343
import Cardano.Api qualified as Api
4444
import Cardano.Api.Consensus qualified as Consensus
45-
import Cardano.Api.Ledger (StandardCrypto, strictMaybeToMaybe)
45+
import Cardano.Api.Ledger (strictMaybeToMaybe)
4646
import Cardano.Api.Ledger qualified as L
4747
import Cardano.Api.Network (LedgerPeerSnapshot, Serialised (..))
4848
import Cardano.Api.Network qualified as Consensus
@@ -1118,7 +1118,7 @@ writePoolState mOutFile serialisedCurrentEpochState = do
11181118
<> Map.keysSet (L.psFutureStakePoolParams poolState)
11191119
<> Map.keysSet (L.psRetiring poolState)
11201120

1121-
let poolStates :: Map (L.KeyHash 'L.StakePool) (Params StandardCrypto)
1121+
let poolStates :: Map (L.KeyHash 'L.StakePool) Params
11221122
poolStates =
11231123
fromList $
11241124
hks
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module Cardano.CLI.EraIndependent.Cip.Cip129.Command
2+
( Cip129 (..)
3+
, renderCip129Command
4+
)
5+
where
6+
7+
import Cardano.CLI.EraIndependent.Cip.Common
8+
9+
import Data.Text (Text)
10+
11+
data Cip129
12+
= Cip129DRep Input Output
13+
| Cip129CommitteeHotKey Input Output
14+
| Cip129CommitteeColdKey Input Output
15+
| Cip129GovernanceAction Input Output
16+
17+
renderCip129Command :: Cip129 -> Text
18+
renderCip129Command (Cip129DRep{}) = "cip-129 drep"
19+
renderCip129Command (Cip129CommitteeHotKey{}) = "cip-129 committee-hot-key"
20+
renderCip129Command (Cip129CommitteeColdKey{}) = "cip-129 committee-cold-key"
21+
renderCip129Command (Cip129GovernanceAction{}) = "cip-129 governance-action-id"
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{-# LANGUAGE DataKinds #-}
2+
3+
module Cardano.CLI.EraIndependent.Cip.Cip129.Conversion
4+
( encodeCip129DrepVerficationKeyText
5+
, encodeCip129CommitteeColdVerficationKeyText
6+
, encodeCip129CommitteeHotVerficationKeyText
7+
, encodeCip129GovernanceActionIdText
8+
)
9+
where
10+
11+
import Cardano.Api.Ledger qualified as L
12+
import Cardano.Api.Shelley
13+
14+
import Cardano.CLI.Read.Committee.ColdKey
15+
import Cardano.CLI.Read.Committee.HotKey
16+
import Cardano.CLI.Read.DRep
17+
18+
import Data.Text
19+
20+
encodeCip129DrepVerficationKeyText :: AnyDrepVerificationKey -> Text
21+
encodeCip129DrepVerficationKeyText = serialiseToBech32Cip129 . anyDrepVerificationKeyToCredential
22+
23+
anyDrepVerificationKeyToCredential
24+
:: AnyDrepVerificationKey -> L.Credential L.DRepRole
25+
anyDrepVerificationKeyToCredential drepKey =
26+
case drepKey of
27+
AnyDrepVerificationKey vk ->
28+
let DRepKeyHash hash = verificationKeyHash vk
29+
in L.KeyHashObj hash
30+
AnyDrepExtendedVerificationKey vk ->
31+
let DRepExtendedKeyHash hash = verificationKeyHash vk
32+
in L.KeyHashObj hash
33+
34+
encodeCip129CommitteeHotVerficationKeyText :: AnyCommitteeHotVerificationKey -> Text
35+
encodeCip129CommitteeHotVerficationKeyText = serialiseToBech32Cip129 . anyCommitteeHotVerificationKeyToCredential
36+
37+
anyCommitteeHotVerificationKeyToCredential
38+
:: AnyCommitteeHotVerificationKey -> L.Credential L.HotCommitteeRole
39+
anyCommitteeHotVerificationKeyToCredential committeeHotKey =
40+
case committeeHotKey of
41+
AnyCommitteeHotVerificationKey vk ->
42+
let CommitteeHotKeyHash hash = verificationKeyHash vk
43+
in L.KeyHashObj hash
44+
AnyCommitteeHotExtendedVerificationKey vk ->
45+
let CommitteeHotExtendedKeyHash hash = verificationKeyHash vk
46+
in L.KeyHashObj hash
47+
48+
encodeCip129CommitteeColdVerficationKeyText :: AnyCommitteeColdVerificationKey -> Text
49+
encodeCip129CommitteeColdVerficationKeyText = serialiseToBech32Cip129 . anyCommitteeColdVerificationKeyToCredential
50+
51+
anyCommitteeColdVerificationKeyToCredential
52+
:: AnyCommitteeColdVerificationKey -> L.Credential L.ColdCommitteeRole
53+
anyCommitteeColdVerificationKeyToCredential committeeColdKey =
54+
case committeeColdKey of
55+
AnyCommitteeColdVerificationKey vk ->
56+
let CommitteeColdKeyHash hash = verificationKeyHash vk
57+
in L.KeyHashObj hash
58+
AnyCommitteeColdExtendedVerificationKey vk ->
59+
let CommitteeColdExtendedKeyHash hash = verificationKeyHash vk
60+
in L.KeyHashObj hash
61+
62+
encodeCip129GovernanceActionIdText :: L.GovActionId -> Text
63+
encodeCip129GovernanceActionIdText = serialiseGovActionIdToBech32Cip129

0 commit comments

Comments
 (0)