Skip to content
Draft
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: 11 additions & 2 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-12-02T22:23:29Z
, cardano-haskell-packages 2026-01-30T03:40:53Z
, hackage.haskell.org 2026-01-12T19:29:50Z
, cardano-haskell-packages 2026-01-27T13:37:12Z

packages:
cardano-cli
Expand Down Expand Up @@ -67,3 +67,12 @@ if impl (ghc >= 9.12)
-- Do NOT add more source-repository-package stanzas here unless they are strictly
-- temporary! Please read the section in CONTRIBUTING about updating dependencies.

source-repository-package
type: git
location: https://github.com/IntersectMBO/cardano-api
tag: 7f0d7a8e22f5fe921e80f75ce868554f898c1d07
--sha256: sha256-8Lq88OX0+P+yTo2OX3oYgw3LHFSASASsnd/OoC4wMvo=
subdir:
cardano-api

allow-older: plutus-ledger-api, plutus-core
12 changes: 6 additions & 6 deletions cardano-cli/src/Cardano/CLI/EraBased/Script/Mint/Read.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module Cardano.CLI.EraBased.Script.Mint.Read
)
where

import Cardano.Api
import Cardano.Api hiding (AnyScriptWitness)
import Cardano.Api.Experimental qualified as Exp
import Cardano.Api.Experimental.AnyScriptWitness
import Cardano.Api.Experimental.Plutus qualified as Exp
Expand All @@ -27,13 +27,13 @@ import Cardano.Ledger.Core qualified as L
readMintScriptWitness
:: forall era e
. Exp.IsEra era
=> ScriptRequirements Exp.MintItem -> CIO e (PolicyId, Exp.AnyWitness (Exp.LedgerEra era))
=> ScriptRequirements Exp.MintItem -> CIO e (PolicyId, AnyScriptWitness (Exp.LedgerEra era))
readMintScriptWitness (OnDiskSimpleScript scriptFp) = do
let sFp = unFile scriptFp
s <- readFileSimpleScript sFp (Exp.useEra @era)
let sHash :: L.ScriptHash =
Exp.hashSimpleScript (s :: Exp.SimpleScript (Exp.LedgerEra era))
return (fromMaryPolicyID $ L.PolicyID sHash, Exp.AnySimpleScriptWitness $ Exp.SScript s)
return (fromMaryPolicyID $ L.PolicyID sHash, AnyScriptWitnessSimple $ Exp.SScript s)
readMintScriptWitness
( OnDiskPlutusScript
(OnDiskPlutusScriptCliArgs scriptFp Exp.NoScriptDatumAllowed redeemerFile execUnits)
Expand All @@ -57,7 +57,7 @@ readMintScriptWitness
execUnits
return
( polId
, Exp.AnyPlutusScriptWitness $
, AnyScriptWitnessPlutus $
AnyPlutusMintingScriptWitness sw
)
readMintScriptWitness
Expand All @@ -83,9 +83,9 @@ readMintScriptWitness
execUnits
return
( polId
, Exp.AnyPlutusScriptWitness $
, AnyScriptWitnessPlutus $
AnyPlutusMintingScriptWitness
sw
)
readMintScriptWitness (SimpleReferenceScript (SimpleRefScriptArgs refTxIn polId)) =
return (polId, Exp.AnySimpleScriptWitness $ Exp.SReferenceScript refTxIn)
return (polId, AnyScriptWitnessSimple $ Exp.SReferenceScript refTxIn)
98 changes: 59 additions & 39 deletions cardano-cli/src/Cardano/CLI/EraBased/Transaction/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,13 @@ runTransactionBuildCmd

requiredSigners <-
mapM (fromEitherIOCli . readRequiredSigner) reqSigners
mReturnCollateral <- forM mReturnColl toTxOutInShelleyBasedEra
mReturnCollateral :: Maybe (Exp.TxOut (Exp.LedgerEra era)) <-
forM mReturnColl toTxOutInShelleyBasedEra

txOuts <- mapM (toTxOutInAnyEra eon) txouts
txOuts <-
mapM
toTxOutInEra
txouts

-- Conway related
votingProceduresAndMaybeScriptWits :: [(VotingProcedures era, Exp.AnyWitness (Exp.LedgerEra era))] <-
Expand Down Expand Up @@ -367,6 +371,15 @@ runTransactionBuildCmd
then writeTxFileTextEnvelopeCanonical eon fpath noWitTx
else writeTxFileTextEnvelope eon fpath noWitTx

toTxOutInEra
:: Exp.IsEra era
=> TxOutAnyEra
-> CIO e (Exp.TxOut (Exp.LedgerEra era))
toTxOutInEra (TxOutAnyEra addr' val' mDatumHash refScriptFp) = do
let addr = anyAddressInShelleyBasedEra (convert Exp.useEra) addr'
o <- mkTxOut (convert Exp.useEra) addr val' mDatumHash refScriptFp
fromEitherCli $ Exp.fromLegacyTxOut o

runTransactionBuildEstimateCmd
:: forall era e
. Exp.IsEra era
Expand Down Expand Up @@ -434,7 +447,7 @@ runTransactionBuildEstimateCmd -- TODO change type

mReturnCollateral <- mapM toTxOutInShelleyBasedEra mReturnColl

txOuts <- mapM (toTxOutInAnyEra sbe) txouts
txOuts <- mapM toTxOutInEra txouts

-- the same collateral input can be used for several plutus scripts
let filteredTxinsc = nubOrd txInsCollateral
Expand Down Expand Up @@ -531,7 +544,7 @@ runTransactionBuildEstimateCmd -- TODO change type
txBodyOutFile
$ unsignedToToApiTx unsignedTx

unsignedToToApiTx :: forall era. Exp.IsEra era => Exp.UnsignedTx era -> Api.Tx era
unsignedToToApiTx :: forall era. Exp.IsEra era => Exp.UnsignedTx (Exp.LedgerEra era) -> Api.Tx era
unsignedToToApiTx (Exp.UnsignedTx lTx) =
ShelleyTx (convert $ Exp.useEra @era) $ obtainCommonConstraints (Exp.useEra @era) lTx

Expand Down Expand Up @@ -642,7 +655,7 @@ runTransactionBuildRawCmd

mReturnCollateral <- mapM toTxOutInShelleyBasedEra mReturnColl

txOuts <- mapM (toTxOutInAnyEra (convert Exp.useEra)) txouts
txOuts <- mapM toTxOutInEra txouts

-- the same collateral input can be used for several plutus scripts
let filteredTxinsc = toList @(Set _) $ fromList txInsCollateral
Expand All @@ -664,7 +677,7 @@ runTransactionBuildRawCmd
)
| (CertificateFile certFile, mSwit) <- certFilesAndMaybeScriptWits
]
txBody :: Exp.UnsignedTx era <-
txBody :: Exp.UnsignedTx (Exp.LedgerEra era) <-
fromEitherCli $
runTxBuildRaw
mScriptValidity
Expand All @@ -687,7 +700,6 @@ runTransactionBuildRawCmd
votingProceduresAndMaybeScriptWits
proposals
currentTreasuryValueAndDonation

