tweag / cooked-validators

MIT License
39 stars 11 forks source link

Add custom names pretty printing for hashes #384

Closed florentc closed 3 months ago

florentc commented 3 months ago

This addresses #379

This PR introduces a quality of life feature to associate readable names to hashes in a new pretty-pretting option.

The option is grouped among others in the pcOptHashes field of PrettyCookedOpts. This field has the following subfields:

Example:

pcOpts :: C.PrettyCookedOpts
pcOpts =
  def
    { C.pcOptHashes =
        def
          { C.pcOptHashNames =
              defaultHashNames
                <> C.hashNamesFromList
                  [ (alice, "Alice"),
                    (bob, "Bob"),
                    (carrie, "Carie")
                  ]
                <> C.hashNamesFromList
                  [ (nftCurrencySymbol, "NFT"),
                    (customCoinsCurrencySymbol, "Custom Coins")
                  ]
                <> C.hashNamesFromList
                  [ (fooValidator, "Foo")
                  ]
          }
    }

TODO and discussion topics

mmontin commented 3 months ago

Maybe stop displaying "pubkey" vs "script" as a prefix when a hash has been resolved to a name (I lean towards keeping it)

I lean towards keeping it either. It does not hurt and bring an info that somebody who has not worked on a codebase will need in order to understand the outcome of a trace.

Investigate or postpone to future PR the token name parsing

I believe it should be postponed.

Experiment with highlighting names from the rest of the text. Hashes where easy to spot because of the # and hexadecimal characters. Now names, in particular if they have spaces or are lowercased, can be hard to notice in the middle of the text. For example Spends from script foo (Reference Script at 28282838!0), or Pays to pubkey Clint Eastwood could become Pays to pubkey [Clint Eastwood] or Spends from script [foo], Pays to pubkey #"Clint Eastwood", etc. (I'd keep it like it is for now)

It could be good indeed to have names highlighted. Now that I think about it, there could be a different highlight if it's a script or a pubkey, which would also kinda solve the first question. Something like script@[myscript] and pkh@[mypkh]

Investigate using existential types or something to avoid having to split the names into several sublists for each concrete type. (That would be nice to have)

I'd say that would be nice to have but not mandatory. It practice, the only way I see that happening is by having a list of types as a type or something like that which would require type families.

There was a hardcoded check to print "Lovelace"/"Quick"/"Permanent" for the relevant currency symbols. Should this now be moved to the default name table (which would contain those 3 elements instead of being empty by default)? (I find it would be conceptually more elegant but maybe prone to accidental overwrites in practice)

I like the idea of having the 3 by default. And if in turn the user overrides it, well it's ok.

florentc commented 3 months ago

This PR is ready for review. The first post has been edited accordingly.

Decisions regarding the discussion items:

In addition: