Skip to content

Incorporate CIP-129 #1087

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions cardano-cli/cardano-cli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@ library
Cardano.CLI.EraIndependent.Address.Info.Run
Cardano.CLI.EraIndependent.Address.Option
Cardano.CLI.EraIndependent.Address.Run
Cardano.CLI.EraIndependent.Cip.Cip129.Command
Cardano.CLI.EraIndependent.Cip.Cip129.Internal.Conversion
Cardano.CLI.EraIndependent.Cip.Cip129.Option
Cardano.CLI.EraIndependent.Cip.Cip129.Run
Cardano.CLI.EraIndependent.Cip.Command
Cardano.CLI.EraIndependent.Cip.Common
Cardano.CLI.EraIndependent.Cip.Option
Cardano.CLI.EraIndependent.Cip.Run
Cardano.CLI.EraIndependent.Debug.CheckNodeConfiguration.Command
Cardano.CLI.EraIndependent.Debug.CheckNodeConfiguration.Run
Cardano.CLI.EraIndependent.Debug.Command
Expand Down Expand Up @@ -177,6 +185,10 @@ library
Cardano.CLI.Orphan
Cardano.CLI.Parser
Cardano.CLI.Read
Cardano.CLI.Read.Committee.ColdKey
Cardano.CLI.Read.Committee.HotKey
Cardano.CLI.Read.DRep
Cardano.CLI.Read.GovernanceActionId
Cardano.CLI.Render
Cardano.CLI.Run
Cardano.CLI.Run.Mnemonic
Expand Down Expand Up @@ -280,6 +292,7 @@ library
transformers-except ^>=0.1.3,
unliftio-core,
utf8-string,
validation,
vary ^>=0.1.1.2,
vector,
yaml,
Expand Down
3 changes: 3 additions & 0 deletions cardano-cli/src/Cardano/CLI/Command.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Cardano.CLI.Compatible.Command
import Cardano.CLI.EraBased.Command
import Cardano.CLI.EraBased.Query.Command
import Cardano.CLI.EraIndependent.Address.Command
import Cardano.CLI.EraIndependent.Cip.Command (CipFormatCmds)
import Cardano.CLI.EraIndependent.Debug.Command
import Cardano.CLI.EraIndependent.Hash.Command (HashCmds)
import Cardano.CLI.EraIndependent.Key.Command
Expand Down Expand Up @@ -37,6 +38,8 @@ data ClientCommand
forall era. QueryCommands (QueryCmds era)
| -- | Legacy shelley-based Commands
LegacyCmds LegacyCmds
| -- | Miscellaneous commands
CipFormatCmds CipFormatCmds
| CliPingCommand PingCmd
| CliDebugCmds DebugCmds
| forall a. Help ParserPrefs (ParserInfo a)
Expand Down
8 changes: 7 additions & 1 deletion cardano-cli/src/Cardano/CLI/EraBased/Common/Option.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1852,11 +1852,17 @@ flagFormatCborBin
flagFormatCborBin =
mkFlag "output-cbor-bin" "CBOR" FormatCborBin

flagFormatCip129
:: FormatCip129 :| fs
=> Flag (Vary fs)
flagFormatCip129 =
mkFlag "output-cip129" "CIP-129" FormatCip129

flagFormatHex
:: FormatHex :| fs
=> Flag (Vary fs)
flagFormatHex =
mkFlag "output-hex" "HEX" FormatHex
mkFlag "output-hex" "BASE16" FormatHex

flagFormatJson
:: FormatJson :| fs
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}

module Cardano.CLI.EraBased.Governance.DRep.Command
Expand Down Expand Up @@ -44,7 +45,7 @@ data GovernanceDRepIdCmdArgs era
= GovernanceDRepIdCmdArgs
{ eon :: !(ConwayEraOnwards era)
, vkeySource :: !(VerificationKeyOrHashOrFile DRepKey)
, idOutputFormat :: !(Vary [FormatBech32, FormatHex])
, idOutputFormat :: !(Vary [FormatBech32, FormatHex, FormatCip129])
, mOutFile :: !(Maybe (File () Out))
}

Expand Down
27 changes: 8 additions & 19 deletions cardano-cli/src/Cardano/CLI/EraBased/Governance/DRep/Option.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ import Cardano.Api.Shelley (Hash (DRepMetadataHash))
import Cardano.CLI.EraBased.Common.Option
import Cardano.CLI.EraBased.Governance.DRep.Command
import Cardano.CLI.EraIndependent.Hash.Command (HashGoal (..))
import Cardano.CLI.Option.Flag
import Cardano.CLI.Parser
import Cardano.CLI.Read
import Cardano.CLI.Type.Common hiding (CheckHash)

import Control.Applicative (Alternative ((<|>)), optional)
import Data.Foldable (asum)
import Data.Function
import Options.Applicative (Parser)
import Options.Applicative qualified as Opt
import Vary

