Skip to content
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
12 changes: 6 additions & 6 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ repository cardano-haskell-packages
-- See CONTRIBUTING for information about these, including some Nix commands
-- you need to run if you change them
index-state:
, hackage.haskell.org 2025-09-10T10:05:13Z
, cardano-haskell-packages 2025-09-15T19:20:34Z
, hackage.haskell.org 2025-09-24T20:00:55Z
, cardano-haskell-packages 2025-10-23T12:06:55Z

packages:
cardano-cli
Expand Down Expand Up @@ -58,11 +58,11 @@ semaphore: True
-- Always write GHC env files, because they are needed for ghci.
write-ghc-environment-files: always

-- IMPORTANT
-- Do NOT add more source-repository-package stanzas here unless they are strictly
-- temporary! Please read the section in CONTRIBUTING about updating dependencies.

if impl (ghc >= 9.12)
allow-newer:
-- https://github.com/kapralVV/Unique/issues/11
, Unique:hashable

-- IMPORTANT
-- Do NOT add more source-repository-package stanzas here unless they are strictly
-- temporary! Please read the section in CONTRIBUTING about updating dependencies.
10 changes: 7 additions & 3 deletions cardano-cli/cardano-cli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ library
binary,
bytestring,
canonical-json,
cardano-api ^>=10.18,
cardano-api ^>=10.19,
cardano-binary,
cardano-crypto,
cardano-crypto-class ^>=2.2,
Expand All @@ -251,7 +251,8 @@ library
cardano-ledger-api,
cardano-ledger-conway,
cardano-ledger-core,
cardano-ping ^>=0.8,
cardano-ledger-dijkstra,
cardano-ping ^>=0.9,
cardano-prelude,
cardano-protocol-tpraos,
cardano-slotting ^>=0.2.0.0,
Expand All @@ -271,19 +272,22 @@ library
http-client-tls,
http-types,
io-classes,
io-classes:strict-stm,
iproute,
microlens,
mmorph,
mtl,
network,
network-uri,
optparse-applicative-fork,
ouroboros-consensus,
ouroboros-consensus-cardano,
prettyprinter,
prettyprinter-ansi-terminal,
random,
rio,
sop-extras,
split,
strict-stm,
text,
time,
transformers,
Expand Down
3 changes: 3 additions & 0 deletions cardano-cli/src/Cardano/CLI/Compatible/Governance/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ runCompatibleGovernanceActionCreateProtocolParametersUpdateCmd eraBasedPParams'
ShelleyBasedEraBabbage ->
shelleyToBabbageProtocolParametersUpdate sbe eraBasedPParams'
ShelleyBasedEraConway -> conwayProtocolParametersUpdate sbe eraBasedPParams'
ShelleyBasedEraDijkstra ->
-- TODO: Dijkstra
error "runCompatibleGovernanceActionCreateProtocolParametersUpdateCmd: Dijkstra not supported yet"

maybeAddUpdatedCostModel
:: GovernanceActionProtocolParametersUpdateCmdArgs era
Expand Down
26 changes: 23 additions & 3 deletions cardano-cli/src/Cardano/CLI/Compatible/Json/Friendly.hs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ data EraIndependentPlutusScriptPurpose
| Rewarding
| Voting
| Proposing
| Guarding

getScriptWitnessDetails
:: forall era. Exp.Era era -> TxBody era -> [Aeson.Pair]
Expand Down Expand Up @@ -341,20 +342,35 @@ getScriptWitnessDetails era tb =
Ledger.ConwayRewarding (L.AsIxItem _ rp) -> addLabelToPurpose Rewarding rp
Ledger.ConwayVoting (L.AsIxItem _ vp) -> addLabelToPurpose Voting vp
Ledger.ConwayProposing (L.AsIxItem _ pp) -> addLabelToPurpose Proposing pp

friendlyPurpose AlonzoEraOnwardsDijkstra purpose = do
let era' = fromJust $ forEraMaybeEon (convert era)
obtainCommonConstraints era' $
case purpose of
Ledger.DijkstraSpending (L.AsIxItem _ sp) -> addLabelToPurpose Spending (friendlyInput sp)
Ledger.DijkstraMinting (L.AsIxItem _ mp) -> addLabelToPurpose Minting mp
Ledger.DijkstraCertifying (L.AsIxItem _ cp) -> addLabelToPurpose Certifying cp
Ledger.DijkstraRewarding (L.AsIxItem _ rp) -> addLabelToPurpose Rewarding rp
Ledger.DijkstraVoting (L.AsIxItem _ vp) -> addLabelToPurpose Voting vp
Ledger.DijkstraProposing (L.AsIxItem _ pp) -> addLabelToPurpose Proposing pp
Ledger.DijkstraGuarding (L.AsIxItem _ pp) -> addLabelToPurpose Guarding pp
friendlyInput :: Ledger.TxIn -> Aeson.Value
friendlyInput (Ledger.TxIn (Ledger.TxId txidHash) ix) =
Aeson.String $
T.pack $
T.unpack (hashToTextAsHex (extractHash txidHash)) ++ "#" ++ show (Ledger.txIxToInt ix)

