Skip to content

Commit 359074e

Browse files
authored
Merge pull request #1087 from IntersectMBO/jordan/cip-129
Incorporate CIP-129
2 parents 9b851c5 + 8f29e3b commit 359074e

37 files changed

+878
-41
lines changed

cardano-cli/cardano-cli.cabal

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,14 @@ library
137137
Cardano.CLI.EraIndependent.Address.Info.Run
138138
Cardano.CLI.EraIndependent.Address.Option
139139
Cardano.CLI.EraIndependent.Address.Run
140+
Cardano.CLI.EraIndependent.Cip.Cip129.Command
141+
Cardano.CLI.EraIndependent.Cip.Cip129.Internal.Conversion
142+
Cardano.CLI.EraIndependent.Cip.Cip129.Option
143+
Cardano.CLI.EraIndependent.Cip.Cip129.Run
144+
Cardano.CLI.EraIndependent.Cip.Command
145+
Cardano.CLI.EraIndependent.Cip.Common
146+
Cardano.CLI.EraIndependent.Cip.Option
147+
Cardano.CLI.EraIndependent.Cip.Run
140148
Cardano.CLI.EraIndependent.Debug.CheckNodeConfiguration.Command
141149
Cardano.CLI.EraIndependent.Debug.CheckNodeConfiguration.Run
142150
Cardano.CLI.EraIndependent.Debug.Command
@@ -177,6 +185,10 @@ library
177185
Cardano.CLI.Orphan
178186
Cardano.CLI.Parser
179187
Cardano.CLI.Read
188+
Cardano.CLI.Read.Committee.ColdKey
189+
Cardano.CLI.Read.Committee.HotKey
190+
Cardano.CLI.Read.DRep
191+
Cardano.CLI.Read.GovernanceActionId
180192
Cardano.CLI.Render
181193
Cardano.CLI.Run
182194
Cardano.CLI.Run.Mnemonic
@@ -280,6 +292,7 @@ library
280292
transformers-except ^>=0.1.3,
281293
unliftio-core,
282294
utf8-string,
295+
validation,
283296
vary ^>=0.1.1.2,
284297
vector,
285298
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: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1852,11 +1852,17 @@ flagFormatCborBin
18521852
flagFormatCborBin =
18531853
mkFlag "output-cbor-bin" "CBOR" FormatCborBin
18541854

1855+
flagFormatCip129
1856+
:: FormatCip129 :| fs
1857+
=> Flag (Vary fs)
1858+
flagFormatCip129 =
1859+
mkFlag "output-cip129" "CIP-129" FormatCip129
1860+
18551861
flagFormatHex
18561862
:: FormatHex :| fs
18571863
=> Flag (Vary fs)
18581864
flagFormatHex =
1859-
mkFlag "output-hex" "HEX" FormatHex
1865+
mkFlag "output-hex" "BASE16" FormatHex
18601866

18611867
flagFormatJson
18621868
:: FormatJson :| fs

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

Lines changed: 2 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
@@ -44,7 +45,7 @@ data GovernanceDRepIdCmdArgs era
4445
= GovernanceDRepIdCmdArgs
4546
{ eon :: !(ConwayEraOnwards era)
4647
, vkeySource :: !(VerificationKeyOrHashOrFile DRepKey)
47-
, idOutputFormat :: !(Vary [FormatBech32, FormatHex])
48+
, idOutputFormat :: !(Vary [FormatBech32, FormatHex, FormatCip129])
4849
, mOutFile :: !(Maybe (File () Out))
4950
}
5051

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

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ 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
25-
import Vary
2626

2727
pGovernanceDRepCmds
2828
:: ()
@@ -74,27 +74,16 @@ pGovernanceDRepKeyIdCmd era = do
7474
( fmap GovernanceDRepIdCmd $
7575
GovernanceDRepIdCmdArgs w
7676
<$> pDRepVerificationKeyOrHashOrFile
77-
<*> pDRepIdOutputFormat
77+
<*> pFormatFlags
78+
"drep id output"
79+
[ flagFormatHex
80+
, flagFormatBech32 & setDefault
81+
, flagFormatCip129
82+
]
7883
<*> optional pOutputFile
7984
)
8085
$ Opt.progDesc "Generate a drep id."
8186

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

10089
pRegistrationCertificateCmd

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ where
1919

2020
import Cardano.Api
2121
import Cardano.Api.Ledger qualified as L
22+
import Cardano.Api.Shelley
2223

2324
import Cardano.CLI.Compatible.Exception
2425
import Cardano.CLI.EraBased.Governance.DRep.Command qualified as Cmd
@@ -99,6 +100,12 @@ runGovernanceDRepIdCmd
99100
( \FormatHex ->
100101
serialiseToRawBytesHex drepVerKeyHash
101102
)
103+
. Vary.on
104+
( \FormatCip129 ->
105+
let DRepKeyHash kh = drepVerKeyHash
106+
keyCredential = L.KeyHashObj kh
107+
in Text.encodeUtf8 $ serialiseToBech32Cip129 keyCredential
108+
)
102109
$ Vary.exhaustiveCase
103110
)
104111

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
@@ -1222,7 +1222,7 @@ writePoolState outputFormat mOutFile serialisedCurrentEpochState = do
12221222
<> Map.keysSet (L.psFutureStakePoolParams poolState)
12231223
<> Map.keysSet (L.psRetiring poolState)
12241224

1225-
let poolStates :: Map (L.KeyHash 'L.StakePool) (Params StandardCrypto)
1225+
let poolStates :: Map (L.KeyHash 'L.StakePool) Params
12261226
poolStates =
12271227
fromList $
12281228
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.Internal.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
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
module Cardano.CLI.EraIndependent.Cip.Cip129.Option
2+
( pCip129
3+
)
4+
where
5+
6+
import Cardano.CLI.EraIndependent.Cip.Command
7+
import Cardano.CLI.EraIndependent.Cip.Common
8+
import Cardano.CLI.Parser
9+
10+
import Data.Foldable
11+
import Options.Applicative qualified as Opt
12+
13+
-- Add sub parsers
14+
pCip129 :: Opt.Parser CipFormatCmds
15+
pCip129 =
16+
Cip129
17+
<$> asum
18+
[ Opt.hsubparser $
19+
commandWithMetavar "drep" $
20+
Opt.info pCip129Drep $
21+
Opt.progDesc "Convert drep verification key to the cip-129 compliant format"
22+
, Opt.hsubparser $
23+
commandWithMetavar "committee-hot-key" $
24+
Opt.info pCip129CommitteeHotKey $
25+
Opt.progDesc "Convert committee hot key to the cip-129 compliant format"
26+
, Opt.hsubparser $
27+
commandWithMetavar "committee-cold-key" $
28+
Opt.info pCip129CommitteeColdKey $
29+
Opt.progDesc "Convert committee cold key to the cip-129 compliant format"
30+
, Opt.hsubparser $
31+
commandWithMetavar "governance-action-id" $
32+
Opt.info pCip129GovernanceAction $
33+
Opt.progDesc "Convert governance action id to the cip-129 compliant format"
34+
]
35+
36+
pCip129Drep :: Opt.Parser Cip129
37+
pCip129Drep =
38+
Cip129DRep
39+
<$> pInput
40+
<*> pOutput
41+
where
42+
pInput =
43+
asum
44+
[ pInputFile "drep-file" "Input hex/bech32/text envelope drep file"
45+
, pInputHexText "drep-hex" "HEX" "Input hex encoded drep"
46+
, pInputBech32Text "drep-bech32" "BECH32" "Input bech32 encoded drep"
47+
]
48+
49+
pCip129CommitteeHotKey :: Opt.Parser Cip129
50+
pCip129CommitteeHotKey =
51+
Cip129CommitteeHotKey
52+
<$> pInput
53+
<*> pOutput
54+
where
55+
pInput =
56+
asum
57+
[ pInputFile "committee-hot-key-file" "Input hex/bech32/text envelope committee hot key file"
58+
, pInputHexText "committee-hot-key-hex" "HEX" "Input hex encoded committee hot key"
59+
, pInputBech32Text "committee-hot-key-bech32" "BECH32" "Input bech32 encoded committee hot key"
60+
]
61+
62+
pCip129CommitteeColdKey :: Opt.Parser Cip129
63+
pCip129CommitteeColdKey =
64+
Cip129CommitteeColdKey
65+
<$> pInput
66+
<*> pOutput
67+
where
68+
pInput =
69+
asum
70+
[ pInputFile "committee-cold-key-file" "Input hex/bech32/text envelope committee cold key file"
71+
, pInputHexText "committee-cold-key-hex" "HEX" "Input hex encoded committee cold key"
72+
, pInputBech32Text "committee-cold-key-bech32" "BECH32" "Input bech32 encoded committee cold key"
73+
]
74+
75+
pCip129GovernanceAction :: Opt.Parser Cip129
76+
pCip129GovernanceAction =
77+
Cip129GovernanceAction
78+
<$> pInput
79+
<*> pOutput
80+
where
81+
pInput =
82+
asum
83+
[ pInputFile "governance-action-file" "Input hex/bech32/text envelope governance action file"
84+
, pInputHexText "governance-action-hex" "HEX" "Input hex encoded governance action"
85+
, pInputBech32Text "governance-action-bech32" "BECH32" "Input bech32 encoded governance action"
86+
]
87+
88+
pOutput :: Opt.Parser Output
89+
pOutput =
90+
asum
91+
[ pOutputFile "output-file" "Output file"
92+
, pOutputText "output-text" "Output text"
93+
]

0 commit comments

Comments
 (0)