cooked-validators
Safe HaskellSafe-Inferred
LanguageHaskell2010

Cooked.Pretty

Description

This module exposes off-chain pretty-printing functions for transaction skeletons, utxo states, addresses, pubkey hashes, values, etc.

We provide the PrettyCooked class and instances for common Plutus types. We don't rely on Pretty from Prettyprinter in order to define better printers for Plutus types which already have instances of Pretty. Also, PrettyCooked makes it possible to optionally modify pretty printing settings PrettyCookedOpts (e.g. length of printed hashes).

Requirements on datum and redeemers

Datums and redeemers are required to have a PrettyCooked instance.

For trivial datatypes, you can rely on Show by using viaShow from Prettyprinter: prettyCooked = Prettyprinter.viaShow.

For more complex datatypes, you can rely on existing PrettyCooked instances. Prefer implementing the prettyCookedOpt function and relay the PrettyCookedOpts settings to other printers.

@ data Foo = Bar Api.Value | Baz Api.PubkeyHash Api.Value

instance PrettyCooked Foo where prettyCookedOpt pcOpts (Bar value) = Bar + prettyCookedOpt pcOpts value prettyCookedOpt pcOpts (Baz pkh value) = prettyItemize Baz "-" [ "user:" + prettyCookedOpt pcOpts pkh, "deposit:" + prettyCookedOpt pcOpts value ] @

The prettyItemize function is useful to nicely lay down nested lists of elements. Since we manipulate regular Doc values, any function from Prettyprinter can be used to implement your printers.

How to pretty print?

Pretty printing of transaction skeletons and UTxO states is done automatically by the end-user functions provided in Cooked.MockChain.Testing.

To do it manually, use instances of PrettyCooked, PrettyCookedList or PrettyCookedMaybe defined in Skeleton or MockChain such as the one for MockChainReturn a UtxoState.

Synopsis

Documentation

type DocCooked = Doc () Source #

A standard Doc without any annotation

class PrettyCooked a where Source #

Type class of things that can be pretty printed as a single document. You need to implement either prettyCookedOpt or prettyCooked manually, otherwise calling either of them will resulting in a infinite loop.

Minimal complete definition

Nothing

Methods

prettyCookedOpt :: PrettyCookedOpts -> a -> DocCooked Source #

Pretty prints an element based on some PrettyCookedOpts

prettyCooked :: a -> DocCooked Source #

Pretty prints an element directly

Instances

Instances details
PrettyCooked Rational Source # 
Instance details

Defined in Cooked.Pretty.Class

PrettyCooked AddTokenLbl Source # 
Instance details

Defined in Cooked.Attack.AddToken

PrettyCooked DatumHijackingLbl Source # 
Instance details

Defined in Cooked.Attack.DatumHijacking

PrettyCooked DoubleSatLbl Source # 
Instance details

Defined in Cooked.Attack.DoubleSat

PrettyCooked DupTokenLbl Source # 
Instance details

Defined in Cooked.Attack.DupToken

PrettyCooked MockChainError Source # 
Instance details

Defined in Cooked.Pretty.MockChain

PrettyCooked MockChainLogEntry Source #

This prints a MockChainLogEntry. In the log, we know a transaction has been validated if the MCLogSubmittedTxSkel is followed by a MCLogNewTx.

Instance details

Defined in Cooked.Pretty.MockChain

PrettyCooked UtxoState Source #

Pretty print a UtxoState. Print the known wallets first, then unknown pubkeys, then scripts.

Instance details

Defined in Cooked.Pretty.MockChain

PrettyCooked DocCooked Source # 
Instance details

Defined in Cooked.Pretty.Class

PrettyCooked TxLabel Source # 
Instance details

Defined in Cooked.Skeleton.Label

PrettyCooked Mint Source #

Prints a minting specification

Example: > #abcdef - Redeemer: red - Reference script at: txOutRef - Foo: 500 - Bar: 1000

Instance details

Defined in Cooked.Pretty.Skeleton

PrettyCooked TxSkelOut Source # 
Instance details

Defined in Cooked.Pretty.Skeleton

PrettyCooked TxGovAction Source # 
Instance details

Defined in Cooked.Pretty.Skeleton

PrettyCooked TxParameterChange Source # 
Instance details

Defined in Cooked.Pretty.Skeleton

PrettyCooked MalformDatumLbl Source # 
Instance details

Defined in Cooked.Tweak.Outputs

PrettyCooked TamperDatumLbl Source # 
Instance details

Defined in Cooked.Tweak.Outputs

PrettyCooked Wallet Source # 
Instance details

Defined in Cooked.Pretty.Skeleton

PrettyCooked ValidationError Source # 
Instance details

Defined in Cooked.Pretty.Plutus

