From 7d03c307019550e72a71b6fb516f997dc98eb1f9 Mon Sep 17 00:00:00 2001 From: Jordan Millar Date: Mon, 16 Sep 2024 16:28:53 -0400 Subject: [PATCH 1/5] Implement TxSupplementalData GADT --- cardano-api/internal/Cardano/Api/Tx/Body.hs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/cardano-api/internal/Cardano/Api/Tx/Body.hs b/cardano-api/internal/Cardano/Api/Tx/Body.hs index 0e40356f0c..78d5e3c825 100644 --- a/cardano-api/internal/Cardano/Api/Tx/Body.hs +++ b/cardano-api/internal/Cardano/Api/Tx/Body.hs @@ -105,6 +105,7 @@ module Cardano.Api.Tx.Body , TxValidityLowerBound (..) , TxValidityUpperBound (..) , TxMetadataInEra (..) + , TxSupplementalDatums (..) , TxAuxScripts (..) , TxExtraKeyWitnesses (..) , TxWithdrawals (..) @@ -1151,6 +1152,21 @@ deriving instance Eq (TxMetadataInEra era) deriving instance Show (TxMetadataInEra era) +-- ---------------------------------------------------------------------------- +-- Transaction supplemental data (era-dependent) +-- +-- Supplemental datums can be added to the transaction if the corresponding +-- datum hash exists at a input in that transaction. +data TxSupplementalDatums era where + TxSupplementalDataNone :: TxSupplementalDatums era + TxSupplementalDatums + :: [HashableScriptData] + -> TxSupplementalDatums era + +deriving instance Eq (TxSupplementalDatums era) + +deriving instance Show (TxSupplementalDatums era) + -- ---------------------------------------------------------------------------- -- Auxiliary scripts (era-dependent) -- From 273d580fa9121fffb1bc6a6f71720da177f76477 Mon Sep 17 00:00:00 2001 From: Jordan Millar Date: Mon, 16 Sep 2024 16:33:39 -0400 Subject: [PATCH 2/5] Update TxBodyContent with txSupplementalData field --- cardano-api/internal/Cardano/Api/Tx/Body.hs | 1 + 1 file changed, 1 insertion(+) diff --git a/cardano-api/internal/Cardano/Api/Tx/Body.hs b/cardano-api/internal/Cardano/Api/Tx/Body.hs index 78d5e3c825..572e90c23e 100644 --- a/cardano-api/internal/Cardano/Api/Tx/Body.hs +++ b/cardano-api/internal/Cardano/Api/Tx/Body.hs @@ -1375,6 +1375,7 @@ data TxBodyContent build era , txValidityUpperBound :: TxValidityUpperBound era , txMetadata :: TxMetadataInEra era , txAuxScripts :: TxAuxScripts era + , txSupplementalData :: TxSupplementalDatums era , txExtraKeyWits :: TxExtraKeyWitnesses era , txProtocolParams :: BuildTxWith build (Maybe (LedgerProtocolParameters era)) , txWithdrawals :: TxWithdrawals build era From 443b62c83eeb2b7b60128fc81cefa31874a51b8a Mon Sep 17 00:00:00 2001 From: Jordan Millar Date: Mon, 16 Sep 2024 16:36:25 -0400 Subject: [PATCH 3/5] Implement txSupplementalData Update convScriptData to include supplemental datums --- cardano-api/internal/Cardano/Api/Tx/Body.hs | 26 ++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/cardano-api/internal/Cardano/Api/Tx/Body.hs b/cardano-api/internal/Cardano/Api/Tx/Body.hs index 572e90c23e..61f1df3222 100644 --- a/cardano-api/internal/Cardano/Api/Tx/Body.hs +++ b/cardano-api/internal/Cardano/Api/Tx/Body.hs @@ -144,6 +144,7 @@ module Cardano.Api.Tx.Body , convReturnCollateral , convScripts , convScriptData + , convSupplementalDatums , convTotalCollateral , convTransactionFee , convTxIns @@ -1407,6 +1408,7 @@ defaultTxBodyContent era = , txFee = defaultTxFee era , txValidityLowerBound = TxValidityNoLowerBound , txValidityUpperBound = defaultTxValidityUpperBound era + , txSupplementalData = TxSupplementalDataNone , txMetadata = TxMetadataNone , txAuxScripts = TxAuxScriptsNone , txExtraKeyWits = TxExtraKeyWitnessesNone @@ -1628,6 +1630,7 @@ createTransactionBody sbe bc = apiExtraKeyWitnesses = txExtraKeyWits bc apiReturnCollateral = txReturnCollateral bc apiTotalCollateral = txTotalCollateral bc + apiSupplementalData = txSupplementalData bc -- Ledger types collTxIns = convCollateralTxIns apiCollateralTxIns @@ -1638,7 +1641,7 @@ createTransactionBody sbe bc = txAuxData = toAuxiliaryData sbe (txMetadata bc) (txAuxScripts bc) scripts = convScripts apiScriptWitnesses languages = convLanguages apiScriptWitnesses - sData = convScriptData sbe apiTxOuts apiScriptWitnesses + sData = convScriptData sbe apiTxOuts apiScriptWitnesses apiSupplementalData proposalProcedures = convProposalProcedures $ maybe TxProposalProceduresNone unFeatured (txProposalProcedures bc) votingProcedures = convVotingProcedures $ maybe TxVotingProceduresNone unFeatured (txVotingProcedures bc) currentTreasuryValue = Ledger.maybeToStrictMaybe $ unFeatured =<< txCurrentTreasuryValue bc @@ -2435,8 +2438,9 @@ convScriptData => ShelleyBasedEra era -> [TxOut CtxTx era] -> [(ScriptWitnessIndex, AnyScriptWitness era)] + -> TxSupplementalData era -> TxBodyScriptData era -convScriptData sbe txOuts scriptWitnesses = +convScriptData sbe txOuts scriptWitnesses txSuppDatums = caseShelleyToMaryOrAlonzoEraOnwards (const TxBodyNoScriptData) ( \w -> @@ -2460,6 +2464,8 @@ convScriptData sbe txOuts scriptWitnesses = , let d' = toAlonzoData d ] + supplementalDatums = convSupplementalDatums sbe txSuppDatums + scriptdata :: [HashableScriptData] scriptdata = [d | TxOut _ _ (TxOutDatumInTx _ d) _ <- txOuts] @@ -2477,7 +2483,7 @@ convScriptData sbe txOuts scriptWitnesses = ) <- scriptWitnesses ] - in TxBodyScriptData w datums redeemers + in TxBodyScriptData w (datums <> supplementalDatums) redeemers ) sbe @@ -3378,6 +3384,20 @@ fromShelleyWithdrawal (L.Withdrawals withdrawals) = | (stakeAddr, value) <- Map.assocs withdrawals ] +convSupplementalDatums + :: ShelleyBasedEra era + -> TxSupplementalData era + -> L.TxDats (ShelleyLedgerEra era) +convSupplementalDatums sbe TxSupplementalDataNone = + shelleyBasedEraConstraints sbe mempty +convSupplementalDatums sbe (TxSupplementalData datums) = + shelleyBasedEraConstraints sbe $ + L.TxDats $ + Map.fromList + [ (L.hashData d, d) + | d <- map toAlonzoData datums + ] + -- | In the Allegra and Mary eras the auxiliary data consists of the tx metadata -- and the axiliary scripts. In the Alonzo and later eras the auxiliary data consists of the tx metadata -- and the axiliary scripts, and the axiliary script data. From f4942cabcae05d5bee7334c93c387a0d55200629 Mon Sep 17 00:00:00 2001 From: Jordan Millar Date: Mon, 16 Sep 2024 16:39:38 -0400 Subject: [PATCH 4/5] Update makeUnsignedTx to include supplemental datums --- cardano-api/internal/Cardano/Api/Experimental/Tx.hs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cardano-api/internal/Cardano/Api/Experimental/Tx.hs b/cardano-api/internal/Cardano/Api/Experimental/Tx.hs index 7356cb2046..3aaf71e9bf 100644 --- a/cardano-api/internal/Cardano/Api/Experimental/Tx.hs +++ b/cardano-api/internal/Cardano/Api/Experimental/Tx.hs @@ -76,6 +76,7 @@ makeUnsignedTx era bc = obtainCommonConstraints era $ do apiExtraKeyWitnesses = txExtraKeyWits bc apiReturnCollateral = txReturnCollateral bc apiTotalCollateral = txTotalCollateral bc + apiSupplementaryData = txSupplementalData bc -- Ledger types txins = convTxIns $ txIns bc @@ -90,10 +91,11 @@ makeUnsignedTx era bc = obtainCommonConstraints era $ do txAuxData = toAuxiliaryData sbe (txMetadata bc) (txAuxScripts bc) scripts = convScripts apiScriptWitnesses languages = convLanguages apiScriptWitnesses - sData = convScriptData sbe apiTxOuts apiScriptWitnesses + sData = convScriptData sbe apiTxOuts apiScriptWitnesses apiSupplementaryData (datums, redeemers) = case sData of TxBodyScriptData _ ds rs -> (ds, rs) TxBodyNoScriptData -> (mempty, L.Redeemers mempty) + let setMint = convMintValue apiMintValue setReqSignerHashes = convExtraKeyWitnesses apiExtraKeyWitnesses ledgerTxBody = From ecc162318f4bc678cd3fe51ee10ccfe6a48d8e45 Mon Sep 17 00:00:00 2001 From: Jordan Millar Date: Mon, 16 Sep 2024 16:40:52 -0400 Subject: [PATCH 5/5] Misc changes --- cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs | 1 + cardano-api/internal/Cardano/Api/Fees.hs | 1 + cardano-api/internal/Cardano/Api/Tx/Body.hs | 20 ++++++++++++------- cardano-api/src/Cardano/Api.hs | 2 ++ 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs b/cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs index 2f432702fa..61c73e3773 100644 --- a/cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs +++ b/cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs @@ -696,6 +696,7 @@ genTxBodyContent sbe = do , Api.txValidityUpperBound , Api.txMetadata , Api.txAuxScripts + , Api.txSupplementalData = Api.BuildTxWith Api.TxSupplementalDataNone , Api.txExtraKeyWits , Api.txProtocolParams , Api.txWithdrawals diff --git a/cardano-api/internal/Cardano/Api/Fees.hs b/cardano-api/internal/Cardano/Api/Fees.hs index 7f736b6f53..50ccf0fad2 100644 --- a/cardano-api/internal/Cardano/Api/Fees.hs +++ b/cardano-api/internal/Cardano/Api/Fees.hs @@ -1433,6 +1433,7 @@ substituteExecutionUnits _ _ _ + _ txWithdrawals txCertificates _ diff --git a/cardano-api/internal/Cardano/Api/Tx/Body.hs b/cardano-api/internal/Cardano/Api/Tx/Body.hs index 61f1df3222..ab6fb0c665 100644 --- a/cardano-api/internal/Cardano/Api/Tx/Body.hs +++ b/cardano-api/internal/Cardano/Api/Tx/Body.hs @@ -57,6 +57,7 @@ module Cardano.Api.Tx.Body , setTxVotingProcedures , setTxMintValue , setTxScriptValidity + , setTxSupplementalDatums , setTxCurrentTreasuryValue , setTxTreasuryDonation , TxBodyError (..) @@ -1376,7 +1377,7 @@ data TxBodyContent build era , txValidityUpperBound :: TxValidityUpperBound era , txMetadata :: TxMetadataInEra era , txAuxScripts :: TxAuxScripts era - , txSupplementalData :: TxSupplementalDatums era + , txSupplementalData :: BuildTxWith build (TxSupplementalDatums era) , txExtraKeyWits :: TxExtraKeyWitnesses era , txProtocolParams :: BuildTxWith build (Maybe (LedgerProtocolParameters era)) , txWithdrawals :: TxWithdrawals build era @@ -1408,7 +1409,7 @@ defaultTxBodyContent era = , txFee = defaultTxFee era , txValidityLowerBound = TxValidityNoLowerBound , txValidityUpperBound = defaultTxValidityUpperBound era - , txSupplementalData = TxSupplementalDataNone + , txSupplementalData = BuildTxWith TxSupplementalDataNone , txMetadata = TxMetadataNone , txAuxScripts = TxAuxScriptsNone , txExtraKeyWits = TxExtraKeyWitnessesNone @@ -1501,6 +1502,10 @@ setTxMintValue v txBodyContent = txBodyContent{txMintValue = v} setTxScriptValidity :: TxScriptValidity era -> TxBodyContent build era -> TxBodyContent build era setTxScriptValidity v txBodyContent = txBodyContent{txScriptValidity = v} +setTxSupplementalDatums + :: TxSupplementalDatums era -> TxBodyContent BuildTx era -> TxBodyContent BuildTx era +setTxSupplementalDatums v txBodyContent = txBodyContent{txSupplementalData = BuildTxWith v} + setTxProposalProcedures :: Maybe (Featured ConwayEraOnwards era (TxProposalProcedures build era)) -> TxBodyContent build era @@ -1917,6 +1922,7 @@ fromLedgerTxBody sbe scriptValidity body scriptdata mAux = , txMintValue = fromLedgerTxMintValue sbe body , txExtraKeyWits = fromLedgerTxExtraKeyWitnesses sbe body , txProtocolParams = ViewTx + , txSupplementalData = ViewTx , txMetadata , txAuxScripts , txScriptValidity = scriptValidity @@ -2438,9 +2444,9 @@ convScriptData => ShelleyBasedEra era -> [TxOut CtxTx era] -> [(ScriptWitnessIndex, AnyScriptWitness era)] - -> TxSupplementalData era + -> BuildTxWith BuildTx (TxSupplementalDatums era) -> TxBodyScriptData era -convScriptData sbe txOuts scriptWitnesses txSuppDatums = +convScriptData sbe txOuts scriptWitnesses (BuildTxWith txSuppDatums) = caseShelleyToMaryOrAlonzoEraOnwards (const TxBodyNoScriptData) ( \w -> @@ -3386,14 +3392,14 @@ fromShelleyWithdrawal (L.Withdrawals withdrawals) = convSupplementalDatums :: ShelleyBasedEra era - -> TxSupplementalData era + -> TxSupplementalDatums era -> L.TxDats (ShelleyLedgerEra era) convSupplementalDatums sbe TxSupplementalDataNone = shelleyBasedEraConstraints sbe mempty -convSupplementalDatums sbe (TxSupplementalData datums) = +convSupplementalDatums sbe (TxSupplementalDatums datums) = shelleyBasedEraConstraints sbe $ L.TxDats $ - Map.fromList + fromList [ (L.hashData d, d) | d <- map toAlonzoData datums ] diff --git a/cardano-api/src/Cardano/Api.hs b/cardano-api/src/Cardano/Api.hs index c168cc0cc9..588fbb3550 100644 --- a/cardano-api/src/Cardano/Api.hs +++ b/cardano-api/src/Cardano/Api.hs @@ -312,6 +312,7 @@ module Cardano.Api , setTxUpdateProposal , setTxMintValue , setTxScriptValidity + , setTxSupplementalDatums , setTxProposalProcedures , setTxVotingProcedures , setTxCurrentTreasuryValue @@ -356,6 +357,7 @@ module Cardano.Api , EpochSlots (..) , TxMetadataInEra (..) , TxAuxScripts (..) + , TxSupplementalDatums (..) , TxExtraKeyWitnesses (..) , TxWithdrawals (..) , TxCertificates (..)