let Exp.UnsignedTx lTx = txBody
noWitTx = ShelleyTx (convert eon) lTx
fromEitherIOCli $
Expand All @@ -705,18 +717,18 @@ runTxBuildRaw
-- ^ Read only reference inputs
-> [TxIn]
-- ^ TxIn for collateral
-> Maybe (TxOut CtxTx era)
-> Maybe (Exp.TxOut (Exp.LedgerEra era))
-- ^ Return collateral
-> Maybe Lovelace
-- ^ Total collateral
-> [TxOut CtxTx era]
-> [Exp.TxOut (Exp.LedgerEra era)]
-> Maybe SlotNo
-- ^ Tx lower bound
-> TxValidityUpperBound era
-- ^ Tx upper bound
-> Lovelace
-- ^ Tx fee
-> (L.MultiAsset, [(PolicyId, Exp.AnyWitness (Exp.LedgerEra era))])
-> (L.MultiAsset, [(PolicyId, Exp.AnyScriptWitness (Exp.LedgerEra era))])
-- ^ Multi-Asset minted value(s)
-> [(Exp.Certificate (Exp.LedgerEra era), Exp.AnyWitness (Exp.LedgerEra era))]
-- ^ Certificate with potential script witness
Expand All @@ -729,7 +741,7 @@ runTxBuildRaw
-> [(VotingProcedures era, Exp.AnyWitness (Exp.LedgerEra era))]
-> [(Proposal era, Exp.AnyWitness (Exp.LedgerEra era))]
-> Maybe (TxCurrentTreasuryValue, TxTreasuryDonation)
-> Either TxCmdError (Exp.UnsignedTx era)
-> Either TxCmdError (Exp.UnsignedTx (Exp.LedgerEra era))
runTxBuildRaw
mScriptValidity
inputsAndMaybeScriptWits
Expand Down Expand Up @@ -787,17 +799,17 @@ constructTxBodyContent
-- ^ Read only reference inputs
-> [TxIn]
-- ^ TxIn for collateral
-> Maybe (TxOut CtxTx era)
-> Maybe (Exp.TxOut (Exp.LedgerEra era))
-- ^ Return collateral
-> Maybe Lovelace
-- ^ Total collateral
-> [TxOut CtxTx era]
-> [Exp.TxOut (Exp.LedgerEra era)]
-- ^ Normal outputs
-> Maybe SlotNo
-- ^ Tx lower bound
-> TxValidityUpperBound era
-- ^ Tx upper bound
-> (L.MultiAsset, [(PolicyId, Exp.AnyWitness (Exp.LedgerEra era))])
-> (L.MultiAsset, [(PolicyId, Exp.AnyScriptWitness (Exp.LedgerEra era))])
-- ^ Multi-Asset value(s)
-> [(Exp.Certificate (Exp.LedgerEra era), Exp.AnyWitness (Exp.LedgerEra era))]
-- ^ Certificate with potential script witness
Expand Down Expand Up @@ -850,17 +862,18 @@ constructTxBodyContent
-- TODO The last argument of validateTxInsReference is a datum set from reference inputs
-- Should we allow providing of datum from CLI?
-- TODO: Figure how to expose resolved datums

