IntersectMBO / plutus-apps

The Plutus application platform
Apache License 2.0
306 stars 214 forks source link

fromCardanoTxOutDatum is creating OutputDatumHash but receiving TxOutDatumInTx #1060

Closed manupadillaph closed 1 year ago

manupadillaph commented 1 year ago

Summary

The method fromCardanoTxOutDatum to convert from C.TxOutDatum C.CtxTx era to PV2.OutputDatum is creating a OutputDatumHash when is receiving a datum in the type of TxOutDatumInTx, instead of returning a PV2.OutputDatum.

Don't know if it is intentional or a bug.

fromCardanoTxOutDatum :: C.TxOutDatum C.CtxTx era -> PV2.OutputDatum   
fromCardanoTxOutDatum C.TxOutDatumNone       =   
    PV2.NoOutputDatum    
fromCardanoTxOutDatum (C.TxOutDatumHash _ h) =   
    PV2.OutputDatumHash $ PV2.DatumHash $ PlutusTx.toBuiltin (C.serialiseToRawBytes h)   

-- HERE --> 
fromCardanoTxOutDatum (C.TxOutDatumInTx _ d) =    
    PV2.OutputDatumHash $ PV2.DatumHash $ PlutusTx.toBuiltin (C.serialiseToRawBytes (C.hashScriptData d))   
-- <---  

fromCardanoTxOutDatum (C.TxOutDatumInline _ d) =   
    PV2.OutputDatum $ PV2.Datum $ fromCardanoScriptData d   

Steps to reproduce the behavior

Use the method to convert a datum with era, attached to a tx, TxOutDatumInTx , to a OutputDatum and you will get only the hash. Not the body of the datum.

Actual Result

The Hash of the TxOutDatumHash

Expected Result

To get the body of the datum

Describe the approach you would take to fix this

Change this line in plutus-ledger/src/Ledger/Tx/CardanoAPI/Internal.hs


fromCardanoTxOutDatum :: C.TxOutDatum C.CtxTx era -> PV2.OutputDatum   
fromCardanoTxOutDatum C.TxOutDatumNone       =   
    PV2.NoOutputDatum    
fromCardanoTxOutDatum (C.TxOutDatumHash _ h) =   
    PV2.OutputDatumHash $ PV2.DatumHash $ PlutusTx.toBuiltin (C.serialiseToRawBytes h)   

-- HERE --> 
fromCardanoTxOutDatum (CardanoApi.TxOutDatumInTx _ d) =   
    PV2.OutputDatum $ PV2.Datum $ fromCardanoScriptData d  
-- <---  

fromCardanoTxOutDatum (C.TxOutDatumInline _ d) =   
    PV2.OutputDatum $ PV2.Datum $ fromCardanoScriptData d  

System info

Plutus v1.1.0 and 1.2.0

catch-21 commented 1 year ago

It is intentional.

If using TxOutDatumInTx, you must query the blockchain for the datum value. E.g. using a chain follower like db-sync.