The SpendsScript constraint has a parameter for the datum which is annoying and redundant with the spendable output itself. This was necessary to pretty print these constraints. This PR removes the parameter, keeps pretty-printing as it was, and adds convenience functions to write cleaner endpoints & traces.
[x] TODO: adapt attack modules
[x] TODO: adapt examples in the examples package
Look at each commit of this PR to get a better grasp at individual changes.
The Example module showcases the changes. (you will need to disable the attack modules and tests if you want to try until these are adapted)
Main changes
The datum is no longer a parameter of SpendsScript
Pretty printing has been adapted to extract the datum from the spendable out instead
BlockChain has a new operation: datumFromTxOut (which only existed for the Contract monad).
New convenience functions spOutResolveDatum and spOutsFromCardanoTx that make use of datumFromTxOut. It is useful to fetch spendable outputs from freshly validated transactions instead of tediously searching through the whole mockchain afterwards with utxosSuchThat.
Why this works?
A SpendableOut has a Pl.ChainIndexTxOut which contains a datum field. This datum is either (Either) an actual Pl.Datum or a datum hash (Pl.DatumHash).
In practice, the existing classic SpendsScript constraint leads to a runtime error (DatumNotFound from plutus-apps) when the Pl.ChainIndexTxOut only has a hash. This means that we have always been manipulating ChainIndexTxOuts with the actual datum inside (when we fetch one with scriptUtxosSuchThat for instance).
In other words, removing the datum parameter from SpendsScript does not change anything.
On the other hand, script utxos we extract from Pl.CardanoTx only have a hash. This is were the new functions datumFromTxOut, spOutResolveDatum, and spOutsFromCardanoTx come in handy: they look up the hash in the context of a BlockChain so that we have SpendableOuts which are usable by SpendsScript.
This is something that we had not noticed before because we were only using SpendableOuts coming from utxosSuchThat functions.
The
SpendsScript
constraint has a parameter for the datum which is annoying and redundant with the spendable output itself. This was necessary to pretty print these constraints. This PR removes the parameter, keeps pretty-printing as it was, and adds convenience functions to write cleaner endpoints & traces.examples
packageLook at each commit of this PR to get a better grasp at individual changes.
The
Example
module showcases the changes. (you will need to disable the attack modules and tests if you want to try until these are adapted)Main changes
SpendsScript
BlockChain
has a new operation:datumFromTxOut
(which only existed for theContract
monad).spOutResolveDatum
andspOutsFromCardanoTx
that make use ofdatumFromTxOut
. It is useful to fetch spendable outputs from freshly validated transactions instead of tediously searching through the whole mockchain afterwards withutxosSuchThat
.Why this works?
A
SpendableOut
has aPl.ChainIndexTxOut
which contains a datum field. This datum is either (Either
) an actualPl.Datum
or a datum hash (Pl.DatumHash
). In practice, the existing classicSpendsScript
constraint leads to a runtime error (DatumNotFound
from plutus-apps) when thePl.ChainIndexTxOut
only has a hash. This means that we have always been manipulatingChainIndexTxOut
s with the actual datum inside (when we fetch one withscriptUtxosSuchThat
for instance). In other words, removing the datum parameter fromSpendsScript
does not change anything.On the other hand, script utxos we extract from
Pl.CardanoTx
only have a hash. This is were the new functionsdatumFromTxOut
,spOutResolveDatum
, andspOutsFromCardanoTx
come in handy: they look up the hash in the context of aBlockChain
so that we haveSpendableOut
s which are usable bySpendsScript
. This is something that we had not noticed before because we were only usingSpendableOut
s coming fromutxosSuchThat
functions.