From 026cc1a6a49494dbf3a94e9ec8d954667c5eae51 Mon Sep 17 00:00:00 2001 From: thanhvh Date: Fri, 23 Aug 2024 17:11:23 +0700 Subject: [PATCH] Fix datum conversion in 'fromLedgerTxOuts' when using 'fromAlonzoTxOut' --- cardano-api/internal/Cardano/Api/Tx/Body.hs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/cardano-api/internal/Cardano/Api/Tx/Body.hs b/cardano-api/internal/Cardano/Api/Tx/Body.hs index 0e40356f0c..71d1bdcaf9 100644 --- a/cardano-api/internal/Cardano/Api/Tx/Body.hs +++ b/cardano-api/internal/Cardano/Api/Tx/Body.hs @@ -2010,8 +2010,10 @@ fromLedgerTxOuts sbe body scriptdata = ShelleyBasedEraAlonzo -> [ fromAlonzoTxOut AlonzoEraOnwardsAlonzo + txdatums txout - | txout <- toList (body ^. L.outputsTxBodyL) + | let txdatums = selectTxDatums scriptdata + , txout <- toList (body ^. L.outputsTxBodyL) ] ShelleyBasedEraBabbage -> [ fromBabbageTxOut @@ -2039,18 +2041,31 @@ selectTxDatums (TxBodyScriptData _ (Alonzo.TxDats' datums) _) = datums fromAlonzoTxOut :: () => AlonzoEraOnwards era + -> Map (L.DataHash StandardCrypto) (L.Data ledgerera) -> L.TxOut (ShelleyLedgerEra era) -> TxOut CtxTx era -fromAlonzoTxOut w txOut = +fromAlonzoTxOut w txdatums txOut = alonzoEraOnwardsConstraints w $ TxOut (fromShelleyAddr shelleyBasedEra (txOut ^. L.addrTxOutL)) (TxOutValueShelleyBased sbe (txOut ^. L.valueTxOutL)) - (fromAlonzoTxOutDatumHash w (txOut ^. L.dataHashTxOutL)) + (fromAlonzoTxOutDatum w txdatums (txOut ^. L.dataHashTxOutL)) ReferenceScriptNone where sbe = alonzoEraOnwardsToShelleyBasedEra w +fromAlonzoTxOutDatum + :: () + => AlonzoEraOnwards era + -> Map (L.DataHash StandardCrypto) (L.Data ledgerera) + -> StrictMaybe (L.DataHash StandardCrypto) + -> TxOutDatum CtxTx era +fromAlonzoTxOutDatum w txdatums = \case + SNothing -> TxOutDatumNone + SJust dh + | Just d <- Map.lookup dh txdatums -> TxOutDatumInTx' w (ScriptDataHash dh) (fromAlonzoData d) + | otherwise -> TxOutDatumHash w (ScriptDataHash dh) + fromBabbageTxOut :: forall era . ()