From fbfa4e915ceee98e0fa5459caa26e222f5602bbc Mon Sep 17 00:00:00 2001 From: Mathieu Montin Date: Thu, 21 Mar 2024 16:04:26 +0100 Subject: [PATCH] Unresolved `TxOut` pretty printing bug resolution (#387) Fixing txout printing resolution bug --- src/Cooked/Pretty/Cooked.hs | 27 +++++++++------------------ src/Cooked/Pretty/Options.hs | 2 +- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/src/Cooked/Pretty/Cooked.hs b/src/Cooked/Pretty/Cooked.hs index 999c4e46b..bc8be0fe3 100644 --- a/src/Cooked/Pretty/Cooked.hs +++ b/src/Cooked/Pretty/Cooked.hs @@ -334,27 +334,18 @@ prettyTxSkelInReference opts skelContext txOutRef = do ) getReferenceScriptDoc :: (IsAbstractOutput output, ToScriptHash (ReferenceScriptType output)) => PrettyCookedOpts -> output -> Maybe DocCooked -getReferenceScriptDoc opts output = - case output ^. outputReferenceScriptL of - Nothing -> Nothing - Just refScript -> - Just $ - "Reference script hash:" - <+> prettyHash (pcOptHashes opts) (toHash . toScriptHash $ refScript) +getReferenceScriptDoc opts output = prettyReferenceScriptHash opts . toScriptHash <$> output ^. outputReferenceScriptL -lookupOutput :: - SkelContext -> - Pl.TxOutRef -> - Maybe (Pl.TxOut, TxSkelOutDatum) +lookupOutput :: SkelContext -> Pl.TxOutRef -> Maybe (Pl.TxOut, TxSkelOutDatum) lookupOutput (SkelContext managedTxOuts managedTxSkelOutDatums) txOutRef = do output <- Map.lookup txOutRef managedTxOuts - datumHash <- - case outputOutputDatum output of - Pl.OutputDatum datum -> return (Pl.datumHash datum) - Pl.OutputDatumHash datumHash -> return datumHash - Pl.NoOutputDatum -> Nothing - txSkelOutDatum <- Map.lookup datumHash managedTxSkelOutDatums - return (output, txSkelOutDatum) + return + ( output, + case outputOutputDatum output of + Pl.OutputDatum datum -> Map.findWithDefault TxSkelOutNoDatum (Pl.datumHash datum) managedTxSkelOutDatums + Pl.OutputDatumHash datumHash -> Map.findWithDefault TxSkelOutNoDatum datumHash managedTxSkelOutDatums + Pl.NoOutputDatum -> TxSkelOutNoDatum + ) -- | Pretty-print a list of transaction skeleton options, only printing an -- option if its value is non-default. If no non-default options are in the diff --git a/src/Cooked/Pretty/Options.hs b/src/Cooked/Pretty/Options.hs index 0c31445ac..65be14a79 100644 --- a/src/Cooked/Pretty/Options.hs +++ b/src/Cooked/Pretty/Options.hs @@ -1,6 +1,5 @@ {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE TypeSynonymInstances #-} -- | Pretty-printing options for 'prettyCookedOpt' and their default values. module Cooked.Pretty.Options @@ -8,6 +7,7 @@ module Cooked.Pretty.Options PrettyCookedHashOpts (..), PCOptTxOutRefs (..), hashNamesFromList, + defaultHashNames, ) where