tweag / cooked-validators

MIT License
39 stars 11 forks source link

Reference inputs and reference scripts #217

Closed carlhammann closed 1 year ago

carlhammann commented 1 year ago

This PR brings

A separation of output type interfaces

This was discussed in this thread. We now have a class IsAbstractOutput, and a constraint type IsOnchainOutput, which imposes restrictions on the type families in the IsAbstractOutput. I think it'd be worthwhile to (on one of the clean-up PRs to come in the next few days):

Reference inputs

There's now a field txSkelInsReference :: TxSkel -> Set Pl.TxOutRef on the TxSkel which behaves in the expected way.

Reference scripts

Reference scripts are used as demonstrated in their test module, but I'll still summarise how to use them here, because the subject is relatively subtle.

To use a script s as a reference script, you must

  1. Create an output that contains the s. It's possible in principle for this output to belong to a script or a private key (there are tests for both), but I'm not sure what the difference in meaning is. For the latter case, here's a smart constructor for TxSkelOut. In any case, the output at which the script resides will have a TxOutRef, which we'll call o.
  2. Spend an output belonging to s, while using TxSkelRedeemerForReferencedScript to provide the redeemer, and include o in the txSkelInsReference.
    • If you forget to include o on the transaction, you will get this error from transaction generation.
    • If you include o on the transaction and use TxSkelRedeemerForScript, you will get a phase 1 error from the ledger complaining that the script is included twice on the transaction.

Edit: What I think still needs to be done before merging

mmontin commented 1 year ago

Before I dive a bit more into details, I have a few questions/remarks

carlhammann commented 1 year ago

I think this is in a mergeable state now. The one point that's missing about the pretty-printing business will come on a separate PR.