Skip to content

Commit

Permalink
Implement txSupplementalData
Browse files Browse the repository at this point in the history
Update convScriptData to include supplemental datums
  • Loading branch information
Jimbo4350 committed Sep 17, 2024
1 parent 273d580 commit 443b62c
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions cardano-api/internal/Cardano/Api/Tx/Body.hs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ module Cardano.Api.Tx.Body
, convReturnCollateral
, convScripts
, convScriptData
, convSupplementalDatums
, convTotalCollateral
, convTransactionFee
, convTxIns
Expand Down Expand Up @@ -1407,6 +1408,7 @@ defaultTxBodyContent era =
, txFee = defaultTxFee era
, txValidityLowerBound = TxValidityNoLowerBound
, txValidityUpperBound = defaultTxValidityUpperBound era
, txSupplementalData = TxSupplementalDataNone
, txMetadata = TxMetadataNone
, txAuxScripts = TxAuxScriptsNone
, txExtraKeyWits = TxExtraKeyWitnessesNone
Expand Down Expand Up @@ -1628,6 +1630,7 @@ createTransactionBody sbe bc =
apiExtraKeyWitnesses = txExtraKeyWits bc
apiReturnCollateral = txReturnCollateral bc
apiTotalCollateral = txTotalCollateral bc
apiSupplementalData = txSupplementalData bc

-- Ledger types
collTxIns = convCollateralTxIns apiCollateralTxIns
Expand All @@ -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
Expand Down Expand Up @@ -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 ->
Expand All @@ -2460,6 +2464,8 @@ convScriptData sbe txOuts scriptWitnesses =
, let d' = toAlonzoData d
]

supplementalDatums = convSupplementalDatums sbe txSuppDatums

scriptdata :: [HashableScriptData]
scriptdata =
[d | TxOut _ _ (TxOutDatumInTx _ d) _ <- txOuts]
Expand All @@ -2477,7 +2483,7 @@ convScriptData sbe txOuts scriptWitnesses =
) <-
scriptWitnesses
]
in TxBodyScriptData w datums redeemers
in TxBodyScriptData w (datums <> supplementalDatums) redeemers
)
sbe

Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 443b62c

Please sign in to comment.