PrettyCooked ValidationPhase Source # 
Instance details

Defined in Cooked.Pretty.Plutus

PrettyCooked Address Source # 
Instance details

Defined in Cooked.Pretty.Plutus

PrettyCooked Credential Source # 
Instance details

Defined in Cooked.Pretty.Plutus

PrettyCooked ScriptError Source # 
Instance details

Defined in Cooked.Pretty.Plutus

PrettyCooked POSIXTime Source # 
Instance details

Defined in Cooked.Pretty.Plutus

PrettyCooked AssetClass Source # 
Instance details

Defined in Cooked.Pretty.Plutus

PrettyCooked Value Source # 
Instance details

Defined in Cooked.Pretty.Plutus

PrettyCooked TxOutRef Source # 
Instance details

Defined in Cooked.Pretty.Plutus

PrettyCooked BuiltinData Source # 
Instance details

Defined in Cooked.Pretty.Plutus

PrettyCooked Integer Source # 
Instance details

Defined in Cooked.Pretty.Class

PrettyCooked () Source # 
Instance details

Defined in Cooked.Pretty.Class

PrettyCooked Bool Source # 
Instance details

Defined in Cooked.Pretty.Class

PrettyCooked Int Source # 
Instance details

Defined in Cooked.Pretty.Class

PrettyCooked [MockChainLogEntry] Source # 
Instance details

Defined in Cooked.Pretty.MockChain

Show a => PrettyCooked (MockChainReturn a UtxoState) Source # 
Instance details

Defined in Cooked.Pretty.MockChain

Show a => PrettyCooked (a, UtxoState) Source # 
Instance details

Defined in Cooked.Pretty.MockChain

class PrettyCookedList a where Source #

Type class of things that can be pretty printed as a list of documents. Similarly to PrettyCooked, at least of the functions from this class needs to be manually implemented to avoid infinite loops.

Minimal complete definition

Nothing

Methods

prettyCookedOptList :: PrettyCookedOpts -> a -> [DocCooked] Source #

Pretty prints an element as a list on some PrettyCookedOpts

prettyCookedOptListMaybe :: PrettyCookedOpts -> a -> [Maybe DocCooked] Source #

Pretty prints an element as a list of optional documents

prettyCookedList :: a -> [DocCooked] Source #

Pretty prints an elements as a list

Instances

Instances details
PrettyCookedList UtxoPayloadSet Source #

Pretty prints the state of an address, that is the list of UTxOs (including value and datum), grouped

Instance details

Defined in Cooked.Pretty.MockChain

PrettyCookedList TxOpts Source #

Pretty-print a list of transaction skeleton options, only printing an option if its value is non-default.

Instance details

Defined in Cooked.Pretty.Skeleton

PrettyCookedList TxSkelProposal Source # 
Instance details

Defined in Cooked.Pretty.Skeleton

PrettyCookedList TxSkelRedeemer Source #

Prints a list of docs corresponding to an instance of TxSkelRedeemer

Instance details

Defined in Cooked.Pretty.Skeleton

PrettyCooked a => PrettyCookedList (Set a) Source # 
Instance details

Defined in Cooked.Pretty.Class

PrettyCookedList (Contextualized TxSkel) Source #

Prints a Contextualized TxSkel

Instance details

Defined in Cooked.Pretty.Skeleton

PrettyCookedList (Contextualized TxOutRef) Source #

Resolves a TxOutRef from a given context, builds a doc cooked for its address and value, and also builds a possibly empty list for its datum and reference script when they exist.

Instance details

Defined in Cooked.Pretty.Skeleton

PrettyCooked a => PrettyCookedList [a] Source # 
Instance details

Defined in Cooked.Pretty.Class

PrettyCookedList (TxOpts, [Wallet]) Source #

Prints a list of pubkeys with a flag next to the balancing wallet

Instance details

Defined in Cooked.Pretty.Skeleton

class PrettyCookedMaybe a where Source #

Type class of things that can be optionally pretty printed as a document

Minimal complete definition

Nothing

Methods

prettyCookedOptMaybe :: PrettyCookedOpts -> a -> Maybe DocCooked Source #

Pretty prints an optional document on some PrettyCookedOpts

prettyCookedMaybe :: a -> Maybe DocCooked Source #

Pretty prints an option document

class ToHash a where Source #

Hashable elements can be transformed to BuiltinByteString

Instances

Instances details
ToHash Wallet Source # 
Instance details

Defined in Cooked.Pretty.Hashable

ToHash PubKeyHash Source # 
Instance details

Defined in Cooked.Pretty.Hashable

ToHash DatumHash Source # 
Instance details

Defined in Cooked.Pretty.Hashable