pGovernanceDRepCmds
:: ()
Expand Down Expand Up @@ -74,27 +74,16 @@ pGovernanceDRepKeyIdCmd era = do
( fmap GovernanceDRepIdCmd $
GovernanceDRepIdCmdArgs w
<$> pDRepVerificationKeyOrHashOrFile
<*> pDRepIdOutputFormat
<*> pFormatFlags
"drep id output"
[ flagFormatHex
, flagFormatBech32 & setDefault
, flagFormatCip129
]
<*> optional pOutputFile
)
$ Opt.progDesc "Generate a drep id."

pDRepIdOutputFormat :: Parser (Vary [FormatBech32, FormatHex])
pDRepIdOutputFormat =
asum [make (Vary.from FormatHex) "hex", make (Vary.from FormatBech32) "bech32"]
<|> pure default_
where
default_ = Vary.from FormatBech32
make format flag_ =
Opt.flag' format $
mconcat
[ Opt.help $
"Format drep id output as "
<> flag_
<> (if format == default_ then " (the default)." else ".")
, Opt.long ("output-" <> flag_)
]

-- Registration Certificate related

pRegistrationCertificateCmd
Expand Down
7 changes: 7 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Governance/DRep/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ where

import Cardano.Api
import Cardano.Api.Ledger qualified as L
import Cardano.Api.Shelley

import Cardano.CLI.Compatible.Exception
import Cardano.CLI.EraBased.Governance.DRep.Command qualified as Cmd
Expand Down Expand Up @@ -99,6 +100,12 @@ runGovernanceDRepIdCmd
( \FormatHex ->
serialiseToRawBytesHex drepVerKeyHash
)
. Vary.on
( \FormatCip129 ->
let DRepKeyHash kh = drepVerKeyHash
keyCredential = L.KeyHashObj kh
in Text.encodeUtf8 $ serialiseToBech32Cip129 keyCredential
)
$ Vary.exhaustiveCase
)

Expand Down
4 changes: 2 additions & 2 deletions cardano-cli/src/Cardano/CLI/EraBased/Query/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ where
import Cardano.Api hiding (QueryInShelleyBasedEra (..))
import Cardano.Api qualified as Api
import Cardano.Api.Consensus qualified as Consensus
import Cardano.Api.Ledger (StandardCrypto, strictMaybeToMaybe)
import Cardano.Api.Ledger (strictMaybeToMaybe)
import Cardano.Api.Ledger qualified as L
import Cardano.Api.Network (LedgerPeerSnapshot, Serialised (..))
import Cardano.Api.Network qualified as Consensus
Expand Down Expand Up @@ -1224,7 +1224,7 @@ writePoolState outputFormat mOutFile serialisedCurrentEpochState = do
<> Map.keysSet (L.psFutureStakePoolParams poolState)
<> Map.keysSet (L.psRetiring poolState)

