@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:
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.
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
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.
@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 awayutxosSuchThat
as a primitive ofMonadBlockChain
in favour ofallUtxos :: MonadBlockChain m => m [(Pl.TxOutRef, Pl.TxOut)]
.This is also where the meat in this PR lies:
GenericOutput
is essentially isomorphic toPl.TxOut
. That is: Why not makePl.TxOut
our "generic output"? -- It's straightforward to make it an instance ofIsOutput
.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 functionsDatumType
of transaction outputs, as exemplified by thepaysScript
andpaysScriptInlineDatum
smart constructors.