txRetCollateral :: Maybe (Exp.TxReturnCollateral (Exp.LedgerEra era)) <- case mReturnCollateral of
Just rc -> do
let Exp.TxOut o = rc
Right $ Just $ Exp.TxReturnCollateral (o :: (L.TxOut (Exp.LedgerEra era)))
Nothing -> Right Nothing

let refInputs = Exp.TxInsReference allReferenceInputs Set.empty
expTxouts = map Exp.fromLegacyTxOut txouts
auxScripts = case txAuxScripts of
TxAuxScriptsNone -> []
-- TODO: Auxiliary scripts cannot be plutus scripts
TxAuxScripts _ scripts -> mapMaybe scriptInEraToSimpleScript scripts
txRetCollateral = case mReturnCollateral of
Just rc ->
let Exp.TxOut o _ = Exp.fromLegacyTxOut rc
in Just $ Exp.TxReturnCollateral (o :: (L.TxOut (Exp.LedgerEra era)))
Nothing -> Nothing
txTotCollateral = Exp.TxTotalCollateral <$> (mTotCollateral :: Maybe L.Coin)
expTxMetadata = case txMetadata of
TxMetadataNone -> TxMetadata mempty
Expand All @@ -882,7 +895,7 @@ constructTxBodyContent
& Exp.setTxIns inputsAndMaybeScriptWits
& Exp.setTxInsCollateral txinsc
& Exp.setTxInsReference refInputs
& Exp.setTxOuts expTxouts
& Exp.setTxOuts txouts
& maybe id Exp.setTxReturnCollateral txRetCollateral
& maybe id Exp.setTxTotalCollateral txTotCollateral
& Exp.setTxFee fee
Expand Down Expand Up @@ -940,16 +953,15 @@ runTxBuild
-- ^ TxIn with potential script witness
-> [TxIn]
-- ^ TxIn for collateral
-> Maybe (TxOut CtxTx era)
-> Maybe (Exp.TxOut (Exp.LedgerEra era))
-- ^ Return collateral
-> Maybe Lovelace
-- ^ Total collateral
-> [TxOut CtxTx era]
-> [Exp.TxOut (Exp.LedgerEra era)]
-- ^ Normal outputs
-> TxOutChangeAddress
-- ^ A change output
-> (L.MultiAsset, [(PolicyId, Exp.AnyWitness (Exp.LedgerEra era))]) -- TODO: Double check why this is a list

