Skip to content

Commit

Permalink
Adapt cardano-ledger-pretty to MultiAsset mint field
Browse files Browse the repository at this point in the history
  • Loading branch information
teodanciu committed Aug 8, 2022
1 parent eefccbd commit bbe5280
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ((<+>))
Expand Down Expand Up @@ -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))
Expand Down
27 changes: 17 additions & 10 deletions libs/cardano-ledger-pretty/src/Cardano/Ledger/Pretty/Mary.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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) =
Expand Down

0 comments on commit bbe5280

Please sign in to comment.