Improve the tx submission reponse
Currently in the cardano-tx-submit-webapi I use a pair ot StrictTMVars to submit a transaction to the network and get the response. The type of the response is Maybe ApplyMempoolPayloadErr which is returns either an error in the Just or Nothing if the submission is successful.
For something like the cardano-tx-submit-webapi for a succesful submission, I would like return the transaction id to the caller. With the current types that is not possible.
Had a look at the code for this and there does not see to be a simple way to fix this. I suspect the easiest and best solution would be to change from Maybe ApplyMempoolPayloadErr to Either ApplyMempoolPayloadErr TxId.
Note that the protocol itself does not return the txid, just a success indicator. This is fine since the txid can be computed locally. So the web api can compute and return the txid in the case that the tx is submitted successfully.
Chatted with Duncan and we concluded that Either ApplyMempoolPayloadErr () makes more sense (and is more iniuitive) than Maybe ApplyMempoolPayloadErr. The TxId can be extracted from the Tx locally.
Yes, I agree, Nothing :: Maybe a indicating a successful operation is unintuitive. What about returning:
data ApplyMempoolResult
= ApplyMempoolError ApplyMempoolPayloadErr
| ApplyMempoolSuccess
^ -- successful transaction submission, `TxId` is not returned as it can be computed locally.
The main advantage over Either is the haddock documentation.
Yeah, that is at least as good as the EIther I suggested. Especially if the haddock for ApplyMempoolSuccess suggests that the TxId is not needed because its is already available on the submission side.
Yes, the intention is to solve your original problem of looking around the code how to do things.
I like the ApplyMempoolPayloadResult/ApplyMempoolPayloadStatus approach.