Skip to content

Commit

Permalink
Add Legacy prefix to legacy run transaction commands
Browse files Browse the repository at this point in the history
  • Loading branch information
newhoggy committed Aug 26, 2023
1 parent 0f77e68 commit c35d534
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 51 deletions.
2 changes: 1 addition & 1 deletion cardano-cli/src/Cardano/CLI/Legacy/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ runLegacyCmds = \case
LegacyQueryCmds cmd -> firstExceptT CmdQueryError $ runQueryCmds cmd
LegacyStakeAddressCmds cmd -> firstExceptT CmdStakeAddressError $ runStakeAddressCmds cmd
LegacyTextViewCmds cmd -> firstExceptT CmdTextViewError $ runTextViewCmds cmd
LegacyTransactionCmds cmd -> firstExceptT CmdTransactionError $ runTransactionCmds cmd
LegacyTransactionCmds cmd -> firstExceptT CmdTransactionError $ runLegacyTransactionCmds cmd
103 changes: 53 additions & 50 deletions cardano-cli/src/Cardano/CLI/Legacy/Run/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
{- HLINT ignore "Use let" -}

module Cardano.CLI.Legacy.Run.Transaction
( runTransactionCmds
, readFileTx
, toTxOutInAnyEra
( runLegacyTransactionCmds
) where

import Cardano.Api
Expand Down Expand Up @@ -61,44 +59,49 @@ import qualified Data.Text.IO as Text
import Data.Type.Equality (TestEquality (..))
import qualified System.IO as IO

runTransactionCmds :: LegacyTransactionCmds -> ExceptT ShelleyTxCmdError IO ()
runTransactionCmds cmd =
runLegacyTransactionCmds :: LegacyTransactionCmds -> ExceptT ShelleyTxCmdError IO ()
runLegacyTransactionCmds cmd =
case cmd of
TxBuild mNodeSocketPath era consensusModeParams nid mScriptValidity mOverrideWits txins readOnlyRefIns
reqSigners txinsc mReturnColl mTotCollateral txouts changeAddr mValue mLowBound
mUpperBound certs wdrls metadataSchema scriptFiles metadataFiles mUpProp mconwayVote
mNewConstitution outputOptions -> do
runTxBuildCmd mNodeSocketPath era consensusModeParams nid mScriptValidity mOverrideWits txins readOnlyRefIns
runLegacyTxBuildCmd mNodeSocketPath era consensusModeParams nid mScriptValidity mOverrideWits txins readOnlyRefIns
reqSigners txinsc mReturnColl mTotCollateral txouts changeAddr mValue mLowBound
mUpperBound certs wdrls metadataSchema scriptFiles metadataFiles mUpProp mconwayVote
mNewConstitution outputOptions
TxBuildRaw era mScriptValidity txins readOnlyRefIns txinsc mReturnColl
mTotColl reqSigners txouts mValue mLowBound mUpperBound fee certs wdrls
metadataSchema scriptFiles metadataFiles mProtocolParamsFile mUpProp out -> do
runTxBuildRawCmd era mScriptValidity txins readOnlyRefIns txinsc mReturnColl
runLegacyTxBuildRawCmd era mScriptValidity txins readOnlyRefIns txinsc mReturnColl
mTotColl reqSigners txouts mValue mLowBound mUpperBound fee certs wdrls
metadataSchema scriptFiles metadataFiles mProtocolParamsFile mUpProp out
TxSign txinfile skfiles network txoutfile ->
runTxSign txinfile skfiles network txoutfile
runLegacyTxSign txinfile skfiles network txoutfile
TxSubmit mNodeSocketPath anyConsensusModeParams network txFp ->
runTxSubmit mNodeSocketPath anyConsensusModeParams network txFp
runLegacyTxSubmit mNodeSocketPath anyConsensusModeParams network txFp
TxCalculateMinFee txbody nw pParamsFile nInputs nOutputs nShelleyKeyWitnesses nByronKeyWitnesses ->
runTxCalculateMinFee txbody nw pParamsFile nInputs nOutputs nShelleyKeyWitnesses nByronKeyWitnesses
TxCalculateMinRequiredUTxO era pParamsFile txOuts -> runTxCalculateMinRequiredUTxO era pParamsFile txOuts
TxHashScriptData scriptDataOrFile -> runTxHashScriptData scriptDataOrFile
TxGetTxId txinfile -> runTxGetTxId txinfile
TxView txinfile -> runTxView txinfile
TxMintedPolicyId sFile -> runTxCreatePolicyId sFile
runLegacyTxCalculateMinFee txbody nw pParamsFile nInputs nOutputs nShelleyKeyWitnesses nByronKeyWitnesses
TxCalculateMinRequiredUTxO era pParamsFile txOuts ->
runLegacyTxCalculateMinRequiredUTxO era pParamsFile txOuts
TxHashScriptData scriptDataOrFile ->
runLegacyTxHashScriptData scriptDataOrFile
TxGetTxId txinfile ->
runLegacyTxGetTxId txinfile
TxView txinfile ->
runLegacyTxView txinfile
TxMintedPolicyId sFile ->
runLegacyTxCreatePolicyId sFile
TxCreateWitness txBodyfile witSignData mbNw outFile ->
runTxCreateWitness txBodyfile witSignData mbNw outFile
runLegacyTxCreateWitness txBodyfile witSignData mbNw outFile
TxAssembleTxBodyWitness txBodyFile witnessFile outFile ->
runTxSignWitness txBodyFile witnessFile outFile
runLegacyTxSignWitness txBodyFile witnessFile outFile

-- ----------------------------------------------------------------------------
-- Building transactions
--

runTxBuildCmd
runLegacyTxBuildCmd
:: SocketPath
-> AnyCardanoEra
-> AnyConsensusModeParams
Expand Down Expand Up @@ -126,7 +129,7 @@ runTxBuildCmd
-> [NewConstitutionFile In] -- TODO: Conway era - we should replace this with a sumtype that handles all governance actions
-> TxBuildOutputOptions
-> ExceptT ShelleyTxCmdError IO ()
runTxBuildCmd
runLegacyTxBuildCmd
socketPath (AnyCardanoEra cEra) consensusModeParams@(AnyConsensusModeParams cModeParams) nid
mScriptValidity mOverrideWits txins readOnlyRefIns reqSigners txinsc mReturnColl mTotCollateral txouts
changeAddr mValue mLowBound mUpperBound certs wdrls metadataSchema scriptFiles metadataFiles mUpProp
Expand Down Expand Up @@ -185,9 +188,9 @@ runTxBuildCmd
-- the same collateral input can be used for several plutus scripts
let filteredTxinsc = Set.toList $ Set.fromList txinsc

-- We need to construct the txBodycontent outside of runTxBuild
-- We need to construct the txBodycontent outside of runLegacyTxBuild
BalancedTxBody txBodycontent balancedTxBody _ _ <-
runTxBuild
runLegacyTxBuild
socketPath cEra consensusModeParams nid mScriptValidity inputsAndMaybeScriptWits readOnlyRefIns filteredTxinsc
mReturnCollateral mTotCollateral txOuts changeAddr valuesWithScriptWits mLowBound
mUpperBound certsAndMaybeScriptWits withdrawalsAndMaybeScriptWits
Expand Down Expand Up @@ -263,7 +266,7 @@ runTxBuildCmd
& onLeft (left . ShelleyTxCmdWriteFileError)


runTxBuildRawCmd
runLegacyTxBuildRawCmd
:: AnyCardanoEra
-> Maybe ScriptValidity
-> [(TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))]
Expand All @@ -286,7 +289,7 @@ runTxBuildRawCmd
-> Maybe UpdateProposalFile
-> TxBodyFile Out
-> ExceptT ShelleyTxCmdError IO ()
runTxBuildRawCmd
runLegacyTxBuildRawCmd
(AnyCardanoEra cEra) mScriptValidity txins readOnlyRefIns txinsc mReturnColl
mTotColl reqSigners txouts mValue mLowBound mUpperBound fee certs wdrls
metadataSchema scriptFiles metadataFiles mpParamsFile mUpProp out = do
Expand Down Expand Up @@ -328,7 +331,7 @@ runTxBuildRawCmd
-- the same collateral input can be used for several plutus scripts
let filteredTxinsc = Set.toList $ Set.fromList txinsc

