From 47d51b39bd7099a4a8e77b00a410077bfa8b1408 Mon Sep 17 00:00:00 2001 From: teodanciu Date: Wed, 3 Aug 2022 16:20:35 +0100 Subject: [PATCH] Adapt cardano-ledger-pretty to `MultiAsset` mint field --- .../src/Cardano/Ledger/Pretty/Alonzo.hs | 4 +-- .../src/Cardano/Ledger/Pretty/Babbage.hs | 4 +-- .../src/Cardano/Ledger/Pretty/Mary.hs | 27 ++++++++++++------- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/libs/cardano-ledger-pretty/src/Cardano/Ledger/Pretty/Alonzo.hs b/libs/cardano-ledger-pretty/src/Cardano/Ledger/Pretty/Alonzo.hs index 3e779c82987..4401ccab1a4 100644 --- a/libs/cardano-ledger-pretty/src/Cardano/Ledger/Pretty/Alonzo.hs +++ b/libs/cardano-ledger-pretty/src/Cardano/Ledger/Pretty/Alonzo.hs @@ -35,7 +35,7 @@ import Cardano.Ledger.AuxiliaryData import Cardano.Ledger.BaseTypes (BoundedRational (unboundRational)) import Cardano.Ledger.Core import Cardano.Ledger.Pretty hiding (ppPParams, ppPParamsUpdate, ppTx, ppTxBody, ppTxOut) -import Cardano.Ledger.Pretty.Mary (ppTimelock, ppValidityInterval, ppValue) +import Cardano.Ledger.Pretty.Mary (ppMultiAsset, ppTimelock, ppValidityInterval) import qualified Plutus.V1.Ledger.Api as Plutus import qualified Prettyprinter as PP @@ -222,7 +222,7 @@ ppTxBody (AlonzoTxBody i ifee o c w fee vi u rsh mnt sdh axh ni) = ("vldt", ppValidityInterval vi), ("update", ppStrictMaybe ppUpdate u), ("reqSignerHashes", ppSet ppKeyHash rsh), - ("mint", ppValue mnt), + ("mint", ppMultiAsset mnt), ("scriptIntegrityHash", ppStrictMaybe ppSafeHash sdh), ("adHash", ppStrictMaybe ppAuxDataHash axh), ("txnetworkid", ppStrictMaybe ppNetwork ni) diff --git a/libs/cardano-ledger-pretty/src/Cardano/Ledger/Pretty/Babbage.hs b/libs/cardano-ledger-pretty/src/Cardano/Ledger/Pretty/Babbage.hs index 72436434509..a13ab96ebc0 100644 --- a/libs/cardano-ledger-pretty/src/Cardano/Ledger/Pretty/Babbage.hs +++ b/libs/cardano-ledger-pretty/src/Cardano/Ledger/Pretty/Babbage.hs @@ -50,7 +50,7 @@ import Cardano.Ledger.Pretty.Alonzo ppExUnits, ppPrices, ) -import Cardano.Ledger.Pretty.Mary (ppValidityInterval, ppValue) +import Cardano.Ledger.Pretty.Mary (ppMultiAsset, ppValidityInterval) import Control.State.Transition.Extended import Data.Maybe.Strict (StrictMaybe (SJust, SNothing)) import Prettyprinter ((<+>)) @@ -246,7 +246,7 @@ ppTxBody x = ("vldt", ppValidityInterval (vldt' x)), ("update", ppStrictMaybe ppUpdate (update' x)), ("reqSignerHashes", ppSet ppKeyHash (reqSignerHashes' x)), - ("mint", ppValue (mint' x)), + ("mint", ppMultiAsset (mint' x)), ("scriptIntegrityHash", ppStrictMaybe ppSafeHash (scriptIntegrityHash' x)), ("adHash", ppStrictMaybe ppAuxDataHash (adHash' x)), ("txnetworkid", ppStrictMaybe ppNetwork (txnetworkid' x)) diff --git a/libs/cardano-ledger-pretty/src/Cardano/Ledger/Pretty/Mary.hs b/libs/cardano-ledger-pretty/src/Cardano/Ledger/Pretty/Mary.hs index 1aae1a150b0..01af8c31888 100644 --- a/libs/cardano-ledger-pretty/src/Cardano/Ledger/Pretty/Mary.hs +++ b/libs/cardano-ledger-pretty/src/Cardano/Ledger/Pretty/Mary.hs @@ -17,24 +17,31 @@ import Cardano.Ledger.ShelleyMA.Timelocks import Cardano.Ledger.ShelleyMA.TxBody import Prettyprinter (hsep, viaShow) -ppValue :: MaryValue crypto -> PDoc -ppValue v = case gettriples' v of - (n, triples, []) -> ppSexp "Value" [ppCoin (Coin n), ppList pptriple triples] - (n, triples, bad) -> ppSexp "Value" [ppCoin (Coin n), ppList pptriple triples, ppString "Bad " <> ppList ppPolicyID bad] - where - pptriple (i, asset, num) = hsep [ppPolicyID i, ppAssetName asset, ppInteger num] - ppPolicyID :: PolicyID crypto -> PDoc ppPolicyID (PolicyID sh) = ppScriptHash sh +instance PrettyA (PolicyID crypto) where prettyA x = ppSexp "PolicyID" [ppPolicyID x] + ppAssetName :: AssetName -> PDoc ppAssetName = viaShow -instance PrettyA (MaryValue crypto) where prettyA = ppValue +instance PrettyA AssetName where prettyA x = ppSexp "AssetName" [ppAssetName x] -instance PrettyA (PolicyID crypto) where prettyA x = ppSexp "PolicyID" [ppPolicyID x] +ppMultiAsset :: MultiAsset crypto -> PDoc +ppMultiAsset m = ppList pptriple (flattenMultiAssets m) + where + pptriple (i, asset, num) = hsep [ppPolicyID i, ppAssetName asset, ppInteger num] -instance PrettyA AssetName where prettyA x = ppSexp "AssetName" [ppAssetName x] +instance CC.Crypto crypto => PrettyA (MultiAsset crypto) where prettyA x = ppSexp "MultiAsset" [ppMultiAsset x] + +ppValue :: MaryValue crypto -> PDoc +ppValue v = case gettriples' v of + (n, triples, []) -> ppSexp "Value" [ppCoin (Coin n), ppList pptriple triples] + (n, triples, bad) -> ppSexp "Value" [ppCoin (Coin n), ppList pptriple triples, ppString "Bad " <> ppList ppPolicyID bad] + where + pptriple (i, asset, num) = hsep [ppPolicyID i, ppAssetName asset, ppInteger num] + +instance PrettyA (MaryValue crypto) where prettyA = ppValue ppTimelock :: CC.Crypto crypto => Timelock crypto -> PDoc ppTimelock (RequireSignature akh) =