tweag / cooked-validators

MIT License
39 stars 11 forks source link

Cleaner implementation of the output types #205

Closed carlhammann closed 1 year ago

carlhammann commented 1 year ago

@florentc had the idea to implement functions like utxosSuchThat as a sequence of filter/converter functions on the new output types. Here is a first example of how that could look. In particular, I decided to throw away utxosSuchThat as a primitive of MonadBlockChain in favour of allUtxos :: MonadBlockChain m => m [(Pl.TxOutRef, Pl.TxOut)].

This is also where the meat in this PR lies:

  1. I noticed that the GenericOutput is essentially isomorphic to Pl.TxOut. That is: Why not make Pl.TxOut our "generic output"? -- It's straightforward to make it an instance of IsOutput.
  2. All of the more specialised output types can be unified under one type ConcreteOutput, which has two parameters: One for the owner type (which could be public key, typed validator, etc.) and one for the datum type (which could be unit, datum hash, typed datum, etc.). This greatly reduces boilerplate, and also makes it easy to write the filter/converter functions
  3. Finally, we can reactivate the idea from PR #203 to have a type with two isomorphic constructors distinguishing between datum hashes and inline datums on transaction outputs: We simply make that type the DatumType of transaction outputs, as exemplified by the paysScript and paysScriptInlineDatum smart constructors.