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

Refactor: break down ApiConstructTransactionData validation #3598

Merged
merged 2 commits into from
Nov 23, 2022

Conversation

Unisay
Copy link
Contributor

@Unisay Unisay commented Nov 22, 2022

This PR is an increment towards the state where Cardano.Wallet.Api.createTransaction API request body validation is modular and is done in a spirit of Parse, don’t validate.

I intend to continue down this road, such that:

  • API layer is responsible for converting HTTP request into a data type that captures a transaction construction task (TransactionCtx atm).

  • TransactionCtx is passed to the Cardano.Wallet.createTransaction layer which takes care of the semantic validations and does all the logic.

Such refactoring will make it possible to reimplement e.g. quitStakePool in terms of the Cardano.Wallet.createTransaction.

Issue Number

ADP-2267

@Unisay Unisay self-assigned this Nov 22, 2022
@Unisay Unisay requested a review from Anviking November 22, 2022 16:04
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.

Hi @Unisay

Thanks for making this PR.

Just some preliminary comments.

, mintBurn = Nothing
, delegations = Nothing
} -> liftHandler $ throwE ErrConstructTxWrongPayload
_ -> pure ()
Copy link
Member

Choose a reason for hiding this comment

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

I remember the discussion about this in the #haskell channel!

I wonder if there's a way to extract this out as a general pattern?

On the one hand, it seems desirable that when we introduce a new field, we get a compilation failure on any record pattern match that's intended to be complete. On the other hand, if we updated all similar record pattern matches across the code base, it would introduce a lot of boilerplate.

Perhaps this is something that can only be fixed in GHC.

Copy link
Contributor Author

@Unisay Unisay Nov 23, 2022

Choose a reason for hiding this comment

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

I wonder if there's a way to extract this out as a general pattern?

Good question, unfortunately I don't see how could it be possible.

On the other hand, if we updated all similar record pattern matches across the code base, it would introduce a lot of boilerplate.

I'd argue then that boilerplate (it is syntactically more verbose than desired) is justified by the additional guarantees that it gives.

@Unisay Unisay force-pushed the yura/ADP-2267/quit-stake-pool-balanceTx branch from 0de2644 to a927c62 Compare November 23, 2022 06:48
Copy link
Contributor

@paweljakubas paweljakubas left a comment

Choose a reason for hiding this comment

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

Seems like a nice decomposition of previously big blob into logical steps/checks/validations that occur in constructTransaction. Thanks to that, many of those pieces could be reused in constructSharedTransaction. I would appreciate smaller commits next time to follow the changes. At this time although they seem correct I would say testing, especially integration one, will tell the truth if those changes are correct.

Copy link
Member

@Anviking Anviking left a comment

Choose a reason for hiding this comment

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

nice — lgtm.

@Unisay
Copy link
Contributor Author

Unisay commented Nov 23, 2022

bors merge

@iohk-bors
Copy link
Contributor

iohk-bors bot commented Nov 23, 2022

Build succeeded:

@iohk-bors iohk-bors bot merged commit 956fa1f into master Nov 23, 2022
@iohk-bors iohk-bors bot deleted the yura/ADP-2267/quit-stake-pool-balanceTx branch November 23, 2022 16:14
WilliamKingNoel-Bot pushed a commit that referenced this pull request Nov 23, 2022
…ata validation r=Unisay a=Unisay This PR is an increment towards the state where `Cardano.Wallet.Api.createTransaction` API request body validation is modular and is done in a spirit of [Parse, don’t validate](https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-validate/).
 
 I intend to continue down this road, such that:
 - API layer is responsible for converting HTTP request into a data type that captures a transaction construction task (`TransactionCtx` atm). 
 
 - `TransactionCtx` is passed to the `Cardano.Wallet.createTransaction` layer which takes care of the semantic validations and does all the logic.
 
 Such refactoring will make it possible to reimplement e.g. `quitStakePool` in terms of the `Cardano.Wallet.createTransaction`.
 
 ### Issue Number
 
 ADP-2267 Co-authored-by: Yura Lazarev <[email protected]> Source commit: 956fa1f
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.

4 participants