txBody <- hoistEither $ runTxBuildRaw cEra mScriptValidity inputsAndMaybeScriptWits readOnlyRefIns filteredTxinsc
txBody <- hoistEither $ runLegacyTxBuildRaw cEra mScriptValidity inputsAndMaybeScriptWits readOnlyRefIns filteredTxinsc
mReturnCollateral mTotColl txOuts mLowBound mUpperBound fee valuesWithScriptWits
certsAndMaybeScriptWits withdrawalsAndMaybeScriptWits requiredSigners txAuxScripts
txMetadata pparams mProp
Expand All @@ -338,7 +341,7 @@ runTxBuildRawCmd
& onLeft (left . ShelleyTxCmdWriteFileError)


runTxBuildRaw
runLegacyTxBuildRaw
:: CardanoEra era
-> Maybe ScriptValidity
-- ^ Mark script as expected to pass or fail validation
Expand Down Expand Up @@ -371,7 +374,7 @@ runTxBuildRaw
-> Maybe ProtocolParameters
-> Maybe UpdateProposal
-> Either ShelleyTxCmdError (TxBody era)
runTxBuildRaw era
runLegacyTxBuildRaw era
mScriptValidity inputsAndMaybeScriptWits
readOnlyRefIns txinsc
mReturnCollateral mTotCollateral txouts
Expand Down Expand Up @@ -437,7 +440,7 @@ runTxBuildRaw era
first ShelleyTxCmdTxBodyError $
getIsCardanoEraConstraint era $ createAndValidateTransactionBody txBodyContent