addLabelToPurpose :: ToJSON v => EraIndependentPlutusScriptPurpose -> v -> Aeson.Value
addLabelToPurpose
:: ToJSON v
=> EraIndependentPlutusScriptPurpose
-> v
-> Aeson.Value
addLabelToPurpose Spending sp = Aeson.object ["spending script witnessed input" .= sp]
addLabelToPurpose Minting mp = Aeson.object ["minting currency with policy id" .= mp]
addLabelToPurpose Certifying cp = Aeson.object ["validating certificate with script credentials" .= cp]
addLabelToPurpose Rewarding rp = Aeson.object ["withdrawing reward from script address" .= rp]
addLabelToPurpose Voting vp = Aeson.object ["voting using script protected voter credentials" .= vp]
addLabelToPurpose Proposing pp = Aeson.object ["submitting a proposal following proposal policy" .= pp]
addLabelToPurpose Guarding _ = error "TODO Dijkstra"

friendlyScriptData :: Ledger.Tx (ShelleyLedgerEra era) -> Aeson.Value
friendlyScriptData tx =
Expand Down Expand Up @@ -638,7 +654,7 @@ renderCertificate sbe = \case
[ "pot" .= friendlyMirPot pot
, friendlyMirTarget sbe target
]
ConwayCertificate w cert ->
ConwayCertificate w@ConwayEraOnwardsConway (cert :: L.ConwayTxCert (ShelleyLedgerEra ConwayEra)) ->
conwayEraOnwardsConstraints w $
case cert of
L.RegDRepTxCert credential coin mAnchor ->
Expand Down Expand Up @@ -734,6 +750,10 @@ renderCertificate sbe = \case
[ "Drep credential" .= drepCredential
, "anchor " .= mbAnchor
]
-- TODO Dijkstra: What's missing here?
_ -> error "renderCertificate: TODO Dijkstra impossible"
ConwayCertificate ConwayEraOnwardsDijkstra _ ->
error "renderCertificate: TODO Dijkstra era not supported"
where
conwayToObject
:: ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ pTxOutDatum =
AlonzoEraOnwardsBabbage ->
pBabbageDatumFunctionality <|> pure TxOutDatumByNone
AlonzoEraOnwardsConway -> pConwayDatumFunctionality <|> pure TxOutDatumByNone
AlonzoEraOnwardsDijkstra -> pConwayDatumFunctionality <|> pure TxOutDatumByNone
)
where
pAlonzoDatumFunctionality =
Expand Down
25 changes: 12 additions & 13 deletions cardano-cli/src/Cardano/CLI/Environment.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}

-- | This module defines constants derived from the environment.
Expand All @@ -16,9 +17,11 @@ import Cardano.Api
, CardanoEra (..)
, NetworkId (..)
, NetworkMagic (..)
, forEraMaybeEon
)
import Cardano.Api.Experimental qualified as Exp

import Data.Type.Equality
import Data.Word (Word32)
import System.Environment qualified as IO
import System.IO qualified as IO
Expand All @@ -43,20 +46,16 @@ getEnvCli = do
, envCliAnyCardanoEra = mCardanoEra
}

anyCardanoEraToEra :: AnyCardanoEra -> Maybe (Exp.Era Exp.ConwayEra)
anyCardanoEraToEra (AnyCardanoEra era) =
case era of
ByronEra -> Nothing
ShelleyEra -> Nothing
AllegraEra -> Nothing
MaryEra -> Nothing
AlonzoEra -> Nothing
BabbageEra -> Nothing
ConwayEra -> Just Exp.ConwayEra

envCliEra :: EnvCli -> Maybe (Exp.Era Exp.ConwayEra)
envCliEra
:: forall era
. Exp.IsEra era
=> EnvCli
-> Maybe (Exp.Era era)
envCliEra envCli = do
anyCardanoEraToEra =<< envCliAnyCardanoEra envCli
AnyCardanoEra cardanoEra <- envCliAnyCardanoEra envCli
era1 <- forEraMaybeEon cardanoEra
Refl <- testEquality era1 (Exp.useEra @era)
pure era1

