Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for supplementary datums #902

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,9 @@ 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.

source-repository-package
type: git
location: https://github.com/IntersectMBO/cardano-api.git
tag: 22417a0f7fce857324dd01389afbeb9fee948cac
subdir: cardano-api
91 changes: 77 additions & 14 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,61 @@ pScriptDatumOrFile scriptFlagPrefix witctx =
, Opt.help "Inline datum present at transaction input."
]

pScriptDataOrFileHidden
:: String
-- ^ data flag prefix
-> String
-- ^ value help text
-> String
-- ^ file help text
-> Parser ScriptDataOrFile
pScriptDataOrFileHidden dataFlagPrefix helpTextForValue helpTextForFile =
asum
[ pScriptDataCborFile
, pScriptDataFile
, pScriptDataValue
]
where
pScriptDataCborFile =
fmap ScriptDataCborFile . Opt.strOption $
mconcat
[ Opt.long (dataFlagPrefix ++ "-cbor-file")
, Opt.metavar "CBOR_FILE"
, Opt.help $
mconcat
[ helpTextForFile
, " The file has to be in CBOR format."
]
, Opt.internal
]

pScriptDataFile =
fmap ScriptDataJsonFile . Opt.strOption $
mconcat
[ Opt.long (dataFlagPrefix ++ "-file")
, Opt.metavar "JSON_FILE"
, Opt.help $
mconcat
[ helpTextForFile
, " The file must follow the detailed JSON schema for script data."
]
, Opt.internal
]

pScriptDataValue =
fmap ScriptDataValue . Opt.option readerScriptData $
mconcat
[ Opt.long (dataFlagPrefix ++ "-value")
, Opt.metavar "JSON_VALUE"
, Opt.help $
mconcat
[ helpTextForValue
, " There is no schema: (almost) any JSON value is supported, including "
, "top-level strings and numbers."
]
, Opt.internal
]

pScriptDataOrFile
:: String
-- ^ data flag prefix
Expand Down Expand Up @@ -1167,16 +1222,16 @@ pScriptDataOrFile dataFlagPrefix helpTextForValue helpTextForFile =
]
]

readerScriptData :: ReadM HashableScriptData
readerScriptData = do
v <- Opt.str
sDataValue <-
liftWith ("readerScriptData: " <>) $
Aeson.eitherDecode v
liftWith (docToString . prettyError) $
scriptDataJsonToHashable ScriptDataJsonNoSchema sDataValue
where
liftWith f = either (fail . f) pure
readerScriptData :: ReadM HashableScriptData
readerScriptData = do
v <- Opt.str
sDataValue <-
liftWith ("readerScriptData: " <>) $
Aeson.eitherDecode v
liftWith (docToString . prettyError) $
scriptDataJsonToHashable ScriptDataJsonNoSchema sDataValue
where
liftWith f = either (fail . f) pure

pVoteFiles
:: ShelleyBasedEra era
Expand Down Expand Up @@ -2111,10 +2166,18 @@ pTxOutDatum =

pTxOutDatumByValue =
TxOutDatumByValue
<$> pScriptDataOrFile
"tx-out-datum-embed"
"The script datum to embed in the tx for this output, given here."
"The script datum to embed in the tx for this output, in the given file."
<$> asum
[ pScriptDataOrFile
"tx-out-supplemental-datum"
"The supplemental script datum to embed in the tx for this output, given here."
"The supplemental script datum to embed in the tx for this output, in the given file."
, -- The embed option was hidden because it's not obvious that this is a supplemental datum.
-- This can be removed eventually.
pScriptDataOrFileHidden
"tx-out-datum-embed"
"The script datum to embed in the tx for this output, given here."
"The script datum to embed in the tx for this output, in the given file."
]

pTxOutInlineDatumByValue =
TxOutInlineDatumByValue
Expand Down
2 changes: 1 addition & 1 deletion cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1313,7 +1313,7 @@ toTxAlonzoDatum supp cliDatum =
pure (TxOutDatumHash supp $ hashScriptDataBytes sData)
TxOutDatumByValue sDataOrFile -> do
sData <- firstExceptT TxCmdScriptDataError $ readScriptDataOrFile sDataOrFile
pure (TxOutDatumInTx supp sData)
pure (TxOutSupplementalDatum supp sData)
TxOutInlineDatumByValue sDataOrFile -> do
let cEra = toCardanoEra supp
forEraInEon cEra (txFeatureMismatch cEra TxFeatureInlineDatums) $ \babbageOnwards -> do
Expand Down
17 changes: 1 addition & 16 deletions cardano-cli/src/Cardano/CLI/Json/Friendly.hs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ friendlyTxBodyImpl
txValidityUpperBound
txMetadata
txAuxScripts
txSupplementalData
txExtraKeyWits
_txProtocolParams
txWithdrawals
Expand Down Expand Up @@ -252,10 +251,6 @@ friendlyTxBodyImpl
era
(`getRedeemerDetails` tb)
)
++ ( monoidForEraInEon @AlonzoEraOnwards
era
(`friendlySupplementalDatums` txSupplementalData)
)
++ ( monoidForEraInEon @ConwayEraOnwards
era
( \cOnwards ->
Expand Down Expand Up @@ -293,16 +288,6 @@ friendlyTxBodyImpl
friendlyLedgerProposals cOnwards proposalProcedures =
Array $ fromList $ map (friendlyLedgerProposal cOnwards) proposalProcedures

-- | API doesn't yet show that supplemental datums are alonzo onwards. So we do it in this function prototype,
-- even if we don't use the witness.
friendlySupplementalDatums
:: AlonzoEraOnwards era -> BuildTxWith build (TxSupplementalDatums era) -> [Aeson.Pair]
friendlySupplementalDatums _era = \case
ViewTx -> []
BuildTxWith TxSupplementalDataNone -> []
BuildTxWith (TxSupplementalDatums hashableScriptDatas) ->
["supplemental datums" .= toJSON hashableScriptDatas]

friendlyLedgerProposal
:: ConwayEraOnwards era -> L.ProposalProcedure (ShelleyLedgerEra era) -> Aeson.Value
friendlyLedgerProposal cOnwards proposalProcedure = object $ friendlyProposalImpl cOnwards (Proposal proposalProcedure)
Expand Down Expand Up @@ -483,7 +468,7 @@ friendlyTxOut era (TxOut addr amount mdatum script) =
renderDatum = \case
TxOutDatumNone -> Nothing
TxOutDatumHash _ h -> Just $ toJSON h
TxOutDatumInTx _ sData -> Just $ scriptDataToJson ScriptDataJsonDetailedSchema sData
TxOutSupplementalDatum _ sData -> Just $ scriptDataToJson ScriptDataJsonDetailedSchema sData
TxOutDatumInline _ sData -> Just $ scriptDataToJson ScriptDataJsonDetailedSchema sData

friendlyStakeReference :: StakeAddressReference -> Aeson.Value
Expand Down
Loading
Loading