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
5 changes: 2 additions & 3 deletions cardano-cli/cardano-cli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ library
Cardano.CLI.Compatible.Transaction.Command
Cardano.CLI.Compatible.Transaction.Option
Cardano.CLI.Compatible.Transaction.Run
Cardano.CLI.Compatible.Transaction.TxOut
Cardano.CLI.Environment
Cardano.CLI.EraBased.Command
Cardano.CLI.EraBased.Common.Option
Expand Down Expand Up @@ -226,7 +227,6 @@ library
Cardano.CLI.Type.Key.VerificationKey
Cardano.CLI.Type.MonadWarning
Cardano.CLI.Type.Output
Cardano.CLI.Type.TxFeature

other-modules: Paths_cardano_cli
autogen-modules: Paths_cardano_cli
Expand Down Expand Up @@ -460,7 +460,6 @@ test-suite cardano-cli-golden
tasty-discover:tasty-discover,

other-modules:
Test.Golden.Babbage.Transaction.CalculateMinFee
Test.Golden.Byron.SigningKeys
Test.Golden.Byron.Tx
Test.Golden.Byron.TxBody
Expand All @@ -481,6 +480,7 @@ test-suite cardano-cli-golden
Test.Golden.Hash.Hash
Test.Golden.Help
Test.Golden.Key.NonExtendedKey
Test.Golden.Latest.Transaction.CalculateMinFee
Test.Golden.Shelley.Address.Build
Test.Golden.Shelley.Address.Info
Test.Golden.Shelley.Address.KeyGen
Expand Down Expand Up @@ -518,7 +518,6 @@ test-suite cardano-cli-golden
Test.Golden.Shelley.TextView.DecodeCbor
Test.Golden.Shelley.Transaction.Assemble
Test.Golden.Shelley.Transaction.Build
Test.Golden.Shelley.Transaction.CalculateMinFee
Test.Golden.Shelley.Transaction.Id
Test.Golden.Shelley.Transaction.Sign
Test.Golden.TxView
Expand Down
17 changes: 17 additions & 0 deletions cardano-cli/src/Cardano/CLI/Compatible/Exception.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
module Cardano.CLI.Compatible.Exception
( CIO
, CustomCliException (..)
, fromEitherCIOCli
, fromMaybeCli
, throwCliError
, fromEitherCli
, fromEitherIOCli
Expand Down Expand Up @@ -69,3 +71,18 @@ fromExceptTCli
=> ExceptT e IO a
-> m a
fromExceptTCli = withFrozenCallStack $ fromEitherIOCli . runExceptT

fromEitherCIOCli
:: (Show err, Typeable err, Error err) => CIO e (Either err a) -> CIO e a
fromEitherCIOCli n = withFrozenCallStack $ do
r <- n
case r of
Left err -> throwCliError err
Right a -> return a

fromMaybeCli
:: (Show err, Typeable err, Error err) => err -> Maybe a -> CIO e a
fromMaybeCli err n = withFrozenCallStack $ do
case n of
Nothing -> throwCliError err
Just a -> return a
3 changes: 2 additions & 1 deletion cardano-cli/src/Cardano/CLI/Compatible/Transaction/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import Cardano.Api.Shelley hiding (VotingProcedures)

import Cardano.CLI.Compatible.Exception
import Cardano.CLI.Compatible.Transaction.Command
import Cardano.CLI.Compatible.Transaction.TxOut
import Cardano.CLI.EraBased.Script.Certificate.Read
import Cardano.CLI.EraBased.Script.Certificate.Type
import Cardano.CLI.EraBased.Script.Proposal.Type
Expand Down Expand Up @@ -65,7 +66,7 @@ runCompatibleTransactionCmd
) = shelleyBasedEraConstraints sbe $ do
sks <- mapM (fromEitherIOCli . readWitnessSigningData) witnesses

allOuts <- fromEitherIOCli . runExceptT $ mapM (toTxOutInAnyEra sbe) outs
allOuts <- mapM (toTxOutInAnyEra sbe) outs

certFilesAndMaybeScriptWits <-
fromExceptTCli $
Expand Down
131 changes: 131 additions & 0 deletions cardano-cli/src/Cardano/CLI/Compatible/Transaction/TxOut.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE RankNTypes #-}

module Cardano.CLI.Compatible.Transaction.TxOut
( mkTxOut
, toTxOutInAnyEra
)
where

import Cardano.Api
import Cardano.Api.Shelley

import Cardano.CLI.Compatible.Exception
import Cardano.CLI.EraBased.Script.Read.Common
import Cardano.CLI.Orphan ()
import Cardano.CLI.Read
import Cardano.CLI.Type.Common

import Data.Text (Text)

toTxOutInAnyEra
:: ShelleyBasedEra era
-> TxOutAnyEra
-> CIO e (TxOut CtxTx era)
toTxOutInAnyEra era (TxOutAnyEra addr' val' mDatumHash refScriptFp) = do
let addr = anyAddressInShelleyBasedEra era addr'
mkTxOut era addr val' mDatumHash refScriptFp