-- | If the environment variable @CARDANO_NODE_NETWORK_ID@ is set, then return the network id therein.
-- Otherwise, return 'Nothing'.
Expand Down
25 changes: 18 additions & 7 deletions cardano-cli/src/Cardano/CLI/EraBased/Common/Option.hs
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,25 @@ bounded t = Opt.eitherReader $ \s -> do
when (i > fromIntegral (maxBound @a)) $ Left $ t <> " must not greater than " <> show (maxBound @a)
pure (fromIntegral i)

parseFilePath :: String -> String -> Parser FilePath
parseFilePath optname desc =
parseFilePathWithMod
:: String
-- ^ option name
-> String
-- ^ description
-> Mod OptionFields FilePath
-> Parser FilePath
parseFilePathWithMod optname desc mod' =
Opt.strOption
( Opt.long optname
<> Opt.metavar "FILEPATH"
<> Opt.help desc
<> Opt.completer (Opt.bashCompleter "file")
)
. mconcat
$ [ Opt.long optname
, Opt.metavar "FILEPATH"
, Opt.help desc
, Opt.completer (Opt.bashCompleter "file")
, mod'
]

parseFilePath :: String -> String -> Parser FilePath
parseFilePath optname desc = parseFilePathWithMod optname desc mempty

pNetworkIdDeprecated :: Parser NetworkId
pNetworkIdDeprecated =
Expand Down
2 changes: 2 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Genesis/Command.hs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ data GenesisCreateTestNetDataCmdArgs = forall era. GenesisCreateTestNetDataCmdAr
-- ^ Path to the @genesis-alonzo@ file to use. If unspecified, a default one will be used.
, specConway :: !(Maybe FilePath)
-- ^ Path to the @genesis-conway@ file to use. If unspecified, a default one will be used.
, specDijkstra :: !(Maybe FilePath)
-- ^ Path to the @genesis-dijkstra@ file to use. If unspecified, a default one will be used.
, numGenesisKeys :: !Word
-- ^ The number of genesis keys credentials to create and write to disk.
, numPools :: !Word
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,16 @@ import Cardano.Crypto.Hash qualified as Crypto
import Cardano.Prelude (canonicalEncodePretty)
import Cardano.Protocol.Crypto qualified as C

import RIO (throwString)

import Control.DeepSeq (NFData, deepseq)
import Control.Monad (forM, forM_, unless, void, when)
import Control.Monad (forM, forM_, unless, when)
import Data.Aeson.Encode.Pretty qualified as Aeson
import Data.Bifunctor (Bifunctor (..))
import Data.ByteString (ByteString)
import Data.ByteString.Char8 qualified as BS
import Data.ByteString.Lazy.Char8 qualified as LBS
import Data.Function ((&))
import Data.Functor
import Data.Functor.Identity (Identity)
import Data.ListMap (ListMap (..))
import Data.Map.Strict (Map)
Expand All @@ -81,6 +83,7 @@ import Data.Word (Word64)
import GHC.Exts (IsList (..))
import GHC.Generics (Generic)
import GHC.Num (Natural)
import GHC.Stack
import Lens.Micro ((^.))
import System.Directory
import System.FilePath ((</>))
Expand Down Expand Up @@ -218,6 +221,7 @@ runGenesisCreateTestNetDataCmd
, specShelley
, specAlonzo
, specConway
, specDijkstra
, numGenesisKeys
, numPools
, stakeDelegators =
Expand All @@ -240,15 +244,17 @@ runGenesisCreateTestNetDataCmd
, outputDir
} = do
liftIO $ createDirectoryIfMissing False outputDir
let era = convert eon
shelleyGenesisInit <-
fromMaybe shelleyGenesisDefaults
<$> traverse (fromExceptTCli . decodeShelleyGenesisFile) specShelley
alonzoGenesis <-
fromMaybe (alonzoGenesisDefaults era)
<$> traverse (fromExceptTCli . decodeAlonzoGenesisFile (Just era)) specAlonzo
fromMaybe alonzoGenesisDefaults
<$> traverse (fromExceptTCli . decodeAlonzoGenesisFile) specAlonzo
conwayGenesis <-
fromMaybe conwayGenesisDefaults <$> fromExceptTCli (traverse decodeConwayGenesisFile specConway)
dijkstraGenesis <-
fromMaybe dijkstraGenesisDefaults
<$> fromExceptTCli (traverse decodeDijkstraGenesisFile specDijkstra)