runTxBuild
runLegacyTxBuild
:: SocketPath
-> CardanoEra era
-> AnyConsensusModeParams
Expand Down Expand Up @@ -477,7 +480,7 @@ runTxBuild
-> TxGovernanceActions era
-> TxBuildOutputOptions
-> ExceptT ShelleyTxCmdError IO (BalancedTxBody era)
runTxBuild
runLegacyTxBuild
socketPath era (AnyConsensusModeParams cModeParams) networkId mScriptValidity
inputsAndMaybeScriptWits readOnlyRefIns txinsc mReturnCollateral mTotCollateral txouts
(TxOutChangeAddress changeAddr) valuesWithScriptWits mLowerBound mUpperBound
Expand Down Expand Up @@ -575,7 +578,7 @@ runTxBuild
. hoistEither $ notScriptLockedTxIns txinsc nodeEraUTxO

cAddr <- pure (anyAddressInEra era changeAddr)
& onLeft (error $ "runTxBuild: Byron address used: " <> show changeAddr) -- should this throw instead?
& onLeft (error $ "runLegacyTxBuild: Byron address used: " <> show changeAddr) -- should this throw instead?

-- Why do we cast the era? The user can specify an era prior to the era that the node is currently in.
-- We cannot use the user specified era to construct a query against a node because it may differ
Expand Down Expand Up @@ -854,12 +857,12 @@ readValueScriptWitnesses era (v, sWitFiles) = do
-- Transaction signing
--

runTxSign :: InputTxBodyOrTxFile
runLegacyTxSign :: InputTxBodyOrTxFile
-> [WitnessSigningData]
-> Maybe NetworkId
-> TxFile Out
-> ExceptT ShelleyTxCmdError IO ()
runTxSign txOrTxBody witSigningData mnw outTxFile = do
runLegacyTxSign txOrTxBody witSigningData mnw outTxFile = do
sks <- mapM (firstExceptT ShelleyTxCmdReadWitnessSigningDataError . newExceptT . readWitnessSigningData) witSigningData

let (sksByron, sksShelley) = partitionSomeWitnesses $ map categoriseSomeWitness sks
Expand Down Expand Up @@ -930,13 +933,13 @@ runTxSign txOrTxBody witSigningData mnw outTxFile = do
--


runTxSubmit
runLegacyTxSubmit
:: SocketPath
-> AnyConsensusModeParams
-> NetworkId
-> FilePath
-> ExceptT ShelleyTxCmdError IO ()
runTxSubmit socketPath (AnyConsensusModeParams cModeParams) network txFilePath = do
runLegacyTxSubmit socketPath (AnyConsensusModeParams cModeParams) network txFilePath = do
txFile <- liftIO $ fileOrPipe txFilePath
InAnyCardanoEra era tx <- lift (readFileTx txFile) & onLeft (left . ShelleyTxCmdCddlError)
let cMode = AnyConsensusMode $ consensusModeOnly cModeParams
Expand All @@ -962,7 +965,7 @@ runTxSubmit socketPath (AnyConsensusModeParams cModeParams) network txFilePath =
-- Transaction fee calculation
--

runTxCalculateMinFee
runLegacyTxCalculateMinFee
:: TxBodyFile In
-> NetworkId
-> ProtocolParamsFile
Expand All @@ -971,7 +974,7 @@ runTxCalculateMinFee
-> TxShelleyWitnessCount
-> TxByronWitnessCount
-> ExceptT ShelleyTxCmdError IO ()
runTxCalculateMinFee (File txbodyFilePath) nw pParamsFile
runLegacyTxCalculateMinFee (File txbodyFilePath) nw pParamsFile
(TxInCount nInputs) (TxOutCount nOutputs)
(TxShelleyWitnessCount nShelleyKeyWitnesses)
(TxByronWitnessCount nByronKeyWitnesses) = do
Expand Down Expand Up @@ -1016,25 +1019,25 @@ runTxCalculateMinFee (File txbodyFilePath) nw pParamsFile
-- Transaction fee calculation
--