-> (L.MultiAsset, [(PolicyId, Exp.AnyScriptWitness (Exp.LedgerEra era))])
-- ^ Multi-Asset value(s)
-> Maybe SlotNo
-- ^ Tx lower bound
Expand All @@ -968,7 +980,7 @@ runTxBuild
-> [(Proposal era, Exp.AnyWitness (Exp.LedgerEra era))]
-> Maybe (TxCurrentTreasuryValue, TxTreasuryDonation)
-- ^ The current treasury value and the donation.
-> ExceptT TxCmdError IO (Exp.UnsignedTx era, Exp.TxBodyContent (Exp.LedgerEra era))
-> ExceptT TxCmdError IO (Exp.UnsignedTx (Exp.LedgerEra era), Exp.TxBodyContent (Exp.LedgerEra era))
runTxBuild
socketPath
networkId
Expand Down Expand Up @@ -1034,12 +1046,12 @@ runTxBuild
)
& onLeft (left . TxCmdQueryConvenienceError . AcqFailure)
& onLeft (left . TxCmdQueryConvenienceError)

let ledgerPParams = fromShelleyLedgerPParamsShim Exp.useEra $ unLedgerProtocolParameters pparams
txBodyContent <-
hoistEither $
constructTxBodyContent
mScriptValidity
(Just $ fromShelleyLedgerPParamsShim Exp.useEra $ unLedgerProtocolParameters pparams)
(Just ledgerPParams)
inputsAndMaybeScriptWits
readOnlyRefIns
txinsc
Expand Down Expand Up @@ -1069,7 +1081,14 @@ runTxBuild
cAddr <-
pure (anyAddressInEra era changeAddr)
& onLeft (error $ "runTxBuild: Byron address used: " <> show changeAddr) -- should this throw instead?
r@(unsignedTx, _) <-
let unbalancedTx = Exp.makeUnsignedTx (Exp.useEra @era) txBodyContent

unsignedTx :: Exp.UnsignedTx (Exp.LedgerEra era) <-
firstExceptT TxCmdRecursiveTxFeeError $
hoistEither $
obtainCommonConstraints (Exp.useEra @era) $
Exp.calcMinFeeRecursive unbalancedTx ledgerUTxO ledgerPParams 0
(_, updatedTxBodyContent) <-
firstExceptT (TxCmdBalanceTxBody . AnyTxBodyErrorAutoBalance)
. hoistEither
$ Exp.makeTransactionBodyAutoBalance
Expand All @@ -1090,7 +1109,7 @@ runTxBuild
Exp.extractAllIndexedPlutusScriptWitnesses Exp.useEra txBodyContent
scriptWitnessesAfterBalance <-
hoistEither . first TxCmdCBORDecodeError $
Exp.extractAllIndexedPlutusScriptWitnesses Exp.useEra (snd r)
Exp.extractAllIndexedPlutusScriptWitnesses Exp.useEra updatedTxBodyContent
when
( length scriptWitnessesBeforeBalance
/= length scriptWitnessesAfterBalance
Expand All @@ -1101,15 +1120,15 @@ runTxBuild
liftIO . putStrLn . docToString $
"Estimated transaction fee:" <+> pretty (Exp.getUnsignedTxFee unsignedTx)

return r
return (unsignedTx, updatedTxBodyContent)

-- ----------------------------------------------------------------------------
-- Transaction body validation and conversion
--

getAllReferenceInputs
:: [Exp.AnyWitness (Exp.LedgerEra era)]
-> [Exp.AnyWitness (Exp.LedgerEra era)]
-> [Exp.AnyScriptWitness (Exp.LedgerEra era)]
-> [Exp.AnyWitness (Exp.LedgerEra era)]
-- \^ Certificate witnesses
-> [Exp.AnyWitness (Exp.LedgerEra era)]
Expand All @@ -1127,7 +1146,7 @@ getAllReferenceInputs
propProceduresAnMaybeScriptWits
readOnlyRefIns = do
let txinsWitByRefInputs = mapMaybe Exp.getAnyWitnessReferenceInput spendingWitnesses
mintingRefInputs = mapMaybe Exp.getAnyWitnessReferenceInput mintWitnesses
mintingRefInputs = mapMaybe Exp.getAnyScriptWitnessReferenceInput mintWitnesses
certsWitByRefInputs = mapMaybe Exp.getAnyWitnessReferenceInput certScriptWitnesses
withdrawalsWitByRefInputs = mapMaybe Exp.getAnyWitnessReferenceInput withdrawals
votesWitByRefInputs = mapMaybe Exp.getAnyWitnessReferenceInput votingProceduresAndMaybeScriptWits
Expand All @@ -1146,19 +1165,20 @@ getAllReferenceInputs
toTxOutInShelleyBasedEra
:: Exp.IsEra era
=> TxOutShelleyBasedEra
-> CIO e (TxOut CtxTx era)
-> CIO e (Exp.TxOut (Exp.LedgerEra era))
toTxOutInShelleyBasedEra (TxOutShelleyBasedEra addr' val' mDatumHash refScriptFp) = do
let sbe = convert Exp.useEra
addr = shelleyAddressInEra sbe addr'
mkTxOut sbe addr val' mDatumHash refScriptFp
o <- mkTxOut sbe addr val' mDatumHash refScriptFp
fromEitherCli $ Exp.fromLegacyTxOut o

-- TODO: Currently we specify the policyId with the '--mint' option on the cli
-- and we added a separate '--policy-id' parser that parses the policy id for the
-- given reference input (since we don't have the script in this case). To avoid asking
-- for the policy id twice (in the build command) we can potentially query the UTxO and
-- access the script (and therefore the policy id).
createTxMintValue
:: (L.MultiAsset, [(PolicyId, Exp.AnyWitness (Exp.LedgerEra era))])
:: (L.MultiAsset, [(PolicyId, Exp.AnyScriptWitness (Exp.LedgerEra era))])
-> Either TxCmdError (Exp.TxMintValue (Exp.LedgerEra era))
createTxMintValue (val, scriptWitnesses) =
if mempty == val && List.null scriptWitnesses
Expand Down Expand Up @@ -1421,16 +1441,16 @@ runTransactionCalculateMinValueCmd
-> CIO e ()
runTransactionCalculateMinValueCmd
Cmd.TransactionCalculateMinValueCmdArgs
{ era
{ era = era :: Exp.Era era
, protocolParamsFile
, txOut
} = do
pp <-
pp :: L.PParams ((Exp.LedgerEra era)) <-

Check notice

Code scanning / hlint

Redundant bracket

cardano-cli/src/Cardano/CLI/EraBased/Transaction/Run.hs:1442:22-40:&nbsp;Suggestion:&nbsp;Redundant&nbsp;bracket &nbsp;&nbsp; Found: &nbsp;&nbsp;((Exp.LedgerEra&nbsp;era)) &nbsp;&nbsp; Perhaps: &nbsp;&nbsp;(Exp.LedgerEra&nbsp;era)
fromExceptTCli @ProtocolParamsError
(obtainCommonConstraints era $ readProtocolParameters protocolParamsFile)
out <- obtainCommonConstraints era $ toTxOutInShelleyBasedEra txOut

let minValue = calculateMinimumUTxO (convert era) pp out
let minValue = Exp.calculateMinimumUTxO pp out
liftIO . IO.print $ minValue

runTransactionCalculatePlutusScriptCostCmd
Expand Down
6 changes: 6 additions & 0 deletions cardano-cli/src/Cardano/CLI/Type/Error/TxCmdError.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ data AnyTxBodyErrorAutoBalance where

data TxCmdError
= TxCmdCBORDecodeError !CBOR.DecoderError
| TxCmdDatumDecodingError Exp.DatumDecodingError
| TxCmdProtocolParamsError ProtocolParamsError
| forall era. LostScriptWitnesses
[Exp.AnyIndexedPlutusScriptWitness (Exp.LedgerEra era)]
Expand Down Expand Up @@ -78,6 +79,7 @@ data TxCmdError
| TxCmdUtxoJsonError String
| forall era. TxCmdDeprecatedEra (Exp.DeprecatedEra era)
| TxCmdGenesisDataError GenesisDataError
| TxCmdRecursiveTxFeeError Exp.RecursiveFeeCalculationError

instance Show TxCmdError where
show = show . renderTxCmdError
Expand Down Expand Up @@ -195,6 +197,10 @@ renderTxCmdError = \case
, pretty (length after)
, "."
]
TxCmdDatumDecodingError err ->
"Error decoding datum: " <> pshow err
TxCmdRecursiveTxFeeError err ->
"Error during recursive fee calculation: " <> prettyError err

prettyPolicyIdList :: [PolicyId] -> Doc ann
prettyPolicyIdList =
Expand Down
Loading