-- Read NetworkId either from file or from the flag. Flag overrides template file.
let actualNetworkId =
Expand Down Expand Up @@ -372,9 +378,9 @@ runGenesisCreateTestNetDataCmd
stuffedUtxoAddrs <-
liftIO $ Lazy.replicateM (fromIntegral numStuffedUtxo) $ genStuffedAddress network

let conwayGenesis' =
addDRepsToConwayGenesis dRepKeys (map snd delegatorKeys) conwayGenesis
& addCommitteeToConwayGenesis ccColdKeys
conwayGenesis' <-
addDRepsToConwayGenesis dRepKeys (map snd delegatorKeys) conwayGenesis
<&> addCommitteeToConwayGenesis ccColdKeys

let stake = second L.ppId . mkDelegationMapEntry <$> delegations
stakePools = [(L.ppId poolParams', poolParams') | poolParams' <- snd . mkDelegationMapEntry <$> delegations]
Expand Down Expand Up @@ -424,9 +430,10 @@ runGenesisCreateTestNetDataCmd
-- 2. Users of cardano-testnet may use them

forM_
[ ("conway-genesis.json", WritePretty conwayGenesis')
, ("shelley-genesis.json", WritePretty shelleyGenesis')
[ ("shelley-genesis.json", WritePretty shelleyGenesis')
, ("alonzo-genesis.json", WritePretty alonzoGenesis)
, ("conway-genesis.json", WritePretty conwayGenesis')
, ("dijkstra-genesis.json", WritePretty dijkstraGenesis)
]
$ \(filename, genesis) -> fromExceptTCli $ writeFileGenesis (outputDir </> filename) genesis
where
Expand Down Expand Up @@ -466,15 +473,20 @@ runGenesisCreateTestNetDataCmd
toCredential (CommitteeColdKeyHash v) = L.KeyHashObj v

addDRepsToConwayGenesis
:: [VerificationKey DRepKey]
:: forall m
. HasCallStack
=> MonadIO m
=> [VerificationKey DRepKey]
-> [VerificationKey StakeKey]
-> L.ConwayGenesis
-> L.ConwayGenesis
addDRepsToConwayGenesis dRepKeys stakingKeys conwayGenesis =
conwayGenesis
{ L.cgDelegs = delegs (zip stakingKeys (case dRepKeys of [] -> []; _ -> cycle dRepKeys))
, L.cgInitialDReps = initialDReps (L.ucppDRepDeposit $ L.cgUpgradePParams conwayGenesis) dRepKeys
}
-> m L.ConwayGenesis
addDRepsToConwayGenesis dRepKeys stakingKeys conwayGenesis = do
cgInitialDReps <- initialDReps (L.ucppDRepDeposit $ L.cgUpgradePParams conwayGenesis) dRepKeys
pure $
conwayGenesis
{ L.cgDelegs = delegs (zip stakingKeys (case dRepKeys of [] -> []; _ -> cycle dRepKeys))
, L.cgInitialDReps
}
where
delegs
:: [(VerificationKey StakeKey, VerificationKey DRepKey)]
Expand All @@ -490,16 +502,22 @@ runGenesisCreateTestNetDataCmd
initialDReps
:: Lovelace
-> [VerificationKey DRepKey]
-> ListMap (L.Credential L.DRepRole) L.DRepState
initialDReps minDeposit =
fromList
. map
-> m (ListMap (L.Credential L.DRepRole) L.DRepState)
initialDReps minDeposit verificationKeys = do
drepDeposit <-
maybe
(throwString ("Initial DRep deposit value cannot be compacted: " <> show minDeposit))
pure
(L.toCompact $ max (L.Coin 1_000_000) minDeposit)
pure
. fromList
$ map
( \c ->
( verificationKeyToDRepCredential c
, L.DRepState
{ L.drepExpiry = EpochNo 1_000
, L.drepAnchor = SNothing
, L.drepDeposit = max (L.Coin 1_000_000) minDeposit
, L.drepDeposit
, L.drepDelegs = Set.empty -- We don't need to populate this field (field "initialDReps"."keyHash-*"."delegators" in the JSON)
-- because its content is derived from the "delegs" field ("cgDelegs" above). In other words, when the Conway genesis is applied,
-- DRep delegations are computed from the "delegs" field. In the future the "delegators" field may
Expand All @@ -508,6 +526,7 @@ runGenesisCreateTestNetDataCmd
}
)
)
verificationKeys

verificationKeyToDRepCredential
:: VerificationKey DRepKey -> L.Credential L.DRepRole
Expand Down
Loading
Loading