Skip to content

Commit

Permalink
WIP: Add support for supplementary datums
Browse files Browse the repository at this point in the history
  • Loading branch information
Jimbo4350 committed Sep 18, 2024
1 parent ca49409 commit a8f6ad3
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cardano-cli/src/Cardano/CLI/Byron/Parsers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module Cardano.CLI.Byron.Parsers
)
where

import Cardano.Api hiding (GenesisParameters, UpdateProposal, parseFilePath)
import Cardano.Api hiding (GenesisParameters, UpdateProposal)
import Cardano.Api.Byron (Address (..), ByronProtocolParametersUpdate (..),
toByronLovelace)
import qualified Cardano.Api.Ledger as L
Expand Down
3 changes: 3 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Commands/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ data TransactionBuildRawCmdArgs era = TransactionBuildRawCmdArgs
, metadataSchema :: !TxMetadataJsonSchema
, scriptFiles :: ![ScriptFile]
-- ^ Auxiliary scripts
, supplementaryDatums :: ![ScriptDataOrFile]
, metadataFiles :: ![MetadataFile]
, mProtocolParamsFile :: !(Maybe ProtocolParamsFile)
, mUpdateProprosalFile :: !(Maybe (Featured ShelleyToBabbageEra era (Maybe UpdateProposalFile)))
Expand Down Expand Up @@ -124,6 +125,7 @@ data TransactionBuildCmdArgs era = TransactionBuildCmdArgs
, metadataSchema :: !TxMetadataJsonSchema
, scriptFiles :: ![ScriptFile]
-- ^ Auxiliary scripts
, supplementaryDatums :: ![ScriptDataOrFile]
, metadataFiles :: ![MetadataFile]
, mUpdateProposalFile :: !(Maybe (Featured ShelleyToBabbageEra era (Maybe UpdateProposalFile)))
, voteFiles :: ![(VoteFile In, Maybe (ScriptWitnessFiles WitCtxStake))]
Expand Down Expand Up @@ -174,6 +176,7 @@ data TransactionBuildEstimateCmdArgs era = TransactionBuildEstimateCmdArgs
, metadataSchema :: !TxMetadataJsonSchema
, scriptFiles :: ![ScriptFile]
-- ^ Auxiliary scripts
, supplementaryDatums :: ![ScriptDataOrFile]
, metadataFiles :: ![MetadataFile]
, mUpdateProposalFile :: !(Maybe (Featured ShelleyToBabbageEra era (Maybe UpdateProposalFile)))
, voteFiles :: ![(VoteFile In, Maybe (ScriptWitnessFiles WitCtxStake))]
Expand Down
4 changes: 2 additions & 2 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

module Cardano.CLI.EraBased.Options.Common where

import Cardano.Api hiding (bounded, parseFilePath)
import Cardano.Api
import qualified Cardano.Api.Ledger as L
import Cardano.Api.Shelley hiding (bounded, parseFilePath)
import Cardano.Api.Shelley

import Cardano.CLI.Environment (EnvCli (..), envCliAnyShelleyBasedEra,
envCliAnyShelleyToBabbageEra)
Expand Down
3 changes: 3 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ pTransactionBuildCmd era envCli = do
Nothing
"Filepath of auxiliary script(s)"
)
<*> many (pScriptDataOrFile "supplementary-datum" "The supplementary datum." "The supplementary datum file.")
<*> many pMetadataFile
<*> pFeatured (toCardanoEra sbe) (optional pUpdateProposalFile)
<*> pVoteFiles sbe AutoBalance
Expand Down Expand Up @@ -256,6 +257,7 @@ pTransactionBuildEstimateCmd era _envCli = do
Nothing
"Filepath of auxiliary script(s)"
)
<*> many (pScriptDataOrFile "supplementary-datum" "The supplementary datum." "The supplementary datum file.")
<*> many pMetadataFile
<*> pFeatured (toCardanoEra sbe) (optional pUpdateProposalFile)
<*> pVoteFiles sbe ManualBalance
Expand Down Expand Up @@ -293,6 +295,7 @@ pTransactionBuildRaw era =
<*> many (pWithdrawal era ManualBalance)
<*> pTxMetadataJsonSchema
<*> many (pScriptFor "auxiliary-script-file" Nothing "Filepath of auxiliary script(s)")
<*> many (pScriptDataOrFile "supplementary-datum" "The supplementary datum." "The supplementary datum file.")
<*> many pMetadataFile
<*> optional pProtocolParamsFile
<*> pFeatured era (optional pUpdateProposalFile)
Expand Down
26 changes: 26 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ runTransactionBuildCmd
, certificates
, withdrawals
, metadataSchema
, supplementaryDatums
, scriptFiles
, metadataFiles
, mUpdateProposalFile
Expand Down Expand Up @@ -174,6 +175,10 @@ runTransactionBuildCmd
firstExceptT TxCmdMetadataError . newExceptT $
readTxMetadata eon metadataSchema metadataFiles
valuesWithScriptWits <- readValueScriptWitnesses eon $ fromMaybe mempty mValue