runTxCalculateMinRequiredUTxO
runLegacyTxCalculateMinRequiredUTxO
:: AnyCardanoEra
-> ProtocolParamsFile
-> TxOutAnyEra
-> ExceptT ShelleyTxCmdError IO ()
runTxCalculateMinRequiredUTxO (AnyCardanoEra era) pParamsFile txOut = do
runLegacyTxCalculateMinRequiredUTxO (AnyCardanoEra era) pParamsFile txOut = do
pp <- firstExceptT ShelleyTxCmdProtocolParamsError (readProtocolParameters pParamsFile)
out <- toTxOutInAnyEra era txOut
case cardanoEraStyle era of
LegacyByronEra -> error "runTxCalculateMinRequiredUTxO: Byron era not implemented yet"
LegacyByronEra -> error "runLegacyTxCalculateMinRequiredUTxO: Byron era not implemented yet"
ShelleyBasedEra sbe -> do
firstExceptT ShelleyTxCmdPParamsErr . hoistEither
$ checkProtocolParameters sbe pp
pp' <- hoistEither . first ShelleyTxCmdProtocolParamsConverstionError $ toLedgerPParams sbe pp
let minValue = calculateMinimumUTxO sbe out pp'
liftIO . IO.print $ minValue

runTxCreatePolicyId :: ScriptFile -> ExceptT ShelleyTxCmdError IO ()
runTxCreatePolicyId (ScriptFile sFile) = do
runLegacyTxCreatePolicyId :: ScriptFile -> ExceptT ShelleyTxCmdError IO ()
runLegacyTxCreatePolicyId (ScriptFile sFile) = do
ScriptInAnyLang _ script <- firstExceptT ShelleyTxCmdScriptFileError $
readFileScriptInAnyLang sFile
liftIO . Text.putStrLn . serialiseToRawBytesHexText $ hashScript script
Expand Down Expand Up @@ -1091,13 +1094,13 @@ mkShelleyBootstrapWitnesses mnw txBody =
-- Other misc small commands
--

runTxHashScriptData :: ScriptDataOrFile -> ExceptT ShelleyTxCmdError IO ()
runTxHashScriptData scriptDataOrFile = do
runLegacyTxHashScriptData :: ScriptDataOrFile -> ExceptT ShelleyTxCmdError IO ()
runLegacyTxHashScriptData scriptDataOrFile = do
d <- firstExceptT ShelleyTxCmdScriptDataError $ readScriptDataOrFile scriptDataOrFile
liftIO $ BS.putStrLn $ serialiseToRawBytesHex (hashScriptDataBytes d)

runTxGetTxId :: InputTxBodyOrTxFile -> ExceptT ShelleyTxCmdError IO ()
runTxGetTxId txfile = do
runLegacyTxGetTxId :: InputTxBodyOrTxFile -> ExceptT ShelleyTxCmdError IO ()
runLegacyTxGetTxId txfile = do
InAnyCardanoEra _era txbody <-
case txfile of
InputTxBodyFile (File txbodyFilePath) -> do
Expand All @@ -1116,8 +1119,8 @@ runTxGetTxId txfile = do

liftIO $ BS.putStrLn $ serialiseToRawBytesHex (getTxId txbody)

runTxView :: InputTxBodyOrTxFile -> ExceptT ShelleyTxCmdError IO ()
runTxView = \case
runLegacyTxView :: InputTxBodyOrTxFile -> ExceptT ShelleyTxCmdError IO ()
runLegacyTxView = \case
InputTxBodyFile (File txbodyFilePath) -> do
txbodyFile <- liftIO $ fileOrPipe txbodyFilePath
unwitnessed <- firstExceptT ShelleyTxCmdCddlError . newExceptT
Expand All @@ -1141,13 +1144,13 @@ runTxView = \case
-- Witness commands
--

runTxCreateWitness
runLegacyTxCreateWitness
:: TxBodyFile In
-> WitnessSigningData
-> Maybe NetworkId
-> File () Out
-> ExceptT ShelleyTxCmdError IO ()
runTxCreateWitness (File txbodyFilePath) witSignData mbNw oFile = do
runLegacyTxCreateWitness (File txbodyFilePath) witSignData mbNw oFile = do
txbodyFile <- liftIO $ fileOrPipe txbodyFilePath
unwitnessed <- firstExceptT ShelleyTxCmdCddlError . newExceptT
$ readFileTxBody txbodyFile
Expand Down Expand Up @@ -1195,12 +1198,12 @@ runTxCreateWitness (File txbodyFilePath) witSignData mbNw oFile = do
$ writeLazyByteStringFile oFile
$ textEnvelopeToJSON Nothing witness

runTxSignWitness
runLegacyTxSignWitness
:: TxBodyFile In
-> [WitnessFile]
-> File () Out
-> ExceptT ShelleyTxCmdError IO ()
runTxSignWitness (File txbodyFilePath) witnessFiles oFp = do
runLegacyTxSignWitness (File txbodyFilePath) witnessFiles oFp = do
txbodyFile <- liftIO $ fileOrPipe txbodyFilePath
unwitnessed <- firstExceptT ShelleyTxCmdCddlError . newExceptT
$ readFileTxBody txbodyFile
Expand Down

0 comments on commit c35d534

Please sign in to comment.