Every UTXO at a script address must have a TxOutDatumHash (or will be unspendable). To spend the UTXO at the validator you provide a datum and a redeemer, the script must validate with your redeemer, and the datum you provide must hash to the TxOutDatumHash of the UTXO you're spending. The problem, as discussed in CIP-32:
This is quite inconvenient for users. Datums tend to represent the result of computation done by the party who creates the output, and as such there is almost no chance that the spending party will know the datum without communicating with the creating party. That means that either the datum must be communicated between parties off-chain, or communicated on-chain by attaching it to the transaction that creates the output (which is also inconvenient in that the spending party must watch the whole chain to spot it).
But when I look at the code of, for example, the Oracle in Week 6 (or even the English Auction in Week 1), there seems to be a way of pulling the original datum from somewhere:
x <- oracleValue (txOutTxOut o) $ \dh -> Map.lookup dh $ txData $ txOutTxTx o
(source)
Can someone please explain what is happening here? I assume it is the "on-chain communication" technique that the CIP mentions. Does the datum need to be explicitly handled in a particular way for this to be possible? What are txOutTxOut
and txOutTxTx
? Thanks!