txSupplementaryDatums <-
firstExceptT TxCmdScriptDataError $ readTxSupplementaryDatums supplementaryDatums

scripts <-
firstExceptT TxCmdScriptFileError $
mapM (readFileScriptInAnyLang . unFile) scriptFiles
Expand Down Expand Up @@ -261,6 +266,7 @@ runTransactionBuildCmd
withdrawalsAndMaybeScriptWits
requiredSigners
txAuxScripts
txSupplementaryDatums
txMetadata
mProp
mOverrideWitnesses
Expand Down Expand Up @@ -340,6 +346,7 @@ runTransactionBuildEstimateCmd -- TODO change type
, withdrawals
, metadataSchema
, scriptFiles
, supplementaryDatums
, metadataFiles
, mUpdateProposalFile
, voteFiles
Expand Down Expand Up @@ -373,6 +380,9 @@ runTransactionBuildEstimateCmd -- TODO change type
txAuxScripts <-
hoistEither $ first TxCmdAuxScriptsValidationError $ validateTxAuxScripts sbe scripts

txSupplementalDatums <-
firstExceptT TxCmdScriptDataError $ readTxSupplementaryDatums supplementaryDatums

txUpdateProposal <- case mUpdateProposalFile of
Just (Featured w (Just updateProposalFile)) ->
readTxUpdateProposal w updateProposalFile & firstExceptT TxCmdReadTextViewFileError
Expand Down Expand Up @@ -434,6 +444,7 @@ runTransactionBuildEstimateCmd -- TODO change type
requiredSigners
0
txAuxScripts
txSupplementalDatums
txMetadata
txUpdateProposal
votingProceduresAndMaybeScriptWits
Expand Down Expand Up @@ -584,6 +595,7 @@ runTransactionBuildRawCmd
, withdrawals
, metadataSchema
, scriptFiles
, supplementaryDatums
, metadataFiles
, mProtocolParamsFile
, mUpdateProprosalFile
Expand All @@ -610,6 +622,10 @@ runTransactionBuildRawCmd
scripts <-
firstExceptT TxCmdScriptFileError $
mapM (readFileScriptInAnyLang . unFile) scriptFiles

txSupplementaryDatums <-
firstExceptT TxCmdScriptDataError $ readTxSupplementaryDatums supplementaryDatums

txAuxScripts <-
hoistEither $ first TxCmdAuxScriptsValidationError $ validateTxAuxScripts eon scripts

