From 965b466d757f0670961caba940d42dce1adb3d90 Mon Sep 17 00:00:00 2001 From: Jordan Millar Date: Tue, 26 Nov 2024 13:57:52 -0400 Subject: [PATCH] Misc refactors in pretty printing and replacing unnecessary function definitions --- .../Cardano/CLI/EraBased/Run/Transaction.hs | 21 ++++++------------- .../Types/Errors/PlutusScriptDecodeError.hs | 6 +++--- .../CLI/Types/Errors/ScriptDataError.hs | 8 +++---- .../CLI/Types/Errors/ScriptDecodeError.hs | 6 +++--- 4 files changed, 16 insertions(+), 25 deletions(-) diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs index 93cc93f88..084493c27 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs @@ -1226,12 +1226,12 @@ getAllReferenceInputs votingProceduresAndMaybeScriptWits propProceduresAnMaybeScriptWits readOnlyRefIns = do - let txinsWitByRefInputs = [getReferenceInput sWit | (_, Just sWit) <- txins] - mintingRefInputs = map getReferenceInput mintWitnesses - certsWitByRefInputs = [getReferenceInput sWit | (_, Just sWit) <- certFiles] - withdrawalsWitByRefInputs = [getReferenceInput sWit | (_, _, Just sWit) <- withdrawals] - votesWitByRefInputs = [getReferenceInput sWit | (_, Just sWit) <- votingProceduresAndMaybeScriptWits] - propsWitByRefInputs = [getReferenceInput sWit | (_, Just sWit) <- propProceduresAnMaybeScriptWits] + let txinsWitByRefInputs = [getScriptWitnessReferenceInput sWit | (_, Just sWit) <- txins] + mintingRefInputs = map getScriptWitnessReferenceInput mintWitnesses + certsWitByRefInputs = [getScriptWitnessReferenceInput sWit | (_, Just sWit) <- certFiles] + withdrawalsWitByRefInputs = [getScriptWitnessReferenceInput sWit | (_, _, Just sWit) <- withdrawals] + votesWitByRefInputs = [getScriptWitnessReferenceInput sWit | (_, Just sWit) <- votingProceduresAndMaybeScriptWits] + propsWitByRefInputs = [getScriptWitnessReferenceInput sWit | (_, Just sWit) <- propProceduresAnMaybeScriptWits] concatMap catMaybes @@ -1243,15 +1243,6 @@ getAllReferenceInputs , propsWitByRefInputs , map Just readOnlyRefIns ] - where - getReferenceInput - :: ScriptWitness witctx era -> Maybe TxIn - getReferenceInput sWit = - case sWit of - PlutusScriptWitness _ _ (PReferenceScript refIn) _ _ _ -> Just refIn - PlutusScriptWitness _ _ PScript{} _ _ _ -> Nothing - SimpleScriptWitness _ (SReferenceScript refIn) -> Just refIn - SimpleScriptWitness _ SScript{} -> Nothing toAddressInAnyEra :: CardanoEra era diff --git a/cardano-cli/src/Cardano/CLI/Types/Errors/PlutusScriptDecodeError.hs b/cardano-cli/src/Cardano/CLI/Types/Errors/PlutusScriptDecodeError.hs index e00583b19..22dc7efad 100644 --- a/cardano-cli/src/Cardano/CLI/Types/Errors/PlutusScriptDecodeError.hs +++ b/cardano-cli/src/Cardano/CLI/Types/Errors/PlutusScriptDecodeError.hs @@ -29,6 +29,6 @@ instance Error PlutusScriptDecodeError where prettyError err PlutusScriptDecodeErrorVersionMismatch version (AnyPlutusScriptVersion v) -> "Version mismatch in code: script version that was read" - <> pretty version - <> " but tried to decode script version: " - <> pshow v + <+> pretty version + <+> " but tried to decode script version: " + <+> pshow v diff --git a/cardano-cli/src/Cardano/CLI/Types/Errors/ScriptDataError.hs b/cardano-cli/src/Cardano/CLI/Types/Errors/ScriptDataError.hs index aa994380c..e80265297 100644 --- a/cardano-cli/src/Cardano/CLI/Types/Errors/ScriptDataError.hs +++ b/cardano-cli/src/Cardano/CLI/Types/Errors/ScriptDataError.hs @@ -24,12 +24,12 @@ renderScriptDataError = \case ScriptDataErrorFile err -> prettyError err ScriptDataErrorJsonParse fp jsonErr -> - "Invalid JSON format in file: " <> pshow fp <> "\nJSON parse error: " <> pretty jsonErr + "Invalid JSON format in file:" <+> pshow fp <> "\nJSON parse error:" <+> pretty jsonErr ScriptDataErrorConversion fp sDataJsonErr -> - "Error reading metadata at: " <> pshow fp <> "\n" <> prettyError sDataJsonErr + "Error reading metadata at:" <+> pshow fp <> "\n" <> prettyError sDataJsonErr ScriptDataErrorValidation fp sDataRangeErr -> - "Error validating script data at: " <> pshow fp <> ":\n" <> prettyError sDataRangeErr + "Error validating script data at:" <+> pshow fp <> ":\n" <> prettyError sDataRangeErr ScriptDataErrorMetadataDecode fp decoderErr -> - "Error decoding CBOR metadata at: " <> pshow fp <> " Error: " <> pshow decoderErr + "Error decoding CBOR metadata at:" <+> pshow fp <+> "Error:" <+> pshow decoderErr ScriptDataErrorJsonBytes e -> prettyError e diff --git a/cardano-cli/src/Cardano/CLI/Types/Errors/ScriptDecodeError.hs b/cardano-cli/src/Cardano/CLI/Types/Errors/ScriptDecodeError.hs index 7ba879c59..b320c5715 100644 --- a/cardano-cli/src/Cardano/CLI/Types/Errors/ScriptDecodeError.hs +++ b/cardano-cli/src/Cardano/CLI/Types/Errors/ScriptDecodeError.hs @@ -22,8 +22,8 @@ data ScriptDecodeError instance Error ScriptDecodeError where prettyError = \case ScriptDecodeTextEnvelopeError err -> - "Error decoding script: " <> prettyError err + "Error decoding script:" <+> prettyError err ScriptDecodeSimpleScriptError err -> - "Syntax error in script: " <> prettyError err + "Syntax error in script:" <+> prettyError err ScriptDecodeUnknownPlutusScriptVersion version -> - "Unknown Plutus script version: " <> pshow version + "Unknown Plutus script version:" <+> pshow version