let poolStates :: Map (L.KeyHash 'L.StakePool) (Params StandardCrypto)
let poolStates :: Map (L.KeyHash 'L.StakePool) Params
poolStates =
fromList $
hks
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module Cardano.CLI.EraIndependent.Cip.Cip129.Command
( Cip129 (..)
, renderCip129Command
)
where

import Cardano.CLI.EraIndependent.Cip.Common

import Data.Text (Text)

data Cip129
= Cip129DRep Input Output
| Cip129CommitteeHotKey Input Output
| Cip129CommitteeColdKey Input Output
| Cip129GovernanceAction Input Output

renderCip129Command :: Cip129 -> Text
renderCip129Command (Cip129DRep{}) = "cip-129 drep"
renderCip129Command (Cip129CommitteeHotKey{}) = "cip-129 committee-hot-key"
renderCip129Command (Cip129CommitteeColdKey{}) = "cip-129 committee-cold-key"
renderCip129Command (Cip129GovernanceAction{}) = "cip-129 governance-action-id"
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{-# LANGUAGE DataKinds #-}

module Cardano.CLI.EraIndependent.Cip.Cip129.Internal.Conversion
( encodeCip129DrepVerficationKeyText
, encodeCip129CommitteeColdVerficationKeyText
, encodeCip129CommitteeHotVerficationKeyText
, encodeCip129GovernanceActionIdText
)
where

import Cardano.Api.Ledger qualified as L
import Cardano.Api.Shelley

import Cardano.CLI.Read.Committee.ColdKey
import Cardano.CLI.Read.Committee.HotKey
import Cardano.CLI.Read.DRep

import Data.Text

encodeCip129DrepVerficationKeyText :: AnyDrepVerificationKey -> Text
encodeCip129DrepVerficationKeyText = serialiseToBech32Cip129 . anyDrepVerificationKeyToCredential

anyDrepVerificationKeyToCredential
:: AnyDrepVerificationKey -> L.Credential L.DRepRole
anyDrepVerificationKeyToCredential drepKey =
case drepKey of
AnyDrepVerificationKey vk ->
let DRepKeyHash hash = verificationKeyHash vk
in L.KeyHashObj hash
AnyDrepExtendedVerificationKey vk ->
let DRepExtendedKeyHash hash = verificationKeyHash vk
in L.KeyHashObj hash

encodeCip129CommitteeHotVerficationKeyText :: AnyCommitteeHotVerificationKey -> Text
encodeCip129CommitteeHotVerficationKeyText = serialiseToBech32Cip129 . anyCommitteeHotVerificationKeyToCredential

anyCommitteeHotVerificationKeyToCredential
:: AnyCommitteeHotVerificationKey -> L.Credential L.HotCommitteeRole
anyCommitteeHotVerificationKeyToCredential committeeHotKey =
case committeeHotKey of
AnyCommitteeHotVerificationKey vk ->
let CommitteeHotKeyHash hash = verificationKeyHash vk
in L.KeyHashObj hash
AnyCommitteeHotExtendedVerificationKey vk ->
let CommitteeHotExtendedKeyHash hash = verificationKeyHash vk
in L.KeyHashObj hash

encodeCip129CommitteeColdVerficationKeyText :: AnyCommitteeColdVerificationKey -> Text
encodeCip129CommitteeColdVerficationKeyText = serialiseToBech32Cip129 . anyCommitteeColdVerificationKeyToCredential

anyCommitteeColdVerificationKeyToCredential
:: AnyCommitteeColdVerificationKey -> L.Credential L.ColdCommitteeRole
anyCommitteeColdVerificationKeyToCredential committeeColdKey =
case committeeColdKey of
AnyCommitteeColdVerificationKey vk ->
let CommitteeColdKeyHash hash = verificationKeyHash vk
in L.KeyHashObj hash
AnyCommitteeColdExtendedVerificationKey vk ->
let CommitteeColdExtendedKeyHash hash = verificationKeyHash vk
in L.KeyHashObj hash

encodeCip129GovernanceActionIdText :: L.GovActionId -> Text
encodeCip129GovernanceActionIdText = serialiseGovActionIdToBech32Cip129
93 changes: 93 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraIndependent/Cip/Cip129/Option.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
module Cardano.CLI.EraIndependent.Cip.Cip129.Option
( pCip129
)
where

import Cardano.CLI.EraIndependent.Cip.Command
import Cardano.CLI.EraIndependent.Cip.Common
import Cardano.CLI.Parser

import Data.Foldable
import Options.Applicative qualified as Opt

-- Add sub parsers
pCip129 :: Opt.Parser CipFormatCmds
pCip129 =
Cip129
<$> asum
[ Opt.hsubparser $
commandWithMetavar "drep" $
Opt.info pCip129Drep $
Opt.progDesc "Convert drep verification key to the cip-129 compliant format"
, Opt.hsubparser $
commandWithMetavar "committee-hot-key" $
Opt.info pCip129CommitteeHotKey $
Opt.progDesc "Convert committee hot key to the cip-129 compliant format"
, Opt.hsubparser $
commandWithMetavar "committee-cold-key" $
Opt.info pCip129CommitteeColdKey $
Opt.progDesc "Convert committee cold key to the cip-129 compliant format"
, Opt.hsubparser $
commandWithMetavar "governance-action-id" $
Opt.info pCip129GovernanceAction $
Opt.progDesc "Convert governance action id to the cip-129 compliant format"
]

pCip129Drep :: Opt.Parser Cip129
pCip129Drep =
Cip129DRep
<$> pInput
<*> pOutput
where
pInput =
asum
[ pInputFile "drep-file" "Input hex/bech32/text envelope drep file"
, pInputHexText "drep-hex" "HEX" "Input hex encoded drep"
, pInputBech32Text "drep-bech32" "BECH32" "Input bech32 encoded drep"
]

pCip129CommitteeHotKey :: Opt.Parser Cip129
pCip129CommitteeHotKey =
Cip129CommitteeHotKey
<$> pInput
<*> pOutput
where
pInput =
asum
[ pInputFile "committee-hot-key-file" "Input hex/bech32/text envelope committee hot key file"
, pInputHexText "committee-hot-key-hex" "HEX" "Input hex encoded committee hot key"
, pInputBech32Text "committee-hot-key-bech32" "BECH32" "Input bech32 encoded committee hot key"
]

pCip129CommitteeColdKey :: Opt.Parser Cip129
pCip129CommitteeColdKey =
Cip129CommitteeColdKey
<$> pInput
<*> pOutput
where
pInput =
asum
[ pInputFile "committee-cold-key-file" "Input hex/bech32/text envelope committee cold key file"
, pInputHexText "committee-cold-key-hex" "HEX" "Input hex encoded committee cold key"
, pInputBech32Text "committee-cold-key-bech32" "BECH32" "Input bech32 encoded committee cold key"
]

pCip129GovernanceAction :: Opt.Parser Cip129
pCip129GovernanceAction =
Cip129GovernanceAction
<$> pInput
<*> pOutput
where
pInput =
asum
[ pInputFile "governance-action-file" "Input hex/bech32/text envelope governance action file"
, pInputHexText "governance-action-hex" "HEX" "Input hex encoded governance action"
, pInputBech32Text "governance-action-bech32" "BECH32" "Input bech32 encoded governance action"
]

pOutput :: Opt.Parser Output
pOutput =
asum
[ pOutputFile "output-file" "Output file"
, pOutputText "output-text" "Output text"
]
Loading
Loading