Expand Down Expand Up @@ -677,6 +693,7 @@ runTransactionBuildRawCmd
withdrawalsAndMaybeScriptWits
requiredSigners
txAuxScripts
txSupplementaryDatums
txMetadata
mLedgerPParams
txUpdateProposal
Expand Down Expand Up @@ -718,6 +735,7 @@ runTxBuildRaw
-> [Hash PaymentKey]
-- ^ Required signers
-> TxAuxScripts era
-> TxSupplementalDatums era
-> TxMetadataInEra era
-> Maybe (LedgerProtocolParameters era)
-> TxUpdateProposal era
Expand All @@ -742,6 +760,7 @@ runTxBuildRaw
withdrawals
reqSigners
txAuxScripts
txSupplementalDatums
txMetadata
mpparams
txUpdateProposal
Expand All @@ -767,6 +786,7 @@ runTxBuildRaw
reqSigners
fee
txAuxScripts
txSupplementalDatums
txMetadata
txUpdateProposal
votingProcedures
Expand Down Expand Up @@ -807,6 +827,7 @@ constructTxBodyContent
-> Lovelace
-- ^ Tx fee
-> TxAuxScripts era
-> TxSupplementalDatums era
-> TxMetadataInEra era
-> TxUpdateProposal era
-> [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
Expand Down Expand Up @@ -834,6 +855,7 @@ constructTxBodyContent
reqSigners
fee
txAuxScripts
txSupplementalDatums
txMetadata
txUpdateProposal
votingProcedures
Expand Down Expand Up @@ -893,6 +915,7 @@ constructTxBodyContent
& setTxValidityLowerBound validatedLowerBound
& setTxValidityUpperBound mUpperBound
& setTxMetadata txMetadata
& setTxSupplementalDatums txSupplementalDatums
& setTxAuxScripts txAuxScripts
& setTxExtraKeyWits validatedReqSigners
& setTxProtocolParams (BuildTxWith $ LedgerProtocolParameters <$> mPparams)
Expand Down Expand Up @@ -948,6 +971,7 @@ runTxBuild
-> [Hash PaymentKey]
-- ^ Required signers
-> TxAuxScripts era
-> TxSupplementalDatums era
-> TxMetadataInEra era
-> TxUpdateProposal era
-> Maybe Word
Expand Down Expand Up @@ -975,6 +999,7 @@ runTxBuild
withdrawals
reqSigners
txAuxScripts
txSupplementaryData
txMetadata
txUpdateProposal
mOverrideWits
Expand Down Expand Up @@ -1047,6 +1072,7 @@ runTxBuild
reqSigners
0
txAuxScripts
txSupplementaryData
txMetadata
txUpdateProposal
votingProcedures
Expand Down
1 change: 1 addition & 0 deletions cardano-cli/src/Cardano/CLI/Json/Friendly.hs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ friendlyTxBodyImpl
txValidityUpperBound
txMetadata
txAuxScripts
_txSupplementalDatums
txExtraKeyWits
_txProtocolParams
txWithdrawals
Expand Down
2 changes: 2 additions & 0 deletions cardano-cli/src/Cardano/CLI/Legacy/Run/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ runLegacyTransactionBuildCmd
wdrls
metadataSchema
scriptFiles
[]
metadataFiles
mUpdateProposalFile
voteFiles
Expand Down Expand Up @@ -391,6 +392,7 @@ runLegacyTransactionBuildRawCmd
wdrls
metadataSchema
scriptFiles
[]
metadataFiles
mProtocolParamsFile
mUpdateProposalFile
Expand Down
6 changes: 6 additions & 0 deletions cardano-cli/src/Cardano/CLI/Read.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module Cardano.CLI.Read
, ScriptDataError (..)
, readScriptDatumOrFile
, readScriptRedeemerOrFile
, readTxSupplementaryDatums
, renderScriptDataError

-- * Tx
Expand Down Expand Up @@ -485,6 +486,11 @@ readScriptDataOrFile (ScriptDataCborFile fp) = do
getScriptData hSd
return hSd

readTxSupplementaryDatums :: [ScriptDataOrFile] -> ExceptT ScriptDataError IO (TxSupplementalDatums era)
readTxSupplementaryDatums supplementaryDatums =
TxSupplementalDatums <$> mapM readScriptDataOrFile supplementaryDatums


readVerificationKeyOrHashOrFileOrScript
:: MonadIOTransError (Either (FileError ScriptDecodeError) (FileError InputDecodeError)) t m
=> Key keyrole
Expand Down

0 comments on commit a8f6ad3

Please sign in to comment.