ToHash ScriptHash Source # 
Instance details

Defined in Cooked.Pretty.Hashable

ToHash CurrencySymbol Source # 
Instance details

Defined in Cooked.Pretty.Hashable

ToHash TokenName Source # 
Instance details

Defined in Cooked.Pretty.Hashable

ToHash TxId Source # 
Instance details

Defined in Cooked.Pretty.Hashable

ToHash ValidatorHash Source # 
Instance details

Defined in Cooked.Pretty.Hashable

ToHash (Versioned MintingPolicy) Source # 
Instance details

Defined in Cooked.Pretty.Hashable

ToHash (Versioned Script) Source # 
Instance details

Defined in Cooked.Pretty.Hashable

ToHash (TypedValidator a) Source # 
Instance details

Defined in Cooked.Pretty.Hashable

ToHash (MultiPurposeScript a) Source # 
Instance details

Defined in Cooked.Pretty.Hashable

data PrettyCookedOpts Source #

A set of option to pilot pretty printing in cooked-validators

Constructors

PrettyCookedOpts 

Fields

data PrettyCookedHashOpts Source #

A set of options to pilot how hashes are pretty printed

Constructors

PrettyCookedHashOpts 

Fields

  • pcOptHashLength :: Int

    Length of printed hash prefix. By default: 7

  • pcOptHashNames :: Map BuiltinByteString String

    Association between hashes and given names to ease readability. For example Map.singleton (walletPKHash (wallet 1)) Alice By default: "defaultHashNames" which assigns Lovelace, Quick, and Permanent as names for the associated currency symbols

  • pcOptHashVerbose :: Bool

    When a given name exists for a hash, this flag also prints the original hash after the name. By default: False

data PCOptTxOutRefs Source #

Whether to print transaction outputs references.

Constructors

PCOptTxOutRefsHidden

Hide them

PCOptTxOutRefsFull

Always show them.

Warning: this will disable printing similar UTxOs as a group (for instance (×10) Lovelace: 100_000_000)

PCOptTxOutRefsPartial

Show them for UTxOs which are not grouped with similar others. This avoids the downside of PCOptTxOutRefsFull which disables printing UTxOs as a group.

Instances

Instances details
Show PCOptTxOutRefs Source # 
Instance details

Defined in Cooked.Pretty.Options

Eq PCOptTxOutRefs Source # 
Instance details

Defined in Cooked.Pretty.Options

renderString :: (a -> DocCooked) -> a -> String Source #

Use this to convert a pretty-printer to a regular show function using default layout options. This is used in Testing because Tasty uses strings.

printCookedOpt :: PrettyCooked a => PrettyCookedOpts -> a -> IO () Source #

Use this in the REPL as an alternative to the default print function when dealing with pretty-printable cooked values.

For example, printCookedOpt def runMockChain i0 foo

printCooked :: PrettyCooked a => a -> IO () Source #

Version of printCookedOpt that uses default pretty printing options.

prettyHash :: ToHash a => PrettyCookedOpts -> a -> DocCooked Source #

Pretty prints hashable elements based on pcOptHashes in the PrettyCookedOpts. This cannot be made an instance as it would be undecidable (the hope was (ToHash a) => PrettyCooked a)

prettyItemize :: PrettyCookedList a => PrettyCookedOpts -> DocCooked -> DocCooked -> a -> DocCooked Source #

Print an item list with a title

>>> prettyCookedOpts opts "Foo" "-" ["bar1", "bar2", "bar3"]
Foo
  - bar1
  - bar2
  - bar3

prettyItemizeNoTitle :: PrettyCookedList a => PrettyCookedOpts -> DocCooked -> a -> DocCooked Source #

Print an item list without a title

prettyItemizeNonEmpty :: PrettyCookedList a => PrettyCookedOpts -> DocCooked -> DocCooked -> a -> Maybe DocCooked Source #

Print an item list with a title, but only when the list is non-empty

hashNamesFromList :: ToHash a => [(a, String)] -> Map BuiltinByteString String Source #

Smart constructor for maps to be used in the "pcOptHashNames" pretty-printing option.

defaultHashNames :: Map BuiltinByteString String Source #

Default hash to names map that assigns Lovelace, Quick, and Permanent to the associated currency symbols. This is used as the default for the pretty-printing option and is recommended to use as a basis to extend with custom names.

addHashNames :: Map BuiltinByteString String -> PrettyCookedOpts -> PrettyCookedOpts Source #

Adds some additional names to these pretty cooked options. This has two practical use cases:

  • Users can use it in conjuction to hashNamesFromList without having to remember to manually invoke defaultHashNames
  • We use it internally to account for names that have been registered during mockchain runs, such as for names that depend on on-chain data, typically a TxOutRef.