0

The following code would work for V1: outputDatum :: EkivalEscrowDatum

outputDatum = case transferDatum $ txOutDatumHash ownOutput >>= flip findDatum info of

    Nothing -> traceError "Transfer output datum not found"

    Just d  -> d

However, "txOutDatumHash" seems to be missing a corresponding implementation in V2. I understand we may face inline Datum, which would not include the Hash, but backward compatibility appears to not be fully implemented on this function. From the plutus-apps examples, I noticed a mixture of V1 modules whenever the datum was being verified. PS: transferDatum :: Maybe Datum -> Maybe EkivalEscrowDatum

2 Answers 2

0

For plutus v2 you have to differentiate since inline datums could be present at a given output.

outputDatumByHash :: DatumHash -> Maybe Datum
outputDatumByHash h = findDatum h info

ownOutputDatum :: TxOut -> Maybe TransferDatum
ownOutputDatum TxOut{txOutDatum=OutputDatumHash h} = transferDatum $ outputDatumByHash h
ownOutputDatum _                                   = Nothing

outputDatum :: TxOut -> TransferDatum
outputDatum txOut = case ownOutputDatum txOut of
    Nothing -> traceError "Transfer output datum not found"
    Just d  -> d
1

Looking at the API:

V1's TxOut uses txOutDatumHash :: Maybe DatumHash

V2's TxOut uses txOutDatum :: OutputDatum where data OutputDatum = NoOutputDatum | OutputDatumHash DatumHash | OutputDatum Datum

So V2 still has DatumHash but you need to also handle the possibility of OutputDatum (inline datum).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.