ouroboros-network icon indicating copy to clipboard operation
ouroboros-network copied to clipboard

Improve the tx submission reponse

Open erikd opened this issue 5 years ago • 7 comments

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.

erikd avatar Feb 14 '20 01:02 erikd

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.

erikd avatar Feb 14 '20 03:02 erikd

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.

dcoutts avatar Feb 14 '20 07:02 dcoutts

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.

erikd avatar Feb 14 '20 07:02 erikd

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.

coot avatar Feb 14 '20 08:02 coot

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.

erikd avatar Feb 14 '20 08:02 erikd

Yes, the intention is to solve your original problem of looking around the code how to do things.

coot avatar Feb 14 '20 08:02 coot

I like the ApplyMempoolPayloadResult/ApplyMempoolPayloadStatus approach.

intricate avatar Feb 14 '20 15:02 intricate