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

Fork the not_enough_money HTTP API error. #4366

Merged
merged 9 commits into from
Dec 20, 2023

Conversation

jonathanknowles
Copy link
Member

@jonathanknowles jonathanknowles commented Dec 20, 2023

Issue

ADP-3248

Summary of user-facing change

If the wallet is asked to create a transaction in a situation where there are no UTxOs available, then the wallet will return a no_utxos_available error instead of a not_enough_money error.

Details

This PR forks the HTTP API error not_enough_money into two separate errors:

  • not_enough_money
    for when there really isn't enough money
  • no_utxos_available
    for when there might be enough money, but there are definitely no UTxOs available

These two cases can require subtly different workarounds from the user.

Details

This PR solves two problems.

Problem 1

The not_enough_money error is inappropriate in the case where the reward balance alone would be sufficient to cover the amount required.

For example, suppose a user has a wallet with:

  • no UTxOs;
  • an unspent reward balance of 1,000,000,000 ada.

Suppose that the user attempts to make a payment transaction of 10 ada. In this case, the attempt will fail because:

  • every transaction is required to spend at least one UTxO; but
  • the wallet has no UTxOs available.

But the user will receive a misleading not_enough_money error, even though they have more than enough money.

This PR solves this problem by always using no_utxos_available when there are no UTxOs.

Problem 2

In the case where UTxOs are available, but their value is insufficient, we currently attempt to embed information about the shortfall within the error message string:

I can't process this payment as there are not enough funds in the wallet. I am missing:
- lovelace: 123,456 lovelace
- assets: ... <information embedded within string>

This information is valuable for UI clients that wish to inform users how much extra value they would need, but the information is tricky for UI clients to parse, as it's embedded within a string.

We wish to turn the shortfall case into a machine-readable error with a specified JSON encoding (see #4348). However, this error would not be appropriate for the case where there are no UTxOs available at all, as there would not necessarily even be a "shortfall".

This PR avoids this problem by giving the former case (no UTxOs available) its own dedicated error that will not be affected by #4348.

@jonathanknowles jonathanknowles self-assigned this Dec 20, 2023
@jonathanknowles jonathanknowles force-pushed the jonathanknowles/no-utxos-available branch from b5840fe to 67b635e Compare December 20, 2023 05:09
@jonathanknowles jonathanknowles changed the base branch from master to jonathanknowles/api-amount December 20, 2023 05:10
@jonathanknowles jonathanknowles marked this pull request as ready for review December 20, 2023 06:30
@jonathanknowles jonathanknowles changed the title Add no_utxos_available error to HTTP API. Fork the not_enough_money HTTP API error. Dec 20, 2023
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.

very fond of using decodeErrorInfo and your reformulation of the error 👍

Base automatically changed from jonathanknowles/api-amount to master December 20, 2023 09:12
@jonathanknowles jonathanknowles added this pull request to the merge queue Dec 20, 2023
Merged via the queue into master with commit 15f75af Dec 20, 2023
3 checks passed
@jonathanknowles jonathanknowles deleted the jonathanknowles/no-utxos-available branch December 20, 2023 09:39
WilliamKingNoel-Bot pushed a commit that referenced this pull request Dec 20, 2023
…This PR forks the HTTP API error `not_enough_money` into two separate errors: - `not_enough_money` for when there **_really_** isn't enough money - `no_utxos_available` for when there **_might_** be enough money, but there are no UTxOs available These two cases can require subtly different workarounds from the user. ## Details This PR solves two problems. ### Problem 1 The `not_enough_money` error is **_inappropriate_** in the case where the reward balance alone would be sufficient to cover the amount required. For example, suppose a user has a wallet with: - no UTxOs; - an unspent reward balance of `1,000,000,000` ada. Suppose that the user attempts to make a payment transaction of `10` ada. In this case, the attempt will fail because: - every transaction is required to spend at least one UTxO; but - the wallet has no UTxOs available. But the user will receive a misleading `not_enough_money` error, even though they have more than enough money. This PR solves this problem by always using `no_utxos_available` when there are no UTxOs. ### Problem 2 In the case where UTxOs **_are_** available, but their value is insufficient, we currently attempt to embed information about the shortfall within the error message string: > ``` > I can't process this payment as there are not enough funds in the wallet. I am missing: > - lovelace: 123,456 lovelace > - assets: ... <information embedded within string> > ``` This information is valuable for UI clients that wish to inform users how much extra value they would need, but the information is tricky for UI clients to parse, as it's embedded within a **_string_**. We wish to turn the shortfall case into a **_machine-readable_** error with a specified JSON encoding (see #4348). However, this error would not be appropriate for the case where there are no UTxOs available at all, as there would not necessarily even be a "shortfall". This PR avoids this problem by giving the former case (no UTxOs available) its own dedicated error that will not be affected by #4348. Source commit: 15f75af
github-merge-queue bot pushed a commit that referenced this pull request Dec 22, 2023
## Summary

This PR attempts to fix the end-to-end tests.

## Details

If the wallet is asked to create a transaction in a situation where
there are no UTxOs available, then the wallet will return a
`no_utxos_available` error instead of a `not_enough_money` error.

See:
- #4366
-
https://github.com/cardano-foundation/cardano-wallet/actions/runs/7294574003/job/19879662240#step:12:906

## Issue

ADP-3248
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.

2 participants