mkTxOut
:: ShelleyBasedEra era
-> AddressInEra era
-> Value
-> TxOutDatumAnyEra
-> ReferenceScriptAnyEra
-> CIO e (TxOut CtxTx era)
mkTxOut sbe addr val' mDatumHash refScriptFp = do
let era = toCardanoEra sbe
val <- toTxOutValueInShelleyBasedEra sbe val'

datum <-
inEonForEra
(pure TxOutDatumNone)
(`toTxAlonzoDatum` mDatumHash)
era

refScript <-
inEonForEra
(pure ReferenceScriptNone)
(`getReferenceScript` refScriptFp)
era

pure $ TxOut addr val datum refScript

toTxOutValueInShelleyBasedEra
:: ShelleyBasedEra era
-> Value
-> CIO e (TxOutValue era)
toTxOutValueInShelleyBasedEra sbe val =
caseShelleyToAllegraOrMaryEraOnwards
( \_ -> case valueToLovelace val of
Just l -> return (TxOutValueShelleyBased sbe l)
Nothing -> txFeatureMismatch sbe TxFeatureMultiAssetOutputs
)
(\w -> return (TxOutValueShelleyBased sbe (toLedgerValue w val)))
sbe

toTxAlonzoDatum
:: ()
=> AlonzoEraOnwards era
-> TxOutDatumAnyEra
-> CIO e (TxOutDatum CtxTx era)
toTxAlonzoDatum supp cliDatum =
case cliDatum of
TxOutDatumByNone -> pure TxOutDatumNone
TxOutDatumByHashOnly h -> pure (TxOutDatumHash supp h)
TxOutDatumByHashOf sDataOrFile -> do
sData <- fromExceptTCli $ readScriptDataOrFile sDataOrFile
pure (TxOutDatumHash supp $ hashScriptDataBytes sData)
TxOutDatumByValue sDataOrFile -> do
sData <- fromExceptTCli $ readScriptDataOrFile sDataOrFile
pure (TxOutSupplementalDatum supp sData)
TxOutInlineDatumByValue sDataOrFile -> do
let cEra = toCardanoEra supp
forEraInEon cEra (txFeatureMismatch cEra TxFeatureInlineDatums) $ \babbageOnwards -> do
sData <- fromExceptTCli $ readScriptDataOrFile sDataOrFile
pure $ TxOutDatumInline babbageOnwards sData

getReferenceScript
:: ()
=> BabbageEraOnwards era
-> ReferenceScriptAnyEra
-> CIO e (ReferenceScript era)
getReferenceScript w = \case
ReferenceScriptAnyEraNone -> return ReferenceScriptNone
ReferenceScriptAnyEra fp -> ReferenceScript w <$> fromExceptTCli (readFileScriptInAnyLang fp)

-- | An enumeration of era-dependent features where we have to check that it
-- is permissible to use this feature in this era.
data TxFeature
= TxFeatureMultiAssetOutputs
| TxFeatureInlineDatums
deriving Show

renderFeature :: TxFeature -> Text
renderFeature = \case
TxFeatureMultiAssetOutputs -> "Multi-Asset outputs"
TxFeatureInlineDatums -> "Inline datums"

data TxCmdTxFeatureMismatch = TxCmdTxFeatureMismatch !AnyCardanoEra !TxFeature deriving Show

instance Error TxCmdTxFeatureMismatch where
prettyError (TxCmdTxFeatureMismatch (AnyCardanoEra era) feature) =
pretty $
mconcat
[ renderFeature feature
, " cannot be used for "
, eraToStringKey era
, " era transactions."
]

txFeatureMismatch
:: ()
=> ToCardanoEra eon
=> eon era
-> TxFeature
-> CIO e a
txFeatureMismatch eon feature =
throwCliError $ TxCmdTxFeatureMismatch (anyCardanoEra $ toCardanoEra eon) feature

eraToStringKey :: CardanoEra a -> Text
eraToStringKey = docToText . pretty
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,8 @@ runGenesisCreateTestNetDataCmd
skeyHotFile = File @(SigningKey ()) $ committeeDir </> "cc.hot.skey"
vkeyColdFile = File @(VerificationKey ()) $ committeeDir </> "cc.cold.vkey"
skeyColdFile = File @(SigningKey ()) $ committeeDir </> "cc.cold.skey"
hotArgs = CC.GovernanceCommitteeKeyGenHotCmdArgs ConwayEraOnwardsConway vkeyHotFile skeyHotFile
coldArgs = CC.GovernanceCommitteeKeyGenColdCmdArgs ConwayEraOnwardsConway vkeyColdFile skeyColdFile
hotArgs = CC.GovernanceCommitteeKeyGenHotCmdArgs eon vkeyHotFile skeyHotFile
coldArgs = CC.GovernanceCommitteeKeyGenColdCmdArgs eon vkeyColdFile skeyColdFile
liftIO $ createDirectoryIfMissing True committeeDir
void $
CC.runGovernanceCommitteeKeyGenHot hotArgs
Expand All @@ -356,7 +356,7 @@ runGenesisCreateTestNetDataCmd
let drepDir = drepsDir </> "drep" <> show index
vkeyFile = File @(VerificationKey ()) $ drepDir </> "drep.vkey"
skeyFile = File @(SigningKey ()) $ drepDir </> "drep.skey"
cmd = DRep.GovernanceDRepKeyGenCmdArgs ConwayEraOnwardsConway vkeyFile skeyFile
cmd = DRep.GovernanceDRepKeyGenCmdArgs eon vkeyFile skeyFile
liftIO $ createDirectoryIfMissing True drepDir
fst <$> DRep.runGovernanceDRepKeyGenCmd cmd
Transient ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ module Cardano.CLI.EraBased.Genesis.Internal.Common
where

import Cardano.Api hiding (ConwayEra)
import Cardano.Api.Experimental (obtainCommonConstraints)
import Cardano.Api.Experimental qualified as Exp
import Cardano.Api.Ledger (AlonzoGenesis, ConwayGenesis)
import Cardano.Api.Ledger qualified as L
import Cardano.Api.Shelley (ShelleyGenesis, ShelleyLedgerEra, decodeAlonzoGenesis)
Expand Down Expand Up @@ -124,12 +126,12 @@ readRelays fp = do
-- TODO: eliminate this and get only the necessary params, and get them in a more
-- helpful way rather than requiring them as a local file.
readProtocolParameters
:: ()
=> ShelleyBasedEra era
-> ProtocolParamsFile
:: forall era
. Exp.IsEra era
=> ProtocolParamsFile
-> ExceptT ProtocolParamsError IO (L.PParams (ShelleyLedgerEra era))
readProtocolParameters sbe (ProtocolParamsFile fpath) = do
readProtocolParameters (ProtocolParamsFile fpath) = do
pparams <- handleIOExceptT (ProtocolParamsErrorFile . FileIOError fpath) $ LBS.readFile fpath
firstExceptT (ProtocolParamsErrorJSON fpath . Text.pack) . hoistEither $
shelleyBasedEraConstraints sbe $
obtainCommonConstraints (Exp.useEra @era) $
A.eitherDecode' pparams
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module Cardano.CLI.EraBased.Governance.Committee.Command
where

import Cardano.Api
import Cardano.Api.Experimental qualified as Exp
import Cardano.Api.Ledger qualified as L

import Cardano.CLI.Type.Common (PotentiallyCheckedAnchor, ResignationMetadataUrl)
Expand All @@ -37,30 +38,30 @@ data GovernanceCommitteeCmds era

data GovernanceCommitteeKeyGenColdCmdArgs era
= GovernanceCommitteeKeyGenColdCmdArgs
{ eon :: !(ConwayEraOnwards era)
{ era :: !(Exp.Era era)
, vkeyOutFile :: !(File (VerificationKey ()) Out)
, skeyOutFile :: !(File (SigningKey ()) Out)
}
deriving Show

data GovernanceCommitteeKeyGenHotCmdArgs era
= GovernanceCommitteeKeyGenHotCmdArgs
{ eon :: !(ConwayEraOnwards era)
{ era :: !(Exp.Era era)
, vkeyOutFile :: !(File (VerificationKey ()) Out)
, skeyOutFile :: !(File (SigningKey ()) Out)
}
deriving Show

data GovernanceCommitteeKeyHashCmdArgs era
= GovernanceCommitteeKeyHashCmdArgs
{ eon :: !(ConwayEraOnwards era)
{ era :: !(Exp.Era era)
, vkeySource :: !AnyVerificationKeySource
}
deriving Show

data GovernanceCommitteeCreateHotKeyAuthorizationCertificateCmdArgs era
= GovernanceCommitteeCreateHotKeyAuthorizationCertificateCmdArgs
{ eon :: !(ConwayEraOnwards era)
{ era :: !(Exp.Era era)
, vkeyColdKeySource :: !(VerificationKeySource CommitteeColdKey)
, vkeyHotKeySource :: !(VerificationKeySource CommitteeHotKey)
, outFile :: !(File () Out)
Expand All @@ -69,7 +70,7 @@ data GovernanceCommitteeCreateHotKeyAuthorizationCertificateCmdArgs era

data GovernanceCommitteeCreateColdKeyResignationCertificateCmdArgs era
= GovernanceCommitteeCreateColdKeyResignationCertificateCmdArgs
{ eon :: !(ConwayEraOnwards era)
{ era :: !(Exp.Era era)
, vkeyColdKeySource :: !(VerificationKeySource CommitteeColdKey)
, anchor
:: !( Maybe
Expand Down
Loading
Loading