tweag / cooked-validators

MIT License
39 stars 11 forks source link

Be more transparent about when 'SpendableOut's contain a datum #169

Closed carlhammann closed 1 year ago

carlhammann commented 1 year ago

A 'SpendableOut' contains a 'ScriptChainIndexTxOut' which can either contain a Left datumhash or a Right datum. In many cases, the datumHash will be resolvable into a datum if, we're in the context of a MonadMockChain. The question is how/if we should distinguish 'SpendableOut's that

on the type level, and how we should make these distinctions in a systematic way.

florentc commented 1 year ago

A straightforward low-effort solution to distinguish at the type level "resolved" vs "unresolved (but maybe resolvable)" would be to introduce a CookedSpOut, counterpart of SpendableOut type that mirrors Pl.ChainIndexTxOut apart from the Either datumHah datum which would be datum.

The current functions that resolve the datum in a BlockChain would have types like spOutResolveDatum :: MonadBlockChain m => SpendableOut -> m CookedSpOut, or spOutsFromCardanoTx :: MonadBlockChain m => Pl.CardanoTx -> m [CookedSpOut]. The SpendsScript constraint would require a CookedSpOut. This would bring some more type safety although this does not answer all the items.

carlhammann commented 1 year ago

I like that idea, but I'd like something like TypedSpOut a. Are there any cases where, with normal use of cooked, we know that there is a datum, but don't know its type?

florentc commented 1 year ago

When validating a transaction that issues new outputs, the returned transactions CardanoTx from which we can later get the corresponding SpendableOuts do not contain type information anymore about the datum. It should be possible to retrieve the info if we know which PaysScript led to these different outputs. I wonder how such an API could look like. But I think there would be a lot of actually unsafe stuff inside the black box if we were to implement it.