Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add forget pending transaction endpoint (Part1) #845

Merged
merged 4 commits into from
Oct 16, 2019

Conversation

paweljakubas
Copy link
Contributor

@paweljakubas paweljakubas commented Oct 16, 2019

Issue Number

#836

Overview

  • I have added forget pending transaction endpoint, errors and types
  • I have updated swagger accordingly

Comments

data ErrForgetPendingTx
= ErrForgetPendingTxNoSuchWallet ErrNoSuchWallet
| ErrForgetPendingTxNoSuchTransaction ErrNoSuchTransaction
| ErrForgetPendingTxTransactionIsNotPending (Hash "Tx")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. Good point 😅

@@ -611,6 +614,23 @@ postExternalTransaction ctx (PostExternalTransactionData load) = do
tx <- liftHandler $ W.submitExternalTx @ctx @t @k ctx load
return $ ApiTxId (ApiT (txId @t tx))

deleteTransaction
:: forall ctx s t k.
( s ~ SeqState t
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think s ~ SeqState t is superfluous here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed, fixed

ErrForgetPendingTxTransactionIsNotPending tid ->
apiError err404 TransactionNotPending $ mconcat
[ "The transaction with id : ", pretty tid,
"cannot be forgotten as it is not pending anymore."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we'll need an extra blank space before "cannot" ☝️

ErrForgetPendingTxNoSuchTransaction e -> handler e
ErrForgetPendingTxTransactionIsNotPending tid ->
apiError err404 TransactionNotPending $ mconcat
[ "The transaction with id : ", pretty tid,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pretty will show a truncated transaction id, in the API response, we probably want to show the full id so I'd advise for toText instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point - fixed

instance FromText ApiTxId where
fromText txt = case fromText txt of
Left err -> Left $ TextDecodingError $ show err
Right tid -> Right $ ApiTxId $ ApiT tid
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the FromText instance is confusing here 🤔 (especially because we have to still do some conversion on top in parseUrlPiece for the error).
I'd suggest to inline this with the definition in FromHttpApiData ApiTxId and return the right error type directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

where
fromText' txt = case fromText txt of
Left err -> Left $ TextDecodingError $ show err
Right tid -> Right $ ApiTxId $ ApiT tid
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion:

instance FromHttpApiData ApiTxId where
    parseUrlPiece txt = case fromText txt of
        Left (TextDecodingError err) -> Left $ T.pack err
        Right tid -> Right $ ApiTxId $ ApiT tid

Copy link
Member

@jonathanknowles jonathanknowles left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

However, I have a question regarding naming. There seems to be some inconsistency:

  • The endpoint operation name is called deleteTransaction (delete)
  • The response type is called responsesDeleteTransaction (delete)
  • The endpoint description is "forget pending transaction" (forget)
  • The wallet layer function is called forgetPendingTx (forget)
  • The associated error functions are called ErrForgetPendingTx... (forget)

For consistency, is there any way we can pick one of these (either "delete" or "forget") and use that consistently throughout?

I think it would make the code easier to follow. What do you think?

@paweljakubas
Copy link
Contributor Author

paweljakubas commented Oct 16, 2019

@jonathanknowles I was thinking about it. So in order to follow REST API I would stick to DELETE, but underneath, like in Cardano.Wallet would use forget as we did for other endpoints - see postTransaction vs submitTransaction. When it comes to other naming I tried to follow already established convention (errors, etc)

@KtorZ
Copy link
Member

KtorZ commented Oct 16, 2019

I second @paweljakubas on this. delete makes sense at the API-level. Actually, we should only find names as get, put, patch, delete, list in the API-level. Yet, the wallet layer can (ought to) be more expressive and therefore, have functions with a clearer semantic when possible.

@paweljakubas paweljakubas force-pushed the paweljakubas/836/forget-pending-tx branch from b80eab9 to e28d965 Compare October 16, 2019 14:39
@jonathanknowles
Copy link
Member

@KtorZ wrote:

Actually, we should only find names as get, put, patch, delete, list in the API-level

Just to clarify, what is the motivation behind this? Is it to restrict ourselves to just the verbs that are HTTP verbs?

We already seem to violate this principle in a few places. Consider the following API-level names:

  1. listWallets: should this not be called getWallets?
  2. listTransactions: should this not be called getTransactions?
  3. migrateByronWallet: what should this be called, if not migrate?

@paweljakubas paweljakubas force-pushed the paweljakubas/836/forget-pending-tx branch from e28d965 to c65982c Compare October 16, 2019 15:16
@paweljakubas
Copy link
Contributor Author

rebased and resolved conflicts

@KtorZ
Copy link
Member

KtorZ commented Oct 16, 2019

@jonathanknowles

list is a commonly used / accepted verb in the CRUD terminology. You sometimes see people even talking about CRUDL. Mapping that to the rest terminology, there are two options:

  • use list for collections
  • use of the plural form for collections, and singular form for singletons:
    • getResource ==> GET /resources/{id} (or alternatively, getResourceById)
    • getResources ==> GET /resources

I am fine with both so long as naming is consistent although I find the former more readable (use of list).

For migrateByronWallet, something like postByronWalletMigration will be more consistent with the rest. But as I said "we should only find names", I didn't say it was the case.

Having said that, we are really neat-picking here.

@KtorZ
Copy link
Member

KtorZ commented Oct 16, 2019

bors r+

@iohk-bors
Copy link
Contributor

iohk-bors bot commented Oct 16, 2019

👎 Rejected by too few approved reviews

@KtorZ
Copy link
Member

KtorZ commented Oct 16, 2019

bors r+

iohk-bors bot added a commit that referenced this pull request Oct 16, 2019
834: DaedalusIPC: Fix isWindows function r=KtorZ a=rvl

# Issue Number

None.

# Overview

Fixes a typo in the OS detection code for NodeIPC.

# Comments

I again looked at the possibility of importing the cardano-shell package for this functionality. But it is pulling in more dependencies. Also the `daedalusIPC` function there had the logging replaced with `putTextLn`. Branch is [rvl/daedalus-ipc-cardano-shell](rvl/daedalus-ipc-fix...rvl/daedalus-ipc-cardano-shell) for reference though.


840: Make Jörmungandr NetworkLayer use raw blocks r=KtorZ a=Anviking


# Issue Number

#711 

# Overview

<!-- Detail in a few bullet points the work accomplished in this PR -->

- [x] I changed the constructors in `Cardano.Wallet.Jormungandr.Network` to create NetworkLayers with raw jörmungadnr-specific blocks, and later used `toWLBlock <$> nl`. This way we can later use `toSPBlock <$> nl` for stake-pools.


# Comments

<!-- Additional comments or screenshots to attach if any -->

<!-- 
Don't forget to:

 ✓ Self-review your changes to make sure nothing unexpected slipped through
 ✓ Assign yourself to the PR
 ✓ Assign one or several reviewer(s)
 ✓ Once created, link this PR to its corresponding ticket
 ✓ Acknowledge any changes required to the Wiki
-->


845: Add forget pending transaction endpoint (Part1) r=KtorZ a=paweljakubas

# Issue Number

<!-- Put here a reference to the issue this PR relates to and which requirements it tackles -->
#836 

# Overview

<!-- Detail in a few bullet points the work accomplished in this PR -->

- [x] I have added forget pending transaction endpoint, errors and types
- [x] I have updated swagger accordingly


# Comments

<!-- Additional comments or screenshots to attach if any -->

<!-- 
Don't forget to:

 ✓ Self-review your changes to make sure nothing unexpected slipped through
 ✓ Assign yourself to the PR
 ✓ Assign one or several reviewer(s)
 ✓ Once created, link this PR to its corresponding ticket
 ✓ Acknowledge any changes required to the Wiki
-->


Co-authored-by: Rodney Lorrimar <[email protected]>
Co-authored-by: Johannes Lund <[email protected]>
Co-authored-by: Pawel Jakubas <[email protected]>
@iohk-bors iohk-bors bot merged commit c65982c into master Oct 16, 2019
@iohk-bors
Copy link
Contributor

iohk-bors bot commented Oct 16, 2019

Build succeeded

@KtorZ KtorZ added this to the Forget Pending Transaction milestone Oct 17, 2019
@KtorZ KtorZ deleted the paweljakubas/836/forget-pending-tx branch